Update Assertions, minor refactoring

The assertions file is getting a bit crowded, let's split it up.

MAILANDR-528
This commit is contained in:
Niccolò Forlini
2023-04-13 07:35:39 +00:00
parent 0cc44a9dc5
commit 641fbb284c
9 changed files with 110 additions and 16 deletions
@@ -28,9 +28,9 @@ import androidx.compose.ui.test.performClick
import ch.protonmail.android.mailcommon.presentation.compose.AvatarTestTags
import ch.protonmail.android.mailmailbox.presentation.mailbox.MailboxItemTestTags
import ch.protonmail.android.uitest.util.ComposeTestRuleHolder
import ch.protonmail.android.uitest.util.assertTextColor
import ch.protonmail.android.uitest.util.assertions.assertTextColor
import ch.protonmail.android.uitest.util.child
import ch.protonmail.android.uitest.util.peek
import ch.protonmail.android.uitest.util.extensions.peek
class MailboxListItemEntryModel(
position: Int,
@@ -124,7 +124,7 @@ class MailboxListItemEntryModel(
private companion object {
const val MessageReadTextColorHex = 0xFF706D6B // Equivalent to ProtonPalette.Cinder
const val MessageReadTextColorHex = 0xFF706D6B // Equivalent to ProtonPalette.Cinder
const val MessageUnreadTextColorHex = 0xFF0C0C14 // Equivalent to ProtonPalette.DoveGray
}
}
@@ -23,7 +23,7 @@ import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.onFirst
import ch.protonmail.android.mailsettings.presentation.R
import ch.protonmail.android.mailsettings.presentation.R.string
import ch.protonmail.android.uitest.util.assertTextContains
import ch.protonmail.android.uitest.util.assertions.assertTextContains
import ch.protonmail.android.uitest.util.onAllNodesWithText
/**
@@ -24,7 +24,7 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.performClick
import ch.protonmail.android.mailsettings.presentation.R.string
import ch.protonmail.android.uitest.util.assertTextContains
import ch.protonmail.android.uitest.util.assertions.assertTextContains
import ch.protonmail.android.uitest.util.awaitDisplayed
import ch.protonmail.android.uitest.util.onNodeWithText
@@ -29,7 +29,7 @@ import ch.protonmail.android.mailsettings.presentation.accountsettings.AccountSe
import ch.protonmail.android.mailsettings.presentation.accountsettings.AccountSettingsState.Data
import ch.protonmail.android.mailsettings.presentation.accountsettings.TEST_TAG_ACCOUNT_SETTINGS_LIST
import ch.protonmail.android.test.annotations.suite.RegressionTest
import ch.protonmail.android.uitest.util.assertTextContains
import ch.protonmail.android.uitest.util.assertions.assertTextContains
import ch.protonmail.android.uitest.util.hasText
import ch.protonmail.android.uitest.util.onNodeWithText
import me.proton.core.compose.theme.ProtonTheme
@@ -157,5 +157,4 @@ internal class AccountSettingsScreenTest {
.performScrollToNode(hasText(string.mail_settings_snooze_notifications))
.assertIsDisplayed()
}
}
@@ -34,7 +34,7 @@ import ch.protonmail.android.mailsettings.presentation.settings.MainSettingsScre
import ch.protonmail.android.mailsettings.presentation.settings.SettingsState.Data
import ch.protonmail.android.mailsettings.presentation.settings.TEST_TAG_SETTINGS_LIST
import ch.protonmail.android.test.annotations.suite.RegressionTest
import ch.protonmail.android.uitest.util.assertTextContains
import ch.protonmail.android.uitest.util.assertions.assertTextContains
import ch.protonmail.android.uitest.util.hasText
import ch.protonmail.android.uitest.util.onNodeWithText
import me.proton.core.compose.theme.ProtonTheme
@@ -0,0 +1,24 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.uitest.util.assertions
internal object CustomSemanticsPropertyKeyNames {
const val TintColorKey = "TintColorKey"
}
@@ -16,13 +16,15 @@
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.uitest.util
package ch.protonmail.android.uitest.util.assertions
import androidx.annotation.StringRes
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertTextContains
import ch.protonmail.android.uitest.util.getString
import ch.protonmail.android.uitest.util.hasTextColor
fun SemanticsNodeInteraction.assertTextColor(
color: Long
@@ -37,10 +39,3 @@ fun SemanticsNodeInteraction.assertTextContains(
substring: Boolean = false,
ignoreCase: Boolean = false
): SemanticsNodeInteraction = assertTextContains(getString(valueRes), substring, ignoreCase)
/**
* Returns a [Boolean] indicating whether the item exists or not, without throwing an exception.
*/
fun SemanticsNodeInteraction.peek(): Boolean {
return runCatching { assertExists() }.isSuccess
}
@@ -0,0 +1,39 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.uitest.util.assertions
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.SemanticsNodeInteraction
import ch.protonmail.android.uitest.util.extensions.getKeyValueByName
import org.junit.Assert.assertEquals
import kotlin.test.assertNull
fun SemanticsNodeInteraction.assertTintColor(tintColor: Color) = apply {
val tintColorProperty = getKeyValueByName(CustomSemanticsPropertyKeyNames.TintColorKey)
?: throw AssertionError("Expected TintColorKey property was not found on this node.")
assertEquals(tintColor, tintColorProperty.value)
}
fun SemanticsNodeInteraction.assertNoTintColor() = apply {
val tintColorProperty = getKeyValueByName(CustomSemanticsPropertyKeyNames.TintColorKey)
?: throw AssertionError("Expected TintColorKey property was not found on this node.")
assertNull(tintColorProperty.value)
}
@@ -0,0 +1,37 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.uitest.util.extensions
import androidx.compose.ui.test.SemanticsNodeInteraction
/**
* Returns a [Map.Entry] instance for the provided key, null if no entry exists.
*/
fun SemanticsNodeInteraction.getKeyValueByName(key: String): Map.Entry<*, *>? {
return fetchSemanticsNode().config.firstOrNull {
it.key.name == key
}
}
/**
* Returns a [Boolean] indicating whether the item exists or not, without throwing an exception.
*/
fun SemanticsNodeInteraction.peek(): Boolean {
return runCatching { assertExists() }.isSuccess
}