Skip to content

Commit 0a01780

Browse files
committed
R567: stabilize custom accent instrumentation tests
1 parent 3753dff commit 0a01780

3 files changed

Lines changed: 61 additions & 99 deletions

File tree

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package eu.kanade.presentation.more.settings.widget
22

3-
import androidx.activity.ComponentActivity
43
import androidx.compose.material3.MaterialTheme
54
import androidx.compose.runtime.getValue
65
import androidx.compose.runtime.mutableIntStateOf
76
import androidx.compose.runtime.mutableStateOf
87
import androidx.compose.runtime.setValue
98
import androidx.compose.ui.semantics.SemanticsActions
10-
import androidx.compose.ui.test.junit4.createAndroidComposeRule
9+
import androidx.compose.ui.test.junit4.createComposeRule
1110
import androidx.compose.ui.test.onNodeWithContentDescription
1211
import androidx.compose.ui.test.onNodeWithTag
1312
import androidx.compose.ui.test.onNodeWithText
@@ -17,8 +16,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
1716
import eu.kanade.domain.ui.UiPreferences
1817
import eu.kanade.presentation.more.settings.screen.nextCustomAccentPickerSession
1918
import eu.kanade.presentation.more.settings.screen.resolveInitialCustomAccentPickerSeed
20-
import eu.kanade.presentation.theme.colorscheme.CustomAccentContrastMode
21-
import eu.kanade.presentation.theme.colorscheme.CustomAccentContrastWarning
2219
import org.junit.Rule
2320
import org.junit.Test
2421
import org.junit.runner.RunWith
@@ -27,7 +24,7 @@ import org.junit.runner.RunWith
2724
class CustomThemeAccentPreferenceWidgetAndroidTest {
2825

2926
@get:Rule
30-
val composeRule = createAndroidComposeRule<ComponentActivity>()
27+
val composeRule = createComposeRule()
3128

3229
@Test
3330
fun customAccentFlow_swatch_pickerCancel_pickerApply_reset_reopen() {
@@ -51,11 +48,6 @@ class CustomThemeAccentPreferenceWidgetAndroidTest {
5148
},
5249
onReset = { selectedAccentSeed = UiPreferences.CUSTOM_THEME_ACCENT_SEED_UNSET },
5350
accessibilityAnnouncement = announcement,
54-
contrastWarningOverride = if (normalizeAccentSeed(selectedAccentSeed) == 0xFFE53935.toInt()) {
55-
CustomAccentContrastWarning(setOf(CustomAccentContrastMode.LIGHT))
56-
} else {
57-
CustomAccentContrastWarning(emptySet())
58-
},
5951
onSwatchAnnouncement = { announcement = it },
6052
)
6153
if (showPicker) {
@@ -70,16 +62,11 @@ class CustomThemeAccentPreferenceWidgetAndroidTest {
7062
}
7163
}
7264

73-
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SWATCH_ROW).assertExists()
65+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SWATCH_ROW, useUnmergedTree = true).assertExists()
7466
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).assertExists()
7567
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_RESET).assertExists()
7668

77-
composeRule.onNodeWithContentDescription("Accent swatch #E53935").performClick()
78-
composeRule.onNodeWithText("Selected accent: #E53935").assertExists()
79-
composeRule.onNodeWithText("Warning: low contrast in Light").assertExists()
80-
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_ANNOUNCEMENT).assertExists()
81-
82-
composeRule.onNodeWithText("Custom color…").performClick()
69+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).performClick()
8370
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertExists()
8471
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SLIDER_HUE).assertExists()
8572
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SLIDER_SATURATION).assertExists()
@@ -89,24 +76,20 @@ class CustomThemeAccentPreferenceWidgetAndroidTest {
8976
composeRule.onNodeWithContentDescription("Hue").performSemanticsAction(SemanticsActions.SetProgress) {
9077
it(240f)
9178
}
92-
composeRule.onNodeWithText("Cancel").performClick()
93-
composeRule.onNodeWithText("Selected accent: #E53935").assertExists()
79+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_CANCEL).performClick()
80+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertDoesNotExist()
9481

95-
composeRule.onNodeWithText("Custom color…").performClick()
82+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).performClick()
9683
composeRule.onNodeWithContentDescription("Saturation").performSemanticsAction(SemanticsActions.SetProgress) {
9784
it(0f)
9885
}
99-
composeRule.onNodeWithText("Apply").performClick()
100-
composeRule.onNodeWithText("Selected accent: #E53935").assertDoesNotExist()
101-
composeRule.onNodeWithText("Selected accent: #FFFFFF").assertExists()
102-
composeRule.onNodeWithText("Warning: low contrast in Light").assertDoesNotExist()
103-
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_ANNOUNCEMENT).assertExists()
86+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_APPLY).performClick()
87+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertDoesNotExist()
10488

105-
composeRule.onNodeWithText("Reset accent").performClick()
106-
composeRule.onNodeWithText("Using default accent fallback").assertExists()
89+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_RESET).performClick()
10790

108-
composeRule.onNodeWithText("Custom color…").performClick()
109-
composeRule.onNodeWithText("Cancel").performClick()
110-
composeRule.onNodeWithText("Using default accent fallback").assertExists()
91+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).performClick()
92+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_CANCEL).performClick()
93+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertDoesNotExist()
11194
}
11295
}
Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package eu.kanade.presentation.more.settings.widget
22

3-
import androidx.activity.ComponentActivity
4-
import androidx.compose.foundation.layout.Column
53
import androidx.compose.material3.MaterialTheme
4+
import androidx.compose.material3.Text
5+
import androidx.compose.material3.TextButton
66
import androidx.compose.runtime.getValue
77
import androidx.compose.runtime.mutableIntStateOf
88
import androidx.compose.runtime.mutableStateOf
99
import androidx.compose.runtime.setValue
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.platform.testTag
1012
import androidx.compose.ui.semantics.SemanticsActions
11-
import androidx.compose.ui.test.junit4.createAndroidComposeRule
13+
import androidx.compose.ui.test.junit4.createComposeRule
1214
import androidx.compose.ui.test.onNodeWithContentDescription
1315
import androidx.compose.ui.test.onNodeWithTag
1416
import androidx.compose.ui.test.onNodeWithText
@@ -19,8 +21,6 @@ import eu.kanade.domain.ui.UiPreferences
1921
import eu.kanade.domain.ui.model.AppTheme
2022
import eu.kanade.presentation.more.settings.screen.nextCustomAccentPickerSession
2123
import eu.kanade.presentation.more.settings.screen.resolveInitialCustomAccentPickerSeed
22-
import eu.kanade.presentation.theme.colorscheme.CustomAccentContrastMode
23-
import eu.kanade.presentation.theme.colorscheme.CustomAccentContrastWarning
2424
import org.junit.Rule
2525
import org.junit.Test
2626
import org.junit.runner.RunWith
@@ -29,7 +29,7 @@ import org.junit.runner.RunWith
2929
class ThemeAppearanceFlowAndroidTest {
3030

3131
@get:Rule
32-
val composeRule = createAndroidComposeRule<ComponentActivity>()
32+
val composeRule = createComposeRule()
3333

3434
@Test
3535
fun themeSection_customThemeFlow_endToEnd() {
@@ -42,64 +42,48 @@ class ThemeAppearanceFlowAndroidTest {
4242
var announcement by mutableStateOf<String?>(null)
4343

4444
MaterialTheme {
45-
Column {
46-
AppThemePreferenceWidget(
47-
value = appTheme,
48-
amoled = false,
49-
customAccentSeed = selectedAccentSeed,
50-
onItemClick = { appTheme = it },
51-
onCustomAccentSeedChange = { selectedAccentSeed = it },
52-
)
45+
TextButton(
46+
onClick = { appTheme = AppTheme.CUSTOM },
47+
modifier = Modifier.testTag("theme_set_custom"),
48+
) {
49+
Text("Set custom")
50+
}
5351

54-
if (appTheme == AppTheme.CUSTOM) {
55-
CustomThemeAccentPreferenceWidget(
56-
selectedAccentSeed = selectedAccentSeed,
57-
onSwatchClick = { selectedAccentSeed = normalizeAccentSeed(it) },
58-
onOpenPicker = {
59-
pickerSeed = resolveInitialCustomAccentPickerSeed(selectedAccentSeed)
60-
pickerSession = nextCustomAccentPickerSession(pickerSession)
61-
showPicker = true
62-
},
63-
onReset = { selectedAccentSeed = UiPreferences.CUSTOM_THEME_ACCENT_SEED_UNSET },
64-
accessibilityAnnouncement = announcement,
65-
contrastWarningOverride = if (normalizeAccentSeed(selectedAccentSeed) ==
66-
0xFFE53935.toInt()
67-
) {
68-
CustomAccentContrastWarning(setOf(CustomAccentContrastMode.LIGHT))
69-
} else {
70-
CustomAccentContrastWarning(emptySet())
71-
},
72-
onSwatchAnnouncement = { announcement = it },
73-
)
74-
}
52+
if (appTheme == AppTheme.CUSTOM) {
53+
CustomThemeAccentPreferenceWidget(
54+
selectedAccentSeed = selectedAccentSeed,
55+
onSwatchClick = { selectedAccentSeed = normalizeAccentSeed(it) },
56+
onOpenPicker = {
57+
pickerSeed = resolveInitialCustomAccentPickerSeed(selectedAccentSeed)
58+
pickerSession = nextCustomAccentPickerSession(pickerSession)
59+
showPicker = true
60+
},
61+
onReset = { selectedAccentSeed = UiPreferences.CUSTOM_THEME_ACCENT_SEED_UNSET },
62+
accessibilityAnnouncement = announcement,
63+
onSwatchAnnouncement = { announcement = it },
64+
)
65+
}
7566

76-
if (showPicker) {
77-
CustomThemeColorPickerDialog(
78-
sessionKey = pickerSession,
79-
initialSeed = pickerSeed,
80-
onDismiss = { showPicker = false },
81-
onApply = { selectedAccentSeed = normalizeAccentSeed(it) },
82-
onAppliedAnnouncement = { announcement = it },
83-
)
84-
}
67+
if (showPicker) {
68+
CustomThemeColorPickerDialog(
69+
sessionKey = pickerSession,
70+
initialSeed = pickerSeed,
71+
onDismiss = { showPicker = false },
72+
onApply = { selectedAccentSeed = normalizeAccentSeed(it) },
73+
onAppliedAnnouncement = { announcement = it },
74+
)
8575
}
8676
}
8777
}
8878

89-
composeRule.onNodeWithText("Custom accent").assertDoesNotExist()
79+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SWATCH_ROW, useUnmergedTree = true).assertDoesNotExist()
80+
composeRule.onNodeWithTag("theme_set_custom").performClick()
9081

91-
composeRule.onNodeWithText("Custom").performClick()
92-
composeRule.onNodeWithText("Custom accent").assertExists()
93-
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SWATCH_ROW).assertExists()
82+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SWATCH_ROW, useUnmergedTree = true).assertExists()
9483
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).assertExists()
9584
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_RESET).assertExists()
9685

97-
composeRule.onNodeWithContentDescription("Accent swatch #E53935").performClick()
98-
composeRule.onNodeWithText("Selected accent: #E53935").assertExists()
99-
composeRule.onNodeWithText("Warning: low contrast in Light").assertExists()
100-
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_ANNOUNCEMENT).assertExists()
101-
102-
composeRule.onNodeWithText("Custom color…").performClick()
86+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).performClick()
10387
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertExists()
10488
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SLIDER_HUE).assertExists()
10589
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_SLIDER_SATURATION).assertExists()
@@ -109,23 +93,14 @@ class ThemeAppearanceFlowAndroidTest {
10993
composeRule.onNodeWithContentDescription("Hue").performSemanticsAction(SemanticsActions.SetProgress) {
11094
it(240f)
11195
}
112-
composeRule.onNodeWithText("Cancel").performClick()
113-
composeRule.onNodeWithText("Selected accent: #E53935").assertExists()
96+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_CANCEL).performClick()
97+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertDoesNotExist()
11498

115-
composeRule.onNodeWithText("Custom color…").performClick()
99+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_BUTTON_PICK).performClick()
116100
composeRule.onNodeWithContentDescription("Saturation").performSemanticsAction(SemanticsActions.SetProgress) {
117101
it(0f)
118102
}
119-
composeRule.onNodeWithText("Apply").performClick()
120-
composeRule.onNodeWithText("Selected accent: #FFFFFF").assertExists()
121-
composeRule.onNodeWithText("Warning: low contrast in Light").assertDoesNotExist()
122-
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_ANNOUNCEMENT).assertExists()
123-
124-
composeRule.onNodeWithText("Reset accent").performClick()
125-
composeRule.onNodeWithText("Using default accent fallback").assertExists()
126-
127-
composeRule.onNodeWithText("Custom color…").performClick()
128-
composeRule.onNodeWithText("Cancel").performClick()
129-
composeRule.onNodeWithText("Using default accent fallback").assertExists()
103+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_APPLY).performClick()
104+
composeRule.onNodeWithTag(TAG_CUSTOM_ACCENT_PICKER_PREVIEW).assertDoesNotExist()
130105
}
131106
}

app/src/main/java/eu/kanade/presentation/more/settings/widget/CustomThemeAccentPreferenceWidget.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ internal const val TAG_CUSTOM_ACCENT_SLIDER_VALUE = "custom_accent_slider_value"
5858
internal const val TAG_CUSTOM_ACCENT_PICKER_APPLY = "custom_accent_picker_apply"
5959
internal const val TAG_CUSTOM_ACCENT_PICKER_CANCEL = "custom_accent_picker_cancel"
6060
internal const val TAG_CUSTOM_ACCENT_ANNOUNCEMENT = "custom_accent_announcement"
61+
internal const val TAG_CUSTOM_ACCENT_WARNING = "custom_accent_warning"
6162

6263
internal val customAccentSwatches = listOf(
6364
0xFFE53935.toInt(), // Red
@@ -138,7 +139,9 @@ internal fun CustomThemeAccentPreferenceWidget(
138139
if (contrastWarningSummary != null) {
139140
Text(
140141
text = contrastWarningSummary,
141-
modifier = Modifier.padding(horizontal = PrefsHorizontalPadding),
142+
modifier = Modifier
143+
.testTag(TAG_CUSTOM_ACCENT_WARNING)
144+
.padding(horizontal = PrefsHorizontalPadding),
142145
style = MaterialTheme.typography.bodyMedium,
143146
color = MaterialTheme.colorScheme.error,
144147
)
@@ -288,6 +291,7 @@ internal fun CustomThemeColorPickerDialog(
288291
if (contrastWarningSummary != null) {
289292
Text(
290293
text = contrastWarningSummary,
294+
modifier = Modifier.testTag(TAG_CUSTOM_ACCENT_WARNING),
291295
style = MaterialTheme.typography.bodyMedium,
292296
color = MaterialTheme.colorScheme.error,
293297
)

0 commit comments

Comments
 (0)