From f4468ab0f086b557419a9c66d4236cbdb12ee541 Mon Sep 17 00:00:00 2001 From: Dave Date: Sat, 28 Oct 2023 14:45:57 +0100 Subject: [PATCH] Separate setup code --- src/status_im2/integration_test/chat.cljs | 36 +++++++-------------- src/status_im2/integration_test/core.cljs | 21 ++++-------- src/status_im2/integration_test/macros.clj | 19 +++++++++++ src/status_im2/integration_test/wallet.cljs | 20 ++++-------- 4 files changed, 44 insertions(+), 52 deletions(-) create mode 100644 src/status_im2/integration_test/macros.clj diff --git a/src/status_im2/integration_test/chat.cljs b/src/status_im2/integration_test/chat.cljs index 5c38639a6176..9a614a30c3cf 100644 --- a/src/status_im2/integration_test/chat.cljs +++ b/src/status_im2/integration_test/chat.cljs @@ -12,7 +12,9 @@ [status-im2.integration-test.helpers :as helpers] [status-im2.navigation.core] [status-im2.subs.root] ; so integration tests can run independently - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:require-macros + [status-im2.integration-test.macros :refer [with-app-initialized with-account]])) (def chat-id "0x0402905bed83f0bbf993cee8239012ccb1a8bc86907ead834c1e38476a0eda71414eed0e25f525f270592a2eebb01c9119a4ed6429ba114e51f5cb0a28dae1adfd") @@ -20,12 +22,8 @@ (deftest one-to-one-chat-test (log/info "========= one-to-one-chat-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) - (rf-test/wait-for - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (rf/dispatch-sync [:chat.ui/start-chat chat-id]) ;; start a new chat (rf-test/wait-for @@ -38,12 +36,8 @@ (deftest delete-chat-test (log/info "========= delete-chat-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) - (rf-test/wait-for - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (rf/dispatch-sync [:chat.ui/start-chat chat-id]) ;; start a new chat (rf-test/wait-for @@ -59,12 +53,8 @@ (deftest mute-chat-test (log/info "========= mute-chat-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) - (rf-test/wait-for - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (rf/dispatch-sync [:chat.ui/start-chat chat-id]) ;; start a new chat (rf-test/wait-for @@ -91,12 +81,8 @@ "0x048a6773339d11ccf5fd81677b7e54daeec544a1287bd92b725047ad6faa9a9b9f8ea86ed5a226d2a994f5f46d0b43321fd8de7b7997a166e67905c8c73cd37cea" primary-name "zQ3...9cX9gA"] (rf-test/run-test-async - (helpers/initialize-app!) - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) - (rf-test/wait-for - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) ;; search for contact using compressed key (rf/dispatch [:contacts/set-new-identity compressed-key]) diff --git a/src/status_im2/integration_test/core.cljs b/src/status_im2/integration_test/core.cljs index e96d798619b4..b937c0ccc3cf 100644 --- a/src/status_im2/integration_test/core.cljs +++ b/src/status_im2/integration_test/core.cljs @@ -6,7 +6,6 @@ [status-im.events] [status-im.multiaccounts.logout.core :as logout] ; so integration tests can run independently [status-im.subs.root] - [status-im.transport.core :as transport] [status-im.utils.test :as utils.test] [status-im2.events] [status-im2.integration-test.chat] @@ -15,7 +14,9 @@ [status-im2.integration-test.wallet] [status-im2.navigation.core] ; so integration tests can run independently [status-im2.subs.root] - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:require-macros + [status-im2.integration-test.macros :refer [with-app-initialized with-account]])) (utils.test/init!) @@ -34,12 +35,8 @@ (deftest create-account-test (log/info "====== create-account-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) ; initialize app - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) ; create a multiaccount - (rf-test/wait-for ; wait for login - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (helpers/logout!) (rf-test/wait-for [::logout/logout-method]))))) @@ -47,12 +44,8 @@ (deftest create-community-test (log/info "====== create-community-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) ; initialize app - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) ; create a multiaccount - (rf-test/wait-for ; wait for login - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (rf/dispatch-sync [:legacy-only-for-e2e/open-create-community]) (doseq [[k v] (dissoc constants/community :membership)] diff --git a/src/status_im2/integration_test/macros.clj b/src/status_im2/integration_test/macros.clj new file mode 100644 index 000000000000..8e47ce444488 --- /dev/null +++ b/src/status_im2/integration_test/macros.clj @@ -0,0 +1,19 @@ +(ns status-im2.integration-test.macros + (:require [day8.re-frame.test :as rf-test] + [re-frame.core :as rf])) + +(defmacro with-app-initialized + [& body] + `(do + (rf/dispatch [:app-started]) + (rf-test/wait-for + [:profile/get-profiles-overview-success] + ~@body))) + +(defmacro with-account + [& body] + `(do + (status-im2.integration-test.helpers/create-multiaccount!) + (rf-test/wait-for + [:status-im.transport.core/messenger-started] + ~@body))) \ No newline at end of file diff --git a/src/status_im2/integration_test/wallet.cljs b/src/status_im2/integration_test/wallet.cljs index 372f6c856852..158ef706433b 100644 --- a/src/status_im2/integration_test/wallet.cljs +++ b/src/status_im2/integration_test/wallet.cljs @@ -12,17 +12,15 @@ [status-im2.integration-test.helpers :as helpers] [status-im2.navigation.core] [status-im2.subs.root] - [taoensso.timbre :as log])) + [taoensso.timbre :as log]) + (:require-macros + [status-im2.integration-test.macros :refer [with-app-initialized with-account]])) (deftest create-wallet-account-test (log/info "====== create-wallet-account-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) ; create a multiaccount - (rf-test/wait-for ; wait for login - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (helpers/create-new-account!) ; create a new account (rf-test/wait-for @@ -34,12 +32,8 @@ (deftest back-up-seed-phrase-test (log/info "========= back-up-seed-phrase-test ==================") (rf-test/run-test-async - (helpers/initialize-app!) - (rf-test/wait-for - [:profile/get-profiles-overview-success] - (helpers/create-multiaccount!) - (rf-test/wait-for - [::transport/messenger-started] + (with-app-initialized + (with-account (helpers/assert-messenger-started) (rf/dispatch-sync [:set-in [:my-profile/seed :step] :12-words]) ; display seed phrase to user (rf/dispatch-sync [:my-profile/enter-two-random-words]) ; begin prompting user for seed words