Merge pull request #161 from status-im/tests/on-boarding
On boarding tests
This commit is contained in:
commit
73370a9413
|
@ -0,0 +1,21 @@
|
||||||
|
(ns ^:figwheel-no-load env.android-test.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!)
|
||||||
|
|
||||||
|
(set! js/console.disableYellowBox true)
|
||||||
|
|
||||||
|
(def cnt (r/atom 0))
|
||||||
|
(defn reloader [] @cnt [core/app-root])
|
||||||
|
(def root-el (r/as-element [reloader]))
|
||||||
|
|
||||||
|
(figwheel/watch-and-reload
|
||||||
|
:websocket-url "ws://localhost:3449/figwheel-ws"
|
||||||
|
:heads-up-display false
|
||||||
|
:jsload-callback #(swap! cnt inc))
|
||||||
|
|
||||||
|
(core/init :test)
|
||||||
|
(init-stubs)
|
|
@ -164,11 +164,17 @@ function loadApp(platform, devHost, onLoadCb) {
|
||||||
|
|
||||||
// callback when app is ready to get the reloadable component
|
// callback when app is ready to get the reloadable component
|
||||||
var mainJs = '/env/' + platform + '/main.js';
|
var mainJs = '/env/' + platform + '/main.js';
|
||||||
|
var mainTestJs = '/env/' + platform + '_test/main.js';
|
||||||
evalListeners.push(function (url) {
|
evalListeners.push(function (url) {
|
||||||
if (url.indexOf(mainJs) > -1) {
|
if (url.indexOf(mainJs) > -1) {
|
||||||
onLoadCb(env[platform].main.root_el);
|
onLoadCb(env[platform].main.root_el);
|
||||||
console.log('Done loading Clojure app');
|
console.log('Done loading Clojure app');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (url.indexOf(mainTestJs) > -1) {
|
||||||
|
onLoadCb(env[platform + "_test"].main.root_el);
|
||||||
|
console.log('Done loading Clojure app');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof goog === "undefined") {
|
if (typeof goog === "undefined") {
|
||||||
|
|
42
project.clj
42
project.clj
|
@ -27,24 +27,30 @@
|
||||||
[io.appium/java-client "3.4.1"]]
|
[io.appium/java-client "3.4.1"]]
|
||||||
:plugins [[lein-doo "0.1.6"]]
|
:plugins [[lein-doo "0.1.6"]]
|
||||||
:source-paths ["src" "env/dev"]
|
:source-paths ["src" "env/dev"]
|
||||||
:cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"]
|
:cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"]
|
||||||
:figwheel true
|
:figwheel true
|
||||||
:compiler {:output-to "target/ios/not-used.js"
|
:compiler {:output-to "target/ios/not-used.js"
|
||||||
:main "env.ios.main"
|
:main "env.ios.main"
|
||||||
:output-dir "target/ios"
|
:output-dir "target/ios"
|
||||||
:optimizations :none}}
|
:optimizations :none}}
|
||||||
:android {:source-paths ["src" "env/dev"]
|
:android {:source-paths ["src" "env/dev"]
|
||||||
:figwheel true
|
:figwheel true
|
||||||
:compiler {:output-to "target/android/not-used.js"
|
:compiler {:output-to "target/android/not-used.js"
|
||||||
:main "env.android.main"
|
:main "env.android.main"
|
||||||
:output-dir "target/android"
|
:output-dir "target/android"
|
||||||
:optimizations :none}}
|
:optimizations :none}}
|
||||||
:test {:source-paths ["src" "test/cljs"]
|
:android-test {:source-paths ["src" "env/dev"]
|
||||||
:compiler
|
:figwheel true
|
||||||
{:main status-im.test.runner
|
:compiler {:output-to "target/android/not-used.js"
|
||||||
:output-to "target/test/test.js"
|
:main "env.android-test.main"
|
||||||
:optimizations :none
|
:output-dir "target/android"
|
||||||
:target :nodejs}}}}
|
:optimizations :none}}
|
||||||
|
:test {:source-paths ["src" "test/cljs"]
|
||||||
|
:compiler
|
||||||
|
{:main status-im.test.runner
|
||||||
|
:output-to "target/test/test.js"
|
||||||
|
:optimizations :none
|
||||||
|
:target :nodejs}}}}
|
||||||
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
|
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
|
||||||
:prod {:cljsbuild {:builds {:ios {:source-paths ["src" "env/prod"]
|
:prod {:cljsbuild {:builds {:ios {:source-paths ["src" "env/prod"]
|
||||||
:compiler {:output-to "index.ios.js"
|
:compiler {:output-to "index.ios.js"
|
||||||
|
|
|
@ -136,7 +136,7 @@ function phoneSuggestions(params) {
|
||||||
return {markup: view};
|
return {markup: view};
|
||||||
}
|
}
|
||||||
|
|
||||||
status.response({
|
var phoneConfig = {
|
||||||
name: "phone",
|
name: "phone",
|
||||||
description: "Send phone number",
|
description: "Send phone number",
|
||||||
color: "#5fc48d",
|
color: "#5fc48d",
|
||||||
|
@ -158,7 +158,9 @@ status.response({
|
||||||
params: [params.value]
|
params: [params.value]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
status.response(phoneConfig);
|
||||||
|
status.command(phoneConfig);
|
||||||
|
|
||||||
status.command({
|
status.command({
|
||||||
name: "help",
|
name: "help",
|
||||||
|
@ -193,6 +195,16 @@ status.response({
|
||||||
event: "confirm-sign-up",
|
event: "confirm-sign-up",
|
||||||
params: [params.value]
|
params: [params.value]
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
validator: function(params){
|
||||||
|
if(!/^[\d]{4}$/.test(params.value)){
|
||||||
|
var error = status.components.validationMessage(
|
||||||
|
"Confirmation code",
|
||||||
|
"Wrong format"
|
||||||
|
);
|
||||||
|
|
||||||
|
return {errors: [error]}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ function call(pathStr, paramsStr) {
|
||||||
_status_catalog
|
_status_catalog
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!fn) {
|
if (!fn) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,35 @@ function webView(url) {
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validationMessage(titleText, descriptionText) {
|
||||||
|
var titleStyle = {
|
||||||
|
color: "white",
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: "sans-serif"
|
||||||
|
};
|
||||||
|
var title = status.components.text(titleStyle, titleText);
|
||||||
|
|
||||||
|
var descriptionStyle = {
|
||||||
|
color: "white",
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: "sans-serif",
|
||||||
|
opacity: 0.9
|
||||||
|
};
|
||||||
|
var description = status.components.text(descriptionStyle, descriptionText);
|
||||||
|
|
||||||
|
var message = status.components.view(
|
||||||
|
{
|
||||||
|
backgroundColor: "red",
|
||||||
|
height: 61,
|
||||||
|
paddingLeft: 16,
|
||||||
|
paddingTop: 14,
|
||||||
|
},
|
||||||
|
[title, description]
|
||||||
|
);
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
var status = {
|
var status = {
|
||||||
command: function (h) {
|
command: function (h) {
|
||||||
var command = new Command();
|
var command = new Command();
|
||||||
|
@ -118,6 +147,7 @@ var status = {
|
||||||
image: image,
|
image: image,
|
||||||
touchable: touchable,
|
touchable: touchable,
|
||||||
scrollView: scrollView,
|
scrollView: scrollView,
|
||||||
webView: webView
|
webView: webView,
|
||||||
|
validationMessage: validationMessage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
11
run-osx.sh
11
run-osx.sh
|
@ -37,6 +37,13 @@ else
|
||||||
device_type="genymotion"
|
device_type="genymotion"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -z $2 ]
|
||||||
|
then
|
||||||
|
cljs_build="$2"
|
||||||
|
else
|
||||||
|
cljs_build="android"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$device_type" = "genymotion" ]
|
if [ "$device_type" = "genymotion" ]
|
||||||
then
|
then
|
||||||
# Find Device based on Android version 6.0.0
|
# Find Device based on Android version 6.0.0
|
||||||
|
@ -50,7 +57,7 @@ fi
|
||||||
lein voom build-deps && re-natal deps && re-natal use-android-device "${device_type}" && re-natal use-figwheel
|
lein voom build-deps && re-natal deps && re-natal use-android-device "${device_type}" && re-natal use-figwheel
|
||||||
|
|
||||||
# open figwheel in new tab
|
# open figwheel in new tab
|
||||||
tab "lein figwheel android"
|
tab "lein figwheel ${cljs_build}"
|
||||||
|
|
||||||
# open react-native package in new tab
|
# open react-native package in new tab
|
||||||
tab "react-native start"
|
tab "react-native start"
|
||||||
|
@ -62,7 +69,7 @@ adb reverse tcp:8081 tcp:8081 && adb reverse tcp:3449 tcp:3449
|
||||||
|
|
||||||
react-native run-android
|
react-native run-android
|
||||||
|
|
||||||
if [ ! -z $2 ]
|
if [ ! -z $3 ]
|
||||||
then
|
then
|
||||||
tab "appium"
|
tab "appium"
|
||||||
lein test
|
lein test
|
||||||
|
|
|
@ -96,7 +96,7 @@
|
||||||
:login [login]
|
:login [login]
|
||||||
:my-profile [my-profile])))})))
|
:my-profile [my-profile])))})))
|
||||||
|
|
||||||
(defn init []
|
(defn init [& [env]]
|
||||||
(dispatch-sync [:reset-app])
|
(dispatch-sync [:reset-app])
|
||||||
(dispatch [:initialize-crypt])
|
(dispatch [:initialize-crypt])
|
||||||
(dispatch [:initialize-geth])
|
(dispatch [:initialize-geth])
|
||||||
|
|
|
@ -18,13 +18,14 @@
|
||||||
[status-im.persistence.realm.core :as r]
|
[status-im.persistence.realm.core :as r]
|
||||||
[status-im.handlers.server :as server]
|
[status-im.handlers.server :as server]
|
||||||
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
||||||
[status-im.utils.phone-number :refer [format-phone-number]]
|
[status-im.utils.phone-number :refer [format-phone-number
|
||||||
|
valid-mobile-number?]]
|
||||||
[status-im.utils.datetime :as time]
|
[status-im.utils.datetime :as time]
|
||||||
[status-im.components.react :refer [geth]]
|
[status-im.components.react :refer [geth]]
|
||||||
[status-im.components.jail :as j]
|
[status-im.components.jail :as j]
|
||||||
[status-im.utils.types :refer [json->clj]]
|
[status-im.utils.types :refer [json->clj]]
|
||||||
[status-im.commands.utils :refer [generate-hiccup]]
|
[status-im.commands.utils :refer [generate-hiccup]]
|
||||||
status-im.chat.handlers.commands
|
[status-im.chat.handlers.commands :refer [command-prefix]]
|
||||||
status-im.chat.handlers.animation
|
status-im.chat.handlers.animation
|
||||||
status-im.chat.handlers.requests
|
status-im.chat.handlers.requests
|
||||||
status-im.chat.handlers.unviewed-messages))
|
status-im.chat.handlers.unviewed-messages))
|
||||||
|
@ -76,37 +77,28 @@
|
||||||
(when-let [message-input (:message-input db)]
|
(when-let [message-input (:message-input db)]
|
||||||
(.blur message-input)))))
|
(.blur message-input)))))
|
||||||
|
|
||||||
(defn update-text
|
(defn update-text [db [_ chat-id text]]
|
||||||
[{:keys [current-chat-id] :as db} [_ text]]
|
(assoc-in db [:chats chat-id :input-text] text))
|
||||||
(let [suggestions (get-in db [:command-suggestions current-chat-id])]
|
|
||||||
(if-not (= 1 (count suggestions))
|
|
||||||
(update-input-text db text)
|
|
||||||
(assoc db :disable-input true))))
|
|
||||||
|
|
||||||
(defn update-command [db [_ text]]
|
(defn update-command [db [_ text]]
|
||||||
(if-not (commands/get-chat-command db)
|
(if-not (commands/get-chat-command db)
|
||||||
(let [{:keys [command]} (suggestions/check-suggestion db text)]
|
(let [{:keys [command]} (suggestions/check-suggestion db text)]
|
||||||
(if command
|
(if command
|
||||||
(commands/set-chat-command db command)
|
(commands/set-command-input db :commands command)
|
||||||
db))
|
db))
|
||||||
db))
|
db))
|
||||||
|
|
||||||
(defn check-suggestions
|
(defn check-suggestions
|
||||||
[{:keys [current-chat-id] :as db} [_ text]]
|
[db [_ chat-id text]]
|
||||||
(let [suggestions (suggestions/get-suggestions db text)]
|
(let [suggestions (suggestions/get-suggestions db text)]
|
||||||
(assoc-in db [:command-suggestions current-chat-id] suggestions)))
|
(assoc-in db [:command-suggestions chat-id] suggestions)))
|
||||||
|
|
||||||
(defn select-suggestion!
|
(defn select-suggestion!
|
||||||
[{:keys [current-chat-id] :as db} [_ text]]
|
[db [_ chat-id text]]
|
||||||
(let [suggestions (get-in db [:command-suggestions current-chat-id])]
|
(let [suggestions (get-in db [:command-suggestions chat-id])]
|
||||||
(when (= 1 (count suggestions))
|
(if (= 1 (count suggestions))
|
||||||
(dispatch [:set-chat-command (ffirst suggestions)]))))
|
(dispatch [:set-chat-command (ffirst suggestions)])
|
||||||
|
(dispatch [::set-text chat-id text]))))
|
||||||
(register-handler :set-chat-input-text
|
|
||||||
[(enrich update-command)
|
|
||||||
(after select-suggestion!)
|
|
||||||
(after #(dispatch [:animate-command-suggestions]))]
|
|
||||||
((enrich update-text) check-suggestions))
|
|
||||||
|
|
||||||
(defn console? [s]
|
(defn console? [s]
|
||||||
(= "console" s))
|
(= "console" s))
|
||||||
|
@ -114,6 +106,43 @@
|
||||||
(def not-console?
|
(def not-console?
|
||||||
(complement console?))
|
(complement console?))
|
||||||
|
|
||||||
|
(register-handler :set-chat-input-text
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [{:keys [current-chat-id]} [_ text]]
|
||||||
|
(if (console? current-chat-id)
|
||||||
|
(dispatch [::check-input-for-commands text])
|
||||||
|
(dispatch [::check-suggestions current-chat-id text])))))
|
||||||
|
|
||||||
|
(def possible-commands
|
||||||
|
{[:confirmation-code :responses] #(re-matches #"^[\d]{4}$" %)
|
||||||
|
[:phone :commands] valid-mobile-number?})
|
||||||
|
|
||||||
|
(defn check-text-for-commands [text]
|
||||||
|
(ffirst (filter (fn [[_ f]] (f text)) possible-commands)))
|
||||||
|
|
||||||
|
(register-handler ::check-input-for-commands
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ text]]
|
||||||
|
(if-let [[_ type :as command] (check-text-for-commands text)]
|
||||||
|
(let [text' (if (= :commands type)
|
||||||
|
(str command-prefix text)
|
||||||
|
text)]
|
||||||
|
(dispatch [::stage-command-with-content command text']))
|
||||||
|
(dispatch [::check-suggestions "console" text])))))
|
||||||
|
|
||||||
|
(register-handler ::stage-command-with-content
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ [command type] text]]
|
||||||
|
(dispatch [:set-chat-command command type])
|
||||||
|
(dispatch [:set-chat-command-content text]))))
|
||||||
|
|
||||||
|
(register-handler ::check-suggestions
|
||||||
|
[(after select-suggestion!)
|
||||||
|
(after #(dispatch [:animate-command-suggestions]))]
|
||||||
|
check-suggestions)
|
||||||
|
|
||||||
|
(register-handler ::set-text update-text)
|
||||||
|
|
||||||
(defn check-author-direction
|
(defn check-author-direction
|
||||||
[db chat-id {:keys [from outgoing] :as message}]
|
[db chat-id {:keys [from outgoing] :as message}]
|
||||||
(let [previous-message (first (get-in db [:chats chat-id :messages]))]
|
(let [previous-message (first (get-in db [:chats chat-id :messages]))]
|
||||||
|
@ -165,7 +194,7 @@
|
||||||
:outgoing true
|
:outgoing true
|
||||||
:timestamp (time/now-ms)})]
|
:timestamp (time/now-ms)})]
|
||||||
(if command
|
(if command
|
||||||
(commands/set-chat-command db command)
|
(commands/set-command-input db :commands command)
|
||||||
(assoc db :new-message (when-not (str/blank? text) message)))))
|
(assoc db :new-message (when-not (str/blank? text) message)))))
|
||||||
|
|
||||||
(defn prepare-command
|
(defn prepare-command
|
||||||
|
@ -344,7 +373,7 @@
|
||||||
|
|
||||||
(defn store-message!
|
(defn store-message!
|
||||||
[{:keys [new-message]} [_ {chat-id :from}]]
|
[{:keys [new-message]} [_ {chat-id :from}]]
|
||||||
(messages/save-message chat-id new-message))
|
(messages/save-message chat-id new-message))
|
||||||
|
|
||||||
(defn dispatch-request!
|
(defn dispatch-request!
|
||||||
[{:keys [new-message]} [_ {chat-id :from}]]
|
[{:keys [new-message]} [_ {chat-id :from}]]
|
||||||
|
@ -448,16 +477,16 @@
|
||||||
(defn delete-messages!
|
(defn delete-messages!
|
||||||
[{:keys [current-chat-id]} _]
|
[{:keys [current-chat-id]} _]
|
||||||
(r/write :account
|
(r/write :account
|
||||||
(fn []
|
(fn []
|
||||||
(r/delete :account (r/get-by-field :account :msgs :chat-id current-chat-id)))))
|
(r/delete :account (r/get-by-field :account :msgs :chat-id current-chat-id)))))
|
||||||
|
|
||||||
(defn delete-chat!
|
(defn delete-chat!
|
||||||
[{:keys [current-chat-id]} _]
|
[{:keys [current-chat-id]} _]
|
||||||
(r/write :account
|
(r/write :account
|
||||||
(fn [] :account
|
(fn [] :account
|
||||||
(->> (r/get-by-field :account :chats :chat-id current-chat-id)
|
(->> (r/get-by-field :account :chats :chat-id current-chat-id)
|
||||||
(r/single)
|
(r/single)
|
||||||
(r/delete :account)))))
|
(r/delete :account)))))
|
||||||
|
|
||||||
(register-handler :leave-group-chat
|
(register-handler :leave-group-chat
|
||||||
;; todo oreder of operations tbd
|
;; todo oreder of operations tbd
|
||||||
|
|
|
@ -139,9 +139,9 @@
|
||||||
(commands/unstage-command db staged-command)))
|
(commands/unstage-command db staged-command)))
|
||||||
|
|
||||||
(defn set-chat-command
|
(defn set-chat-command
|
||||||
[{:keys [current-chat-id] :as db} [_ command-key]]
|
[{:keys [current-chat-id] :as db} [_ command-key type]]
|
||||||
(-> db
|
(-> db
|
||||||
(commands/set-chat-command command-key)
|
(commands/set-command-input (or type :commands) command-key)
|
||||||
(assoc-in [:chats current-chat-id :command-input :content] command-prefix)
|
(assoc-in [:chats current-chat-id :command-input :content] command-prefix)
|
||||||
(assoc :disable-input true)))
|
(assoc :disable-input true)))
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@
|
||||||
|
|
||||||
(defn set-response-command [db [_ to-msg-id command-key]]
|
(defn set-response-command [db [_ to-msg-id command-key]]
|
||||||
(-> db
|
(-> db
|
||||||
(commands/set-response-chat-command to-msg-id command-key)
|
(commands/set-command-input :responses to-msg-id command-key)
|
||||||
(assoc :canceled-command false)))
|
(assoc :canceled-command false)))
|
||||||
|
|
||||||
(register-handler :set-response-chat-command
|
(register-handler :set-response-chat-command
|
||||||
|
@ -163,6 +163,7 @@
|
||||||
set-response-command)
|
set-response-command)
|
||||||
|
|
||||||
(register-handler ::add-validation-errors
|
(register-handler ::add-validation-errors
|
||||||
|
(after #(dispatch [:fix-response-height]))
|
||||||
(fn [db [_ chat-id errors]]
|
(fn [db [_ chat-id errors]]
|
||||||
(assoc-in db [:custom-validation-errors chat-id]
|
(assoc-in db [:custom-validation-errors chat-id]
|
||||||
(map cu/generate-hiccup errors))))
|
(map cu/generate-hiccup errors))))
|
||||||
|
|
|
@ -28,6 +28,37 @@
|
||||||
(s/put kv/kv-store :signed-up signed-up)
|
(s/put kv/kv-store :signed-up signed-up)
|
||||||
(assoc db :signed-up signed-up))
|
(assoc db :signed-up signed-up))
|
||||||
|
|
||||||
|
; todo fn name is not too smart, but...
|
||||||
|
(defn command-content
|
||||||
|
[command content]
|
||||||
|
{:command (name command)
|
||||||
|
:content content})
|
||||||
|
|
||||||
|
;; -- Send phone number ----------------------------------------
|
||||||
|
(defn on-sign-up-response [& [message]]
|
||||||
|
(let [msg-id (random/id)]
|
||||||
|
(dispatch [:received-msg
|
||||||
|
{:msg-id msg-id
|
||||||
|
:content (command-content
|
||||||
|
:confirmation-code
|
||||||
|
(or message (label :t/confirmation-code)))
|
||||||
|
:content-type content-type-command-request
|
||||||
|
:outgoing false
|
||||||
|
:from "console"
|
||||||
|
:to "me"}])))
|
||||||
|
|
||||||
|
(defn handle-sms [{body :body}]
|
||||||
|
(when-let [matches (re-matches #"(\d{4})" body)]
|
||||||
|
(dispatch [:sign-up-confirm (second matches)])))
|
||||||
|
|
||||||
|
(defn start-listening-confirmation-code-sms [db]
|
||||||
|
(when (not (:confirmation-code-sms-listener db))
|
||||||
|
(assoc db :confirmation-code-sms-listener (add-sms-listener handle-sms))))
|
||||||
|
|
||||||
|
(defn stop-listening-confirmation-code-sms [db]
|
||||||
|
(when-let [listener (:confirmation-code-sms-listener db)]
|
||||||
|
(remove-sms-listener listener)
|
||||||
|
(dissoc db :confirmation-code-sms-listener)))
|
||||||
|
|
||||||
;; -- Send confirmation code and synchronize contacts---------------------------
|
;; -- Send confirmation code and synchronize contacts---------------------------
|
||||||
(defn on-sync-contacts []
|
(defn on-sync-contacts []
|
||||||
|
@ -52,43 +83,15 @@
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
(when (:confirmed body)
|
(let [status (keyword (:status body))]
|
||||||
(dispatch [:stop-listening-confirmation-code-sms])
|
(when (= :confirmed status)
|
||||||
(sync-contacts)
|
(do
|
||||||
;; TODO should be called after sync-contacts?
|
(dispatch [:stop-listening-confirmation-code-sms])
|
||||||
(dispatch [:set-signed-up true])))
|
(sync-contacts)
|
||||||
|
;; TODO should be called after sync-contacts?
|
||||||
; todo fn name is not too smart, but...
|
(dispatch [:set-signed-up true])))
|
||||||
(defn command-content
|
(when (= :failed status)
|
||||||
[command content]
|
(on-sign-up-response (label :t/incorrect-code)))))
|
||||||
{:command (name command)
|
|
||||||
:content content})
|
|
||||||
|
|
||||||
;; -- Send phone number ----------------------------------------
|
|
||||||
(defn on-sign-up-response []
|
|
||||||
(let [msg-id (random/id)]
|
|
||||||
(dispatch [:received-msg
|
|
||||||
{:msg-id msg-id
|
|
||||||
:content (command-content
|
|
||||||
:confirmation-code
|
|
||||||
(label :t/confirmation-code))
|
|
||||||
:content-type content-type-command-request
|
|
||||||
:outgoing false
|
|
||||||
:from "console"
|
|
||||||
:to "me"}])))
|
|
||||||
|
|
||||||
(defn handle-sms [{body :body}]
|
|
||||||
(when-let [matches (re-matches #"(\d{4})" body)]
|
|
||||||
(dispatch [:sign-up-confirm (second matches)])))
|
|
||||||
|
|
||||||
(defn start-listening-confirmation-code-sms [db]
|
|
||||||
(when (not (:confirmation-code-sms-listener db))
|
|
||||||
(assoc db :confirmation-code-sms-listener (add-sms-listener handle-sms))))
|
|
||||||
|
|
||||||
(defn stop-listening-confirmation-code-sms [db]
|
|
||||||
(when-let [listener (:confirmation-code-sms-listener db)]
|
|
||||||
(remove-sms-listener listener)
|
|
||||||
(dissoc db :confirmation-code-sms-listener)))
|
|
||||||
|
|
||||||
;; -- Saving password ----------------------------------------
|
;; -- Saving password ----------------------------------------
|
||||||
(defn save-password [password]
|
(defn save-password [password]
|
||||||
|
|
|
@ -76,10 +76,6 @@
|
||||||
(defn set-chat-command [msg-id command]
|
(defn set-chat-command [msg-id command]
|
||||||
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
|
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
|
||||||
|
|
||||||
(defn label [{:keys [command]}]
|
|
||||||
(->> (when command (name command))
|
|
||||||
(str "request-")))
|
|
||||||
|
|
||||||
(defn message-view
|
(defn message-view
|
||||||
[message content]
|
[message content]
|
||||||
[view (st/message-view message)
|
[view (st/message-view message)
|
||||||
|
|
|
@ -15,9 +15,10 @@
|
||||||
(defn set-chat-command [msg-id command]
|
(defn set-chat-command [msg-id command]
|
||||||
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
|
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
|
||||||
|
|
||||||
(defn label [{:keys [command]}]
|
(defn label [command]
|
||||||
(->> (name command)
|
(when command
|
||||||
(str "request-")))
|
(->> (name (:name command))
|
||||||
|
(str "request-"))))
|
||||||
|
|
||||||
(def min-scale 1)
|
(def min-scale 1)
|
||||||
(def max-scale 1.3)
|
(def max-scale 1.3)
|
||||||
|
@ -59,7 +60,8 @@
|
||||||
[touchable-highlight
|
[touchable-highlight
|
||||||
{:on-press (when-not @answered?
|
{:on-press (when-not @answered?
|
||||||
#(set-chat-command msg-id command))
|
#(set-chat-command msg-id command))
|
||||||
:style st/command-request-image-touchable}
|
:style st/command-request-image-touchable
|
||||||
|
:accessibility-label (label command)}
|
||||||
[animated-view {:style (st/command-request-image-view command scale-anim-val)}
|
[animated-view {:style (st/command-request-image-view command scale-anim-val)}
|
||||||
[image {:source {:uri (:icon command)}
|
[image {:source {:uri (:icon command)}
|
||||||
:style st/command-request-image}]]])})))
|
:style st/command-request-image}]]])})))
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
:alignItems :center
|
:alignItems :center
|
||||||
:justifyContent :center}
|
:justifyContent :center}
|
||||||
[image (:image nav-action)]]]
|
[image (:image nav-action)]]]
|
||||||
[touchable-highlight {:on-press #(dispatch [:navigate-back])}
|
[touchable-highlight {:on-press #(dispatch [:navigate-back])
|
||||||
|
:accessibility-label :navigate-back}
|
||||||
[view {:width 56
|
[view {:width 56
|
||||||
:height 56
|
:height 56
|
||||||
:alignItems :center
|
:alignItems :center
|
||||||
|
|
|
@ -16,4 +16,4 @@
|
||||||
(def response-input-hiding-duration 100)
|
(def response-input-hiding-duration 100)
|
||||||
(def response-suggesstion-resize-duration 100)
|
(def response-suggesstion-resize-duration 100)
|
||||||
|
|
||||||
(def default-number-of-messages 5)
|
(def default-number-of-messages 20)
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
[status-im.utils.crypt :refer [gen-random-bytes]]
|
[status-im.utils.crypt :refer [gen-random-bytes]]
|
||||||
[status-im.components.react :refer [geth]]
|
[status-im.components.react :refer [geth]]
|
||||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||||
[status-im.models.protocol :as protocol]
|
|
||||||
status-im.chat.handlers
|
status-im.chat.handlers
|
||||||
status-im.group-settings.handlers
|
status-im.group-settings.handlers
|
||||||
status-im.navigation.handlers
|
status-im.navigation.handlers
|
||||||
|
@ -57,8 +56,7 @@
|
||||||
(register-handler :initialize-db
|
(register-handler :initialize-db
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
(realm/reset-account)
|
(realm/reset-account)
|
||||||
(assoc app-db
|
(assoc app-db :user-identity nil)))
|
||||||
:user-identity nil)))
|
|
||||||
|
|
||||||
(register-handler :initialize-account-db
|
(register-handler :initialize-account-db
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
(defn get-commands [{:keys [current-chat-id] :as db}]
|
(defn get-commands [{:keys [current-chat-id] :as db}]
|
||||||
(or (get-in db [:chats current-chat-id :commands]) {}))
|
(or (get-in db [:chats current-chat-id :commands]) {}))
|
||||||
|
|
||||||
(defn get-command [{:keys [current-chat-id] :as db} command-key]
|
(defn get-response-or-command
|
||||||
((or (->> (get-in db [:chats current-chat-id])
|
[type {:keys [current-chat-id] :as db} command-key]
|
||||||
((juxt :commands :responses))
|
((or (get-in db [:chats current-chat-id type]) {}) command-key))
|
||||||
(apply merge))
|
|
||||||
{}) command-key))
|
|
||||||
|
|
||||||
(defn find-command [commands command-key]
|
(defn find-command [commands command-key]
|
||||||
(first (filter #(= command-key (:command %)) commands)))
|
(first (filter #(= command-key (:command %)) commands)))
|
||||||
|
@ -25,16 +23,15 @@
|
||||||
[{:keys [current-chat-id] :as db}]
|
[{:keys [current-chat-id] :as db}]
|
||||||
(get-in db (db/chat-command-path current-chat-id)))
|
(get-in db (db/chat-command-path current-chat-id)))
|
||||||
|
|
||||||
(defn set-response-chat-command
|
(defn set-command-input
|
||||||
[{:keys [current-chat-id] :as db} msg-id command-key]
|
([db type command-key]
|
||||||
(update-in db [:chats current-chat-id :command-input] merge
|
(set-command-input db type nil command-key))
|
||||||
{:content nil
|
([{:keys [current-chat-id] :as db} type msg-id command-key]
|
||||||
:command (get-command db command-key)
|
(update-in db [:chats current-chat-id :command-input] merge
|
||||||
:parameter-idx 0
|
{:content nil
|
||||||
:to-msg-id msg-id}))
|
:command (get-response-or-command type db command-key)
|
||||||
|
:parameter-idx 0
|
||||||
(defn set-chat-command [db command-key]
|
:to-msg-id msg-id})))
|
||||||
(set-response-chat-command db nil command-key))
|
|
||||||
|
|
||||||
(defn get-chat-command-to-msg-id
|
(defn get-chat-command-to-msg-id
|
||||||
[{:keys [current-chat-id] :as db}]
|
[{:keys [current-chat-id] :as db}]
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
r/collection->map))
|
r/collection->map))
|
||||||
|
|
||||||
(defn create-contact [{:keys [name photo-path whisper-identity] :as contact}]
|
(defn create-contact [{:keys [name photo-path whisper-identity] :as contact}]
|
||||||
(->> {:name (or name "")
|
(let [contact-from-db (r/get-one-by-field :account :contacts
|
||||||
:photo-path (or photo-path (identicon whisper-identity))}
|
:whisper-identity whisper-identity)]
|
||||||
(merge contact)
|
(when-not contact-from-db
|
||||||
(r/create :account :contacts)))
|
(->> {:name (or name "")
|
||||||
|
:photo-path (or photo-path (identicon whisper-identity))}
|
||||||
|
(merge contact)
|
||||||
|
(r/create :account :contacts)))))
|
||||||
|
|
||||||
(defn save-contacts [contacts]
|
(defn save-contacts [contacts]
|
||||||
(r/write :account #(mapv create-contact contacts)))
|
(r/write :account #(mapv create-contact contacts)))
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
:contacts-syncronized "Your contacts have been synchronized"
|
:contacts-syncronized "Your contacts have been synchronized"
|
||||||
:confirmation-code (str "Thanks! We've sent you a text message with a confirmation "
|
:confirmation-code (str "Thanks! We've sent you a text message with a confirmation "
|
||||||
"code. Please provide that code to confirm your phone number")
|
"code. Please provide that code to confirm your phone number")
|
||||||
|
:incorrect-code (str "Sorry the code was incorrect, please enter again")
|
||||||
:password-saved (str "OK great! Your password has been saved. Just to let you "
|
:password-saved (str "OK great! Your password has been saved. Just to let you "
|
||||||
"know you can always change it in the Console by the way "
|
"know you can always change it in the Console by the way "
|
||||||
"it's me the Console nice to meet you!")
|
"it's me the Console nice to meet you!")
|
||||||
|
|
|
@ -51,10 +51,18 @@
|
||||||
(defn xpath-by-text [text]
|
(defn xpath-by-text [text]
|
||||||
(str ".//*[@text='" text "']"))
|
(str ".//*[@text='" text "']"))
|
||||||
|
|
||||||
|
(defn click-by-text [driver text]
|
||||||
|
(let [elements (->> (xpath-by-text text)
|
||||||
|
(elements-by-xpath driver))]
|
||||||
|
(when (pos? (.size elements))
|
||||||
|
(let [element (.get elements 0)]
|
||||||
|
(.click element)))))
|
||||||
|
|
||||||
(defn contains-text [driver text]
|
(defn contains-text [driver text]
|
||||||
(is (= 1 (->> (xpath-by-text text)
|
(is (pos? (->> (xpath-by-text text)
|
||||||
(elements-by-xpath driver)
|
(elements-by-xpath driver)
|
||||||
(.size)))))
|
(.size)))
|
||||||
|
(format "Text \"%s\" was not found on screen." text)))
|
||||||
|
|
||||||
(defn quit [driver]
|
(defn quit [driver]
|
||||||
(.quit driver))
|
(.quit driver))
|
||||||
|
@ -81,6 +89,14 @@
|
||||||
(let [sym (gensym)]
|
(let [sym (gensym)]
|
||||||
`(deftest ~name
|
`(deftest ~name
|
||||||
(let [~sym (init)]
|
(let [~sym (init)]
|
||||||
|
(click-by-text ~sym "Continue")
|
||||||
~@(for [[f & rest] body]
|
~@(for [[f & rest] body]
|
||||||
`(~f ~sym ~@rest))
|
`(~f ~sym ~@rest))
|
||||||
(quit ~sym)))))
|
(quit ~sym)))))
|
||||||
|
|
||||||
|
(defmacro defaction
|
||||||
|
[name parameters & body]
|
||||||
|
(let [session (gensym)]
|
||||||
|
`(defn ~name [~@(concat [session] parameters)]
|
||||||
|
~@(for [[f & rest] body]
|
||||||
|
`(~f ~session ~@rest)))))
|
||||||
|
|
|
@ -7,9 +7,45 @@
|
||||||
" the exclamation mark or hit the icon to open the command "
|
" the exclamation mark or hit the icon to open the command "
|
||||||
"list and choose the !phone command"))
|
"list and choose the !phone command"))
|
||||||
|
|
||||||
(appium-test console-test
|
(defaction send-sommand []
|
||||||
(click :request-keypair-password)
|
|
||||||
(write :command-input "123")
|
|
||||||
(click :stage-command)
|
|
||||||
(click :send-message)
|
(click :send-message)
|
||||||
(contains-text message-text))
|
(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"))
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
(ns status-im.test.handlers-stubs
|
||||||
|
(:require [re-frame.core :refer [subscribe dispatch after]]
|
||||||
|
[status-im.utils.handlers :refer [register-handler]]
|
||||||
|
[status-im.utils.handlers :as u]
|
||||||
|
[status-im.chat.sign-up :as sign-up-service]
|
||||||
|
status-im.handlers))
|
||||||
|
|
||||||
|
(defn init-stubs []
|
||||||
|
(register-handler :sign-up
|
||||||
|
(fn []
|
||||||
|
(println :ohh)
|
||||||
|
;; todo save phone number to db
|
||||||
|
(sign-up-service/on-sign-up-response)))
|
||||||
|
|
||||||
|
(register-handler :sign-up-confirm
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ confirmation-code]]
|
||||||
|
(sign-up-service/on-send-code-response
|
||||||
|
(if (= "1234" confirmation-code)
|
||||||
|
{:message "Done!"
|
||||||
|
:status :confirmed
|
||||||
|
:confirmed true}
|
||||||
|
{:message "Wrong code!"
|
||||||
|
:status :failed
|
||||||
|
:confirmed false}))))))
|
Loading…
Reference in New Issue