|
| 1 | +/* |
| 2 | + * Wire |
| 3 | + * Copyright (C) 2025 Wire Swiss GmbH |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see http://www.gnu.org/licenses/. |
| 17 | + */ |
| 18 | +package com.wire.android.tests.core.criticalFlows |
| 19 | + |
| 20 | +import SSOServiceHelper.thereIsASSOTeamOwnerForOkta |
| 21 | +import SSOServiceHelper.userAddsOktaUser |
| 22 | +import SSOServiceHelper.userXIsMe |
| 23 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 24 | +import org.junit.runner.RunWith |
| 25 | +import android.content.Context |
| 26 | +import androidx.test.platform.app.InstrumentationRegistry |
| 27 | +import androidx.test.uiautomator.UiDevice |
| 28 | +import backendUtils.BackendClient |
| 29 | +import backendUtils.team.TeamHelper |
| 30 | +import backendUtils.team.deleteTeam |
| 31 | +import com.wire.android.tests.core.di.testModule |
| 32 | +import com.wire.android.tests.core.pages.AllPages |
| 33 | +import com.wire.android.tests.support.UiAutomatorSetup |
| 34 | +import deleteDownloadedFilesContaining |
| 35 | +import kotlinx.coroutines.runBlocking |
| 36 | +import okta.OktaApiClient |
| 37 | +import org.junit.After |
| 38 | +import org.junit.Before |
| 39 | +import org.junit.Rule |
| 40 | +import org.junit.Test |
| 41 | +import org.koin.test.KoinTest |
| 42 | +import org.koin.test.KoinTestRule |
| 43 | +import org.koin.test.inject |
| 44 | +import service.TestServiceHelper |
| 45 | +import uiautomatorutils.UiWaitUtils.WaitUtils.waitFor |
| 46 | +import user.usermanager.ClientUserManager |
| 47 | +import user.utils.ClientUser |
| 48 | +import kotlin.getValue |
| 49 | + |
| 50 | +@RunWith(AndroidJUnit4::class) |
| 51 | +class SSODeviceBackup : KoinTest { |
| 52 | + |
| 53 | + @get:Rule |
| 54 | + val koinTestRule = KoinTestRule.Companion.create { |
| 55 | + modules(testModule) |
| 56 | + } |
| 57 | + private val pages: AllPages by inject() |
| 58 | + private lateinit var device: UiDevice |
| 59 | + |
| 60 | + lateinit var context: Context |
| 61 | + var teamOwner: ClientUser? = null |
| 62 | + var member1: ClientUser? = null |
| 63 | + private lateinit var oktaApiClient: OktaApiClient |
| 64 | + |
| 65 | + var backendClient: BackendClient? = null |
| 66 | + val teamServiceHelper by lazy { |
| 67 | + TestServiceHelper() |
| 68 | + } |
| 69 | + val teamHelper by lazy { |
| 70 | + TeamHelper() |
| 71 | + } |
| 72 | + |
| 73 | + @Before |
| 74 | + fun setUp() { |
| 75 | + context = InstrumentationRegistry.getInstrumentation().context |
| 76 | + device = UiAutomatorSetup.start(UiAutomatorSetup.APP_INTERNAL) |
| 77 | + backendClient = BackendClient.loadBackend("STAGING") |
| 78 | + oktaApiClient = OktaApiClient() |
| 79 | + } |
| 80 | + |
| 81 | + @After |
| 82 | + fun tearDown() { |
| 83 | + teamOwner?.deleteTeam(backendClient!!) |
| 84 | + deleteDownloadedFilesContaining("Wire") |
| 85 | + oktaApiClient.cleanUp() |
| 86 | + } |
| 87 | + |
| 88 | + @Suppress("CyclomaticComplexMethod", "LongMethod") |
| 89 | + @Test |
| 90 | + fun givenSSOTeamWithOkta_whenSettingUpNewDeviceAndRestoringBackup_thenMessageIsRestored() { |
| 91 | + |
| 92 | + runBlocking { |
| 93 | + |
| 94 | + teamServiceHelper.thereIsASSOTeamOwnerForOkta( |
| 95 | + context, |
| 96 | + "user1Name", |
| 97 | + "Messaging", |
| 98 | + oktaApiClient |
| 99 | + ) |
| 100 | + |
| 101 | + teamServiceHelper.userAddsOktaUser("user1Name", "user2Name", oktaApiClient) |
| 102 | + |
| 103 | + teamServiceHelper.userXIsMe("user2Name") |
| 104 | + |
| 105 | + teamOwner = teamHelper.usersManager.findUserBy( |
| 106 | + "user1Name", |
| 107 | + ClientUserManager.FindBy.NAME_ALIAS |
| 108 | + ) |
| 109 | + member1 = teamHelper.usersManager.findUserBy( |
| 110 | + "user2Name", |
| 111 | + ClientUserManager.FindBy.NAME_ALIAS |
| 112 | + ) |
| 113 | + |
| 114 | + val ssoCode = SSOServiceHelper.getSSOCode() |
| 115 | + waitFor(20) // Delay added to allow Okta app assignment to fully sync and avoid 403 error |
| 116 | + pages.registrationPage.apply { |
| 117 | + assertEmailWelcomePage() |
| 118 | + } |
| 119 | + pages.loginPage.apply { |
| 120 | + clickStagingDeepLink() |
| 121 | + clickProceedButtonOnDeeplinkOverlay() |
| 122 | + } |
| 123 | + pages.loginPage.apply { |
| 124 | + enterSSOCodeOnSSOLoginTab(ssoCode) |
| 125 | + clickLoginButton() |
| 126 | + } |
| 127 | + pages.ssoPage.apply { |
| 128 | + enterOktaEmail(member1?.email ?: "") |
| 129 | + enterOktaPassword(member1?.password ?: "") |
| 130 | + tapOktaSignIn() |
| 131 | + } |
| 132 | + pages.registrationPage.apply { |
| 133 | + clickAllowNotificationButton() |
| 134 | + setUserName(member1?.uniqueUsername.orEmpty()) |
| 135 | + clickConfirmButton() |
| 136 | + waitUntilLoginFlowIsCompleted() |
| 137 | + clickDeclineShareDataAlert() |
| 138 | + } |
| 139 | + pages.conversationListPage.apply { |
| 140 | + tapStartNewConversationButton() |
| 141 | + } |
| 142 | + pages.searchPage.apply { |
| 143 | + tapSearchPeopleField() |
| 144 | + typeUserNameInSearchField("user1Name") |
| 145 | + assertUsernameInSearchResultIs(teamOwner?.name ?: "") |
| 146 | + tapUsernameInSearchResult(teamOwner?.name ?: "") |
| 147 | + } |
| 148 | + pages.connectedUserProfilePage.apply { |
| 149 | + assertStartConversationButtonVisible() |
| 150 | + clickStartConversationButton() |
| 151 | + } |
| 152 | + pages.conversationViewPage.apply { |
| 153 | + assertConversationScreenVisible() |
| 154 | + typeMessageInInputField("Testing of the backup functionality") |
| 155 | + clickSendButton() |
| 156 | + assertSentMessageIsVisibleInCurrentConversation("Testing of the backup functionality") |
| 157 | + tapBackButtonToCloseConversationViewPage() |
| 158 | + } |
| 159 | + pages.connectedUserProfilePage.apply { |
| 160 | + tapCloseButtonOnConnectedUserProfilePage() |
| 161 | + } |
| 162 | + pages.conversationListPage.apply { |
| 163 | + clickCloseButtonOnNewConversationScreen() |
| 164 | + assertConversationListVisible() |
| 165 | + } |
| 166 | + pages.conversationListPage.apply { |
| 167 | + clickConversationsMenuEntry() |
| 168 | + clickSettingsButtonOnMenuEntry() |
| 169 | + } |
| 170 | + pages.settingsPage.apply { |
| 171 | + openBackupAndRestoreConversationsMenu() |
| 172 | + iSeeBackupPageHeading() |
| 173 | + clickCreateBackupButton() |
| 174 | + clickBackUpNowButton() |
| 175 | + iSeeBackupConfirmation("Conversations successfully saved") |
| 176 | + iTapSaveFileButton() |
| 177 | + iTapSaveInOSMenuButton() |
| 178 | + iSeeBackupPageHeading() |
| 179 | + clickBackButtonOnSettingsPage() |
| 180 | + } |
| 181 | + pages.conversationListPage.apply { |
| 182 | + clickConversationsMenuEntry() |
| 183 | + clickConversationsButtonOnMenuEntry() |
| 184 | + clickUserProfileButton() |
| 185 | + } |
| 186 | + pages.selfUserProfilePage.apply { |
| 187 | + iSeeUserProfilePage() |
| 188 | + tapLogoutButton() |
| 189 | + iSeeClearDataOnLogOutAlert() |
| 190 | + iSeeInfoTextCheckbox("Delete all your personal information and conversations on this device") |
| 191 | + tapInfoTextCheckbox() |
| 192 | + tapLogoutButton() |
| 193 | + } |
| 194 | + pages.registrationPage.apply { |
| 195 | + assertEmailWelcomePage() |
| 196 | + } |
| 197 | + pages.loginPage.apply { |
| 198 | + clickStagingDeepLink() |
| 199 | + clickProceedButtonOnDeeplinkOverlay() |
| 200 | + } |
| 201 | + pages.loginPage.apply { |
| 202 | + enterSSOCodeOnSSOLoginTab(ssoCode) |
| 203 | + clickLoginButton() |
| 204 | + } |
| 205 | + pages.registrationPage.apply { |
| 206 | + waitUntilLoginFlowIsCompleted() |
| 207 | + clickDeclineShareDataAlert() |
| 208 | + } |
| 209 | + pages.conversationListPage.apply { |
| 210 | + assertConversationIsVisibleWithTeamOwner(teamOwner?.name ?: "") |
| 211 | + tapConversationNameInConversationList(teamOwner?.name ?: "") |
| 212 | + } |
| 213 | + pages.conversationViewPage.apply { |
| 214 | + assertMessageNotVisible("Testing of the backup functionality") |
| 215 | + tapBackButtonToCloseConversationViewPage() |
| 216 | + } |
| 217 | + pages.conversationListPage.apply { |
| 218 | + |
| 219 | + clickConversationsMenuEntry() |
| 220 | + clickSettingsButtonOnMenuEntry() |
| 221 | + } |
| 222 | + pages.settingsPage.apply { |
| 223 | + openBackupAndRestoreConversationsMenu() |
| 224 | + iSeeBackupPageHeading() |
| 225 | + clickRestoreBackupButton() |
| 226 | + clickChooseBackupFileButton() |
| 227 | + selectBackupFileInDocumentsUI(teamHelper, "user2Name") |
| 228 | + waitUntilThisTextIsDisplayedOnBackupAlert("Conversations have been restored") |
| 229 | + clickOkButtonOnBackupAlert() |
| 230 | + } |
| 231 | + pages.conversationListPage.apply { |
| 232 | + assertConversationListVisible() |
| 233 | + assertConversationIsVisibleWithTeamOwner(teamOwner?.name ?: "") |
| 234 | + tapConversationNameInConversationList(teamOwner?.name ?: "") |
| 235 | + } |
| 236 | + pages.conversationViewPage.apply { |
| 237 | + assertMessageNotVisible("Testing of the backup functionality") |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | +} |
0 commit comments