From a8a588bb7020a4605346ac2aa18f3136f6bf22ff Mon Sep 17 00:00:00 2001 From: Gustavo Nunes Date: Thu, 26 Jan 2017 22:55:45 -0200 Subject: [PATCH] Onboarding tests: fixed existing and added new --- env/dev/user.clj | 40 +++++++++++++-- .../env/android}/main.cljs | 18 ++++--- project.clj | 8 +-- src/status_im/accessibility_ids.cljc | 17 +++++++ src/status_im/accounts/screen.cljs | 3 +- src/status_im/chat/views/message_input.cljs | 9 ++-- src/status_im/chat/views/request_message.cljs | 9 +--- src/status_im/chat/views/response.cljs | 4 +- src/status_im/components/drawer/view.cljs | 3 +- src/status_im/components/toolbar/view.cljs | 3 +- test/clj/status_im/console.clj | 51 ------------------- test/clj/status_im/{ => test}/appium.clj | 9 ++-- test/clj/status_im/test/console.clj | 49 ++++++++++++++++++ test/cljs/status_im/test/handlers_stubs.cljs | 7 +-- test/cljs/status_im/test/runner.cljs | 4 +- 15 files changed, 140 insertions(+), 94 deletions(-) rename env/{dev/env/android_test => test/env/android}/main.cljs (53%) create mode 100644 src/status_im/accessibility_ids.cljc delete mode 100644 test/clj/status_im/console.clj rename test/clj/status_im/{ => test}/appium.clj (92%) create mode 100644 test/clj/status_im/test/console.clj diff --git a/env/dev/user.clj b/env/dev/user.clj index 6f5702afa6..7753bfbef0 100644 --- a/env/dev/user.clj +++ b/env/dev/user.clj @@ -12,12 +12,23 @@ (apply hash-map) :profiles)) +(defn get-test-build [build] + (update build :source-paths + (fn [paths] (let [paths-set (set paths)] + (-> paths-set + (disj "env/dev") + (conj "env/test" "test/cljs") + vec))))) + (def cljs-builds (get-in profiles [:dev :cljsbuild :builds])) +(def buids-by-id + (into {} (map (fn [{:keys [id] :as build}] [id build]) cljs-builds))) + (defn start-figwheel "Start figwheel for one or more builds" - [build-ids] + [build-ids cljs-builds] (ra/start-figwheel! {:figwheel-options {:nrepl-port 7888} :build-ids build-ids @@ -38,8 +49,27 @@ (spit path js-resourced)) ctx)}]) +(defn test-id? [id] + (s/includes? (name id) "-test")) + +(defn get-id [id] + (-> id + name + (s/replace #"-test" "") + keyword)) + +(defn get-builds [ids all-builds] + (keep + (fn [id] + (let [build (get all-builds (get-id id))] + (if (test-id? id) + (get-test-build build) + build))) + ids)) + (let [env-build-ids (System/getenv "BUILD_IDS") - build-ids (if env-build-ids - (map keyword (s/split env-build-ids #",")) - [:android])] - (start-figwheel build-ids)) + build-ids (if env-build-ids + (map keyword (s/split env-build-ids #",")) + [:android]) + builds (get-builds build-ids buids-by-id)] + (start-figwheel build-ids builds)) diff --git a/env/dev/env/android_test/main.cljs b/env/test/env/android/main.cljs similarity index 53% rename from env/dev/env/android_test/main.cljs rename to env/test/env/android/main.cljs index 062e01f015..beea0fb9f5 100644 --- a/env/dev/env/android_test/main.cljs +++ b/env/test/env/android/main.cljs @@ -1,21 +1,25 @@ -(ns ^:figwheel-no-load env.android-test.main +(ns ^:figwheel-no-load env.android.main (:require [reagent.core :as r] [status-im.android.core :as core] [figwheel.client :as figwheel :include-macros true] - ;[status-im.test.handlers-stubs :refer [init-stubs]] - )) -(enable-console-print!) + [status-im.test.handlers-stubs :refer [init-stubs]])) (set! js/console.disableYellowBox true) +(enable-console-print!) + (def cnt (r/atom 0)) (defn reloader [] @cnt [core/app-root]) (def root-el (r/as-element [reloader])) +(defn callback [] + (swap! cnt inc) + (status-im.components.status/init-jail) + (re-frame.core/dispatch [:load-commands!])) (figwheel/watch-and-reload - :websocket-url "ws://localhost:3449/figwheel-ws" + :websocket-url "ws://10.0.3.2:3449/figwheel-ws" :heads-up-display false - :jsload-callback #(swap! cnt inc)) + :jsload-callback callback) (core/init) -;(init-stubs) +(init-stubs) diff --git a/project.clj b/project.clj index 8f37456580..ed3536b058 100644 --- a/project.clj +++ b/project.clj @@ -4,7 +4,7 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.9.0-alpha13"] - [org.clojure/clojurescript "1.9.229"] + [org.clojure/clojurescript "1.9.456"] [reagent "0.6.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]] [re-frame "0.7.0"] [natal-shell "0.3.0"] @@ -40,12 +40,6 @@ :main "env.android.main" :output-dir "target/android" :optimizations :none}} - {:id :android-test - :source-paths ["src" "env/dev"] - :compiler {:output-to "target/android/not-used.js" - :main "env.android-test.main" - :output-dir "target/android-test" - :optimizations :none}} {:id :test :source-paths ["src" "test/cljs"] :compiler diff --git a/src/status_im/accessibility_ids.cljc b/src/status_im/accessibility_ids.cljc new file mode 100644 index 0000000000..1cca8f0781 --- /dev/null +++ b/src/status_im/accessibility_ids.cljc @@ -0,0 +1,17 @@ +(ns status-im.accessibility-ids) + +;; Toolbar +(def toolbar-back-button :toolbar-back-button) + +;; Drawer +(def drawer-status-input :drawer-status-input) + +;; Chat +(def chat-cancel-response-button :chat-cancel-response-button) +(def chat-message-input :chat-message-input) +(def chat-send-button :chat-send-button) +(defn chat-request-message-button [command-name] + (keyword (str "request-" (name command-name)))) + +;; Accounts +(def accounts-create-button :accounts-create-button) diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index 5b07f99ee7..bb39c9b635 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -21,6 +21,7 @@ [status-im.utils.listview :as lw] [status-im.accounts.views.account :refer [account-view]] [status-im.i18n :refer [label]] + [status-im.accessibility-ids :as id] [status-im.accounts.styles :as st] [status-im.constants :refer [console-chat-id]])) @@ -74,7 +75,7 @@ (label :t/recover-access)]]]] [view st/add-account-button-container [touchable-highlight {:on-press create-account - :accessibility-label :create-account} + :accessibility-label id/accounts-create-button} [view st/add-account-button [image {:source {:uri :icon_add_white} :style st/icon-plus}] diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index f6b72279f5..dcd598e33a 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -12,6 +12,7 @@ [status-im.chat.styles.message-input :as st] [status-im.chat.styles.plain-message :as st-message] [status-im.chat.styles.response :as st-response] + [status-im.accessibility-ids :as id] [reagent.core :as r] [clojure.string :as str])) @@ -49,7 +50,7 @@ (.-contentSize) (.-height))] (set-layout-size size)) - :accessibility-label :input + :accessibility-label id/chat-message-input :on-focus #(do (dispatch [:set :focused true]) (dispatch [:set-chat-ui-props :show-emoji? false])) :on-blur #(do (dispatch [:set :focused false]) @@ -65,7 +66,7 @@ (command-input-options icon-width disable? sending-disabled?) {:auto-focus (not fullscreen) :blur-on-submit false - :accessibility-label :input + :accessibility-label id/chat-message-input :on-focus #(dispatch [:set :focused true]) :on-blur #(dispatch [:set :focused false]) :default-value (or input-command "")} @@ -110,7 +111,7 @@ [send-button {:on-press (fn [e] (when-not @sending-disabled? (dispatch [:set-chat-ui-props :show-emoji? false]) - (on-press e)))}])) + (on-press e))) + :accessibility-label id/chat-send-button}])) (when (and @command? (= :command (:type @command))) [command/command-icon @command])]]))}))) - diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 065178a793..725b4c52b0 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -8,6 +8,7 @@ icon touchable-highlight]] [status-im.chat.styles.message :as st] + [status-im.accessibility-ids :as id] [status-im.models.commands :refer [parse-command-request]] [status-im.components.animation :as anim])) @@ -18,12 +19,6 @@ params (:set-params command)] (dispatch [:set-response-chat-command message-id command-key params]))) -(defn label [command] - (when command - (->> (:name command) - name - (str "request-")))) - (def min-scale 1) (def max-scale 1.3) @@ -66,7 +61,7 @@ {:on-press (when (and (not @answered?) status-initialized?) #(set-chat-command message-id command)) :style (st/command-request-image-touchable top-offset?) - :accessibility-label (label command)} + :accessibility-label (id/chat-request-message-button (:name command))} [animated-view {:style (st/command-request-image-view command scale-anim-val)} (when command-icon [icon command-icon st/command-request-image])]]))}))) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index c6b09d141d..d55e397235 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -21,6 +21,7 @@ [status-im.utils.platform :refer [ios?]] [status-im.components.webview-bridge :refer [webview-bridge]] [status-im.i18n :refer [label]] + [status-im.accessibility-ids :as id] [status-im.utils.datetime :as dt] [status-im.utils.name :refer [shortened-name]] [status-im.utils.js-resources :as js-res] @@ -69,7 +70,8 @@ [view st/inner-container [command-icon @command] [info-container @command] - [touchable-highlight {:on-press #(dispatch [:start-cancel-command])} + [touchable-highlight {:on-press #(dispatch [:start-cancel-command]) + :accessibility-label id/chat-cancel-response-button} [view st/cancel-container [icon :close_white st/cancel-icon]]]]] [view (merge (drag/pan-handlers pan-responder) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 1ee212738c..590020ed1a 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -18,6 +18,7 @@ [status-im.utils.gfycat.core :refer [generate-gfy]] [status-im.utils.utils :refer [clean-text]] [status-im.i18n :refer [label]] + [status-im.accessibility-ids :as id] [status-im.components.react :refer [dismiss-keyboard!]] [clojure.string :as str] [status-im.components.chat-icon.screen :as ci])) @@ -82,7 +83,7 @@ :auto-focus true :focus status-edit? :max-length 140 - :accessibility-label :input + :accessibility-label id/drawer-status-input :placeholder (label :t/profile-no-status) :default-value status :on-blur #(do diff --git a/src/status_im/components/toolbar/view.cljs b/src/status_im/components/toolbar/view.cljs index dca7b628d2..bb6778bec2 100644 --- a/src/status_im/components/toolbar/view.cljs +++ b/src/status_im/components/toolbar/view.cljs @@ -11,6 +11,7 @@ icon-search]] [status-im.components.toolbar.actions :as act] [status-im.components.toolbar.styles :as st] + [status-im.accessibility-ids :as id] [status-im.utils.platform :refer [platform-specific]])) (defn toolbar [{title :title @@ -31,7 +32,7 @@ [view (get-in platform-specific [:component-styles :toolbar-nav-action]) [image (:image nav-action)]]] [touchable-highlight {:on-press #(dispatch [:navigate-back]) - :accessibility-label :navigate-back} + :accessibility-label id/toolbar-back-button} [view (get-in platform-specific [:component-styles :toolbar-nav-action]) [image {:source {:uri :icon_back} :style icon-back}]]]))] diff --git a/test/clj/status_im/console.clj b/test/clj/status_im/console.clj deleted file mode 100644 index c375c3700d..0000000000 --- a/test/clj/status_im/console.clj +++ /dev/null @@ -1,51 +0,0 @@ -(ns status-im.console - (:require [clojure.test :refer :all] - [status-im.appium :refer :all])) - -(def message-text - (str "Your phone number is also required to use the app. Type" - " the exclamation mark or hit the icon to open the command " - "list and choose the !phone command")) - -(defaction send-sommand [] - (click :send-message) - (click :send-message)) - -(defaction respond-to-request - [request value] - (click (keyword (str "request-" (name request)))) - (write :input value) - (send-sommand)) - -(appium-test happy-case - (click :create-account) - (respond-to-request :keypair "123") - (contains-text message-text) - (respond-to-request :phone "+380671111111") - (respond-to-request :confirmation-code "1234") - (click :navigate-back) - (contains-text "Switch users")) - -(appium-test wrong-confirmation-code - (click :create-account) - (respond-to-request :keypair "123") - (respond-to-request :phone "+380671111111") - (respond-to-request :confirmation-code "432") - (contains-text "Wrong format") - (respond-to-request :confirmation-code "4321") - (contains-text "Wrong code!") - (write :input "1234") - (send-sommand) - (click :navigate-back) - (contains-text "Switch users")) - -(appium-test wrong-phone-number - (click :create-account) - (respond-to-request :keypair "123") - (respond-to-request :phone "+380671111111") - (write :input "+380671111112") - (send-sommand) - (write :input "1234") - (send-sommand) - (click :navigate-back) - (contains-text "Switch users")) diff --git a/test/clj/status_im/appium.clj b/test/clj/status_im/test/appium.clj similarity index 92% rename from test/clj/status_im/appium.clj rename to test/clj/status_im/test/appium.clj index bf769a192a..f05bfc7832 100644 --- a/test/clj/status_im/appium.clj +++ b/test/clj/status_im/test/appium.clj @@ -1,4 +1,4 @@ -(ns status-im.appium +(ns status-im.test.appium (:require [clojure.java.io :as io] [clojure.test :refer :all]) (:import (org.openqa.selenium.remote DesiredCapabilities) @@ -14,7 +14,6 @@ app (io/file dir "app-debug.apk") capabilities (doto (DesiredCapabilities.) (.setCapability "deviceName" "device") - (.setCapability "platformVersion" "6.0.0") (.setCapability "app" (.getAbsolutePath app)) (.setCapability "appPackage" "im.status.ethereum") (.setCapability "appActivity" ".MainActivity")) @@ -49,7 +48,7 @@ (.getText (by-xpath driver xpath))) (defn xpath-by-text [text] - (str ".//*[@text='" text "']")) + (str ".//*[@text=\"" text "\"]")) (defn click-by-text [driver text] (let [elements (->> (xpath-by-text text) @@ -70,7 +69,9 @@ (defmacro appium-test "Defines test which will create new appium session and will pass that session as first argument to each command inside it's body. After execution - of all commands session will be closed. + of all commands, the session will be closed. + Also, at the start of every test, the 'Continue' button from the 'Your phone + appears to be ROOTED' message will be pressed. For instance, diff --git a/test/clj/status_im/test/console.clj b/test/clj/status_im/test/console.clj new file mode 100644 index 0000000000..2efa37efd1 --- /dev/null +++ b/test/clj/status_im/test/console.clj @@ -0,0 +1,49 @@ +(ns status-im.test.console + (:require [clojure.test :refer :all] + [status-im.accessibility-ids :as id] + [status-im.test.appium :refer :all])) + +(defaction send-command [] + (click id/chat-send-button)) + +(defaction respond-to-request [request value] + (click (id/chat-request-message-button request)) + (write id/chat-message-input value) + (send-command)) + +(defaction confirm-password [value] + (write id/chat-message-input value) + (send-command)) + +(appium-test sign-up-successfully + (respond-to-request :password "password") + (confirm-password "password") + (respond-to-request :phone "2015550123") + (respond-to-request :confirmation-code "1234") + (contains-text "Done!") + (click id/toolbar-back-button) + (contains-text "Chats")) + +(appium-test wrong-password + (respond-to-request :password "abc") + (contains-text "Password should be not less then 6 symbols.") + (click id/chat-cancel-response-button) + (respond-to-request :password "password") + (confirm-password "abc") + (contains-text "Password confirmation doesn't match password.")) + +(appium-test wrong-phone-number + (respond-to-request :password "password") + (confirm-password "password") + (respond-to-request :phone "1234") + (contains-text "Invalid phone number")) + +(appium-test wrong-confirmation-code + (respond-to-request :password "password") + (confirm-password "password") + (respond-to-request :phone "2015550123") + (respond-to-request :confirmation-code "432") + (contains-text "Wrong format") + (click id/chat-cancel-response-button) + (respond-to-request :confirmation-code "4321") + (contains-text "Wrong code!")) diff --git a/test/cljs/status_im/test/handlers_stubs.cljs b/test/cljs/status_im/test/handlers_stubs.cljs index 5336ca9cf7..051d823e4f 100644 --- a/test/cljs/status_im/test/handlers_stubs.cljs +++ b/test/cljs/status_im/test/handlers_stubs.cljs @@ -7,9 +7,10 @@ (defn init-stubs [] (register-handler :sign-up - (fn [] - ;; todo save phone number to db - (sign-up-service/on-sign-up-response))) + (u/side-effect! + (fn [] + ;; todo save phone number to db + (sign-up-service/on-sign-up-response)))) (register-handler :sign-up-confirm (u/side-effect! diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index fef2b15ecf..2f503a9e21 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -1,7 +1,7 @@ (ns status-im.test.runner - (:require [doo.runner :refer-macros [doo-tests]] + (:require #_[doo.runner :refer-macros [doo-tests]] [status-im.test.handlers] [status-im.test.commands.handlers])) -(doo-tests 'status-im.test.handlers +#_(doo-tests 'status-im.test.handlers 'status-im.test.commands.handlers)