diff --git a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/e2e/menu/SidebarMenuFoldersTests.kt b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/e2e/menu/SidebarMenuFoldersTests.kt index 9f1118ccd4..a1b875f5b8 100644 --- a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/e2e/menu/SidebarMenuFoldersTests.kt +++ b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/e2e/menu/SidebarMenuFoldersTests.kt @@ -29,7 +29,8 @@ import ch.protonmail.android.uitest.helpers.core.TestId import ch.protonmail.android.uitest.helpers.login.LoginStrategy import ch.protonmail.android.uitest.helpers.login.MockedLoginTestUsers.defaultLoginUser import ch.protonmail.android.uitest.helpers.network.mockNetworkDispatcher -import ch.protonmail.android.uitest.models.folders.SidebarFolderEntry +import ch.protonmail.android.uitest.models.folders.IconTint +import ch.protonmail.android.uitest.models.folders.SidebarCustomItemEntry import ch.protonmail.android.uitest.robot.menu.MenuRobot import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidTest @@ -55,16 +56,94 @@ internal class SidebarMenuFoldersTests : MockedNetworkTest(loginStrategy = Login @Test @TestId("68718") fun checkShortHexAndStandardColorFolderAreDisplayedInSidebarMenu() { - mockWebServer.dispatcher = mockNetworkDispatcher(useDefaultCustomFolders = false) { + mockWebServer.dispatcher = mockNetworkDispatcher( + useDefaultCustomFolders = false, + useDefaultMailSettings = false + ) { addMockRequests( - "/core/v4/labels?Type=3" respondWith "/core/v4/labels/labels-type3_68718.json" withStatusCode 200, - "/mail/v4/messages" respondWith "/mail/v4/messages/messages_empty.json" withStatusCode 200 ignoreQueryParams true + "/mail/v4/settings" + respondWith "/mail/v4/settings/mail-v4-settings_68718.json" + withStatusCode 200, + "/core/v4/labels?Type=3" + respondWith "/core/v4/labels/labels-type3_68718.json" + withStatusCode 200, + "/mail/v4/messages" + respondWith "/mail/v4/messages/messages_empty.json" + withStatusCode 200 ignoreQueryParams true ) } val expectedFolders = arrayOf( - SidebarFolderEntry(index = 0, name = "Shorthand Hex Folder"), - SidebarFolderEntry(index = 1, name = "Standard Folder") + SidebarCustomItemEntry(index = 0, name = "Shorthand Hex Folder", iconTint = IconTint.WithColor.Bridge), + SidebarCustomItemEntry(index = 1, name = "Standard Folder", iconTint = IconTint.WithColor.PurpleBase) + ) + + addAccountRobot + .signIn() + .loginUser(defaultLoginUser) + + menuRobot + .swipeOpenSidebarMenu() + .verify { customFoldersAreDisplayed(*expectedFolders) } + } + + @Test + @TestId("79096") + fun checkFoldersColorWhenSettingIsOffWithNoParentInheritingInSidebarMenu() { + mockWebServer.dispatcher = mockNetworkDispatcher( + useDefaultCustomFolders = false, + useDefaultMailSettings = false + ) { + addMockRequests( + "/mail/v4/settings" + respondWith "/mail/v4/settings/mail-v4-settings_79096.json" + withStatusCode 200, + "/core/v4/labels?Type=3" + respondWith "/core/v4/labels/labels-type3_79096.json" + withStatusCode 200, + "/mail/v4/messages" + respondWith "/mail/v4/messages/messages_empty.json" + withStatusCode 200 ignoreQueryParams true + ) + } + + val expectedFolders = arrayOf( + SidebarCustomItemEntry(index = 0, name = "Shorthand Hex Folder", iconTint = IconTint.NoColor), + SidebarCustomItemEntry(index = 1, name = "Standard Folder", iconTint = IconTint.NoColor) + ) + + addAccountRobot + .signIn() + .loginUser(defaultLoginUser) + + menuRobot + .swipeOpenSidebarMenu() + .verify { customFoldersAreDisplayed(*expectedFolders) } + } + + @Test + @TestId("79097") + fun checkFoldersColorWhenSettingIsOffWithParentInheritingInSidebarMenu() { + mockWebServer.dispatcher = mockNetworkDispatcher( + useDefaultCustomFolders = false, + useDefaultMailSettings = false + ) { + addMockRequests( + "/mail/v4/settings" + respondWith "/mail/v4/settings/mail-v4-settings_79097.json" + withStatusCode 200, + "/core/v4/labels?Type=3" + respondWith "/core/v4/labels/labels-type3_79097.json" + withStatusCode 200, + "/mail/v4/messages" + respondWith "/mail/v4/messages/messages_empty.json" + withStatusCode 200 ignoreQueryParams true + ) + } + + val expectedFolders = arrayOf( + SidebarCustomItemEntry(index = 0, name = "Shorthand Hex Folder", iconTint = IconTint.NoColor), + SidebarCustomItemEntry(index = 1, name = "Standard Folder", iconTint = IconTint.NoColor) ) addAccountRobot diff --git a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/IconTint.kt b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/IconTint.kt new file mode 100644 index 0000000000..ab9db72960 --- /dev/null +++ b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/IconTint.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Proton Technologies AG + * This file is part of Proton Technologies AG and Proton Mail. + * + * Proton Mail is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Proton Mail is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Proton Mail. If not, see . + */ + +package ch.protonmail.android.uitest.models.folders + +import androidx.compose.ui.graphics.Color + +internal sealed class IconTint { + object NoColor : IconTint() + + sealed class WithColor(val value: Color) : IconTint() { + object PurpleBase : WithColor(Color(0xFF8080FF)) + object Bridge : WithColor(Color(0xFFFF6666)) + class Custom(hex: Long) : WithColor(Color(hex)) + } +} diff --git a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarFolderEntry.kt b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarCustomItemEntry.kt similarity index 87% rename from app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarFolderEntry.kt rename to app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarCustomItemEntry.kt index 37923b2933..359987907c 100644 --- a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarFolderEntry.kt +++ b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarCustomItemEntry.kt @@ -18,4 +18,8 @@ package ch.protonmail.android.uitest.models.folders -data class SidebarFolderEntry(val index: Int, val name: String) +internal data class SidebarCustomItemEntry( + val index: Int, + val name: String, + val iconTint: IconTint +) diff --git a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarItemCustomEntryModels.kt b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarItemCustomEntryModels.kt new file mode 100644 index 0000000000..061645566d --- /dev/null +++ b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarItemCustomEntryModels.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Proton Technologies AG + * This file is part of Proton Technologies AG and Proton Mail. + * + * Proton Mail is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Proton Mail is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Proton Mail. If not, see . + */ + +package ch.protonmail.android.uitest.models.folders + +import androidx.compose.ui.test.hasTestTag + +internal class SidebarItemCustomLabelEntryModel( + position: Int +) : SidebarItemEntryModel(position, hasTestTag(TestTags.SidebarItemCustomLabel)) + +internal class SidebarItemCustomFolderEntryModel( + position: Int +) : SidebarItemEntryModel(position, hasTestTag(TestTags.SidebarItemCustomFolder)) + +private object TestTags { + + const val SidebarItemCustomFolder = "SidebarItemCustomFolder" + const val SidebarItemCustomLabel = "SidebarItemCustomLabel" +} diff --git a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarItemEntryModel.kt b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarItemEntryModel.kt new file mode 100644 index 0000000000..240e8ae24a --- /dev/null +++ b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/models/folders/SidebarItemEntryModel.kt @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Proton Technologies AG + * This file is part of Proton Technologies AG and Proton Mail. + * + * Proton Mail is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Proton Mail is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Proton Mail. If not, see . + */ + +package ch.protonmail.android.uitest.models.folders + +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.test.SemanticsMatcher +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.hasTestTag +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import ch.protonmail.android.maillabel.presentation.sidebar.SidebarCustomLabelTestTags +import ch.protonmail.android.uitest.util.ComposeTestRuleHolder +import ch.protonmail.android.uitest.util.assertions.assertNoTintColor +import ch.protonmail.android.uitest.util.assertions.assertTintColor +import ch.protonmail.android.uitest.util.child + +internal sealed class SidebarItemEntryModel( + position: Int, + matcher: SemanticsMatcher, + composeTestRule: ComposeContentTestRule = ComposeTestRuleHolder.rule +) { + + private val rootItem = composeTestRule.onAllNodes( + matcher = matcher, + useUnmergedTree = true + )[position] + + private val icon = rootItem.child { + hasTestTag(SidebarCustomLabelTestTags.Icon) + } + + private val text = rootItem.child { + hasTestTag(SidebarCustomLabelTestTags.Text) + } + + fun hasText(value: String) = apply { + text.assertTextEquals(value) + } + + fun hasIconTint(color: Color) = apply { + icon.assertTintColor(color) + } + + fun hasNoTintColor() = apply { + icon.assertNoTintColor() + } +} diff --git a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/robot/menu/MenuRobot.kt b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/robot/menu/MenuRobot.kt index aa0e89f6e1..8dd488dcb6 100644 --- a/app/src/uiTest/kotlin/ch/protonmail/android/uitest/robot/menu/MenuRobot.kt +++ b/app/src/uiTest/kotlin/ch/protonmail/android/uitest/robot/menu/MenuRobot.kt @@ -20,9 +20,7 @@ package ch.protonmail.android.uitest.robot.menu import androidx.annotation.IdRes import androidx.annotation.StringRes import androidx.compose.ui.test.assertIsDisplayed -import androidx.compose.ui.test.assertTextEquals import androidx.compose.ui.test.junit4.ComposeContentTestRule -import androidx.compose.ui.test.onAllNodesWithTag import androidx.compose.ui.test.onChild import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onRoot @@ -31,7 +29,9 @@ import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.swipeRight import ch.protonmail.android.mailmailbox.presentation.sidebar.TEST_TAG_SIDEBAR_MENU -import ch.protonmail.android.uitest.models.folders.SidebarFolderEntry +import ch.protonmail.android.uitest.models.folders.IconTint +import ch.protonmail.android.uitest.models.folders.SidebarCustomItemEntry +import ch.protonmail.android.uitest.models.folders.SidebarItemCustomFolderEntryModel import ch.protonmail.android.uitest.robot.contacts.ContactsRobot import ch.protonmail.android.uitest.robot.mailbox.allmail.AllMailRobot import ch.protonmail.android.uitest.robot.mailbox.archive.ArchiveRobot @@ -120,7 +120,7 @@ class MenuRobot(private val composeTestRule: ComposeContentTestRule) { } internal inline fun verify(block: Verify.() -> Unit): MenuRobot = - also { Verify(composeTestRule).apply(block) } + also { Verify().apply(block) } @Suppress("unused", "EmptyFunctionBlock") private fun selectMenuItem(@IdRes menuItemName: String) = Unit @@ -153,25 +153,19 @@ class MenuRobot(private val composeTestRule: ComposeContentTestRule) { /** * Contains all the validations that can be performed by [MenuRobot]. */ - internal class Verify(private val composeTestRule: ComposeContentTestRule) { + internal class Verify { - @Suppress("unused", "EmptyFunctionBlock") - fun menuOpened() = Unit - - @Suppress("unused", "EmptyFunctionBlock") - fun menuClosed() = Unit - - fun customFoldersAreDisplayed(vararg folders: SidebarFolderEntry) { + fun customFoldersAreDisplayed(vararg folders: SidebarCustomItemEntry) { folders.forEach { - composeTestRule - .onAllNodesWithTag(SIDEBAR_ITEM_CUSTOM_FOLDER_TAG)[it.index] - .assertTextEquals(it.name) + val item = SidebarItemCustomFolderEntryModel(it.index) + + item.hasText(it.name) + + when (it.iconTint) { + is IconTint.WithColor -> item.hasIconTint(it.iconTint.value) + is IconTint.NoColor -> item.hasNoTintColor() + } } } } - - private companion object { - - const val SIDEBAR_ITEM_CUSTOM_FOLDER_TAG = "SidebarItemCustomFolder" - } } diff --git a/scripts/uitests/AssetsFile.lock b/scripts/uitests/AssetsFile.lock index caf058f879..3fbbde5bda 100644 --- a/scripts/uitests/AssetsFile.lock +++ b/scripts/uitests/AssetsFile.lock @@ -1 +1 @@ -NETWORK_ASSETS_TARGET_REF=c17d93b8b79cf2729261c78e5577866a11c95167 +NETWORK_ASSETS_TARGET_REF=41c3b50fdeefa378257faacad6c7ec09b62f8c87