From 4f56712c6748f436d7191a4f1c03b9176fbe9b5c Mon Sep 17 00:00:00 2001
From: Ming Rui Zhang <mingrui.zhang@savoirfairelinux.com>
Date: Thu, 29 Jul 2021 16:43:38 -0400
Subject: [PATCH] wizardviewstepmodel: remove profile page flow from imported
 accounts

Gitlab: #470

Change-Id: I9dd65e83885e89b447d6354c984d3d707e9f7061
---
 src/wizardviewstepmodel.cpp      |  9 ++++--
 tests/qml/src/tst_WizardView.qml | 48 ++++++++++++++++++++------------
 2 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/wizardviewstepmodel.cpp b/src/wizardviewstepmodel.cpp
index 7efe12e59..90117605a 100644
--- a/src/wizardviewstepmodel.cpp
+++ b/src/wizardviewstepmodel.cpp
@@ -36,10 +36,13 @@ WizardViewStepModel::WizardViewStepModel(LRCInstance* lrcInstance,
         accountAdapter_->changeAccount(index);
 
         auto accountCreationOption = get_accountCreationOption();
-        if (accountCreationOption == AccountCreationOption::ConnectToAccountManager
-            || accountCreationOption == AccountCreationOption::ImportFromBackup
-            || accountCreationOption == AccountCreationOption::ImportFromDevice)
+        if (accountCreationOption == AccountCreationOption::ConnectToAccountManager)
             set_mainStep(MainSteps::Profile);
+        else if (accountCreationOption == AccountCreationOption::ImportFromBackup
+                 || accountCreationOption == AccountCreationOption::ImportFromDevice) {
+            Q_EMIT closeWizardView();
+            reset();
+        }
 
         Q_EMIT accountIsReady(accountId);
     });
diff --git a/tests/qml/src/tst_WizardView.qml b/tests/qml/src/tst_WizardView.qml
index 0f7d8314e..75d2e5fe7 100644
--- a/tests/qml/src/tst_WizardView.qml
+++ b/tests/qml/src/tst_WizardView.qml
@@ -29,6 +29,14 @@ import "qrc:/src/wizardview"
 WizardView {
     id: uut
 
+    function clearSignalSpy() {
+        spyAccountIsReady.clear()
+        spyAccountIsRemoved.clear()
+        spyAccountConfigFinalized.clear()
+        spyReportFailure.clear()
+        spyCloseWizardView.clear()
+    }
+
     SignalSpy {
         id: spyAccountIsReady
 
@@ -64,6 +72,13 @@ WizardView {
         signalName: "reportFailure"
     }
 
+    SignalSpy {
+        id: spyCloseWizardView
+
+        target: WizardViewStepModel
+        signalName: "closeWizardView"
+    }
+
     TestCase {
         name: "WelcomePage to different account creation page and return back"
         when: windowShown
@@ -195,10 +210,7 @@ WizardView {
         when: windowShown
 
         function test_createJamiAccountUiFlow() {
-            spyAccountIsReady.clear()
-            spyAccountIsRemoved.clear()
-            spyAccountStatusChanged.clear()
-            spyAccountConfigFinalized.clear()
+            uut.clearSignalSpy()
 
             var controlPanelStackView = findChild(uut, "controlPanelStackView")
 
@@ -265,6 +277,9 @@ WizardView {
                 WizardViewStepModel.nextStep()
             }
 
+            spyCloseWizardView.wait()
+            compare(spyCloseWizardView.count, 1)
+
             // Check alias text
             compare(SettingsAdapter.getCurrentAccount_Profile_Info_Alias(), aliasText)
 
@@ -286,10 +301,7 @@ WizardView {
         }
 
         function test_createRendezVousAccountUiFlow() {
-            spyAccountIsReady.clear()
-            spyAccountIsRemoved.clear()
-            spyAccountStatusChanged.clear()
-            spyAccountConfigFinalized.clear()
+            uut.clearSignalSpy()
 
             var controlPanelStackView = findChild(uut, "controlPanelStackView")
 
@@ -359,6 +371,9 @@ WizardView {
                 WizardViewStepModel.nextStep()
             }
 
+            spyCloseWizardView.wait()
+            compare(spyCloseWizardView.count, 1)
+
             // Check alias text
             compare(SettingsAdapter.getCurrentAccount_Profile_Info_Alias(), aliasText)
 
@@ -385,10 +400,7 @@ WizardView {
         when: windowShown
 
         function test_createSipAccountUiFlow() {
-            spyAccountIsReady.clear()
-            spyAccountIsRemoved.clear()
-            spyAccountStatusChanged.clear()
-            spyAccountConfigFinalized.clear()
+            uut.clearSignalSpy()
 
             var controlPanelStackView = findChild(uut, "controlPanelStackView")
 
@@ -445,6 +457,9 @@ WizardView {
 
             WizardViewStepModel.nextStep()
 
+            spyCloseWizardView.wait()
+            compare(spyCloseWizardView.count, 1)
+
             AccountAdapter.deleteCurrentAccount()
 
             // Wait until the account removal is finished
@@ -458,10 +473,7 @@ WizardView {
         when: windowShown
 
         function test_createJamiAccountFromBackupUiFlow() {
-            spyAccountIsReady.clear()
-            spyAccountIsRemoved.clear()
-            spyAccountConfigFinalized.clear()
-            spyReportFailure.clear()
+            uut.clearSignalSpy()
 
             var controlPanelStackView = findChild(uut, "controlPanelStackView")
 
@@ -506,8 +518,8 @@ WizardView {
             compare(spyAccountIsReady.count, 1)
             spyAccountConfigFinalized.wait()
             compare(spyAccountConfigFinalized.count, 1)
-
-            WizardViewStepModel.nextStep()
+            spyCloseWizardView.wait()
+            compare(spyCloseWizardView.count, 1)
 
             AccountAdapter.deleteCurrentAccount()
 
-- 
GitLab