Skip to content

Commit c9cdfe3

Browse files
committed
test: WeatherEditScreenTest.kt
1 parent 75a1a8d commit c9cdfe3

File tree

2 files changed

+350
-1
lines changed

2 files changed

+350
-1
lines changed
Lines changed: 349 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,349 @@
1+
package to.bitkit.ui.screens.widgets.weather
2+
3+
import androidx.compose.ui.test.assertIsEnabled
4+
import androidx.compose.ui.test.assertIsNotEnabled
5+
import androidx.compose.ui.test.junit4.createComposeRule
6+
import androidx.compose.ui.test.onNodeWithTag
7+
import androidx.compose.ui.test.performClick
8+
import org.junit.Rule
9+
import org.junit.Test
10+
import to.bitkit.R
11+
import to.bitkit.data.dto.FeeCondition
12+
import to.bitkit.models.widget.WeatherPreferences
13+
import to.bitkit.ui.screens.widgets.blocks.WeatherModel
14+
import to.bitkit.ui.theme.AppThemeSurface
15+
16+
class WeatherEditScreenTest {
17+
18+
@get:Rule
19+
val composeTestRule = createComposeRule()
20+
21+
private val testWeatherModel = WeatherModel(
22+
title = R.string.widgets__weather__condition__good__title,
23+
description = R.string.widgets__weather__condition__good__description,
24+
currentFee = "15 sat/vB",
25+
nextBlockFee = "12 sat/vB",
26+
icon = FeeCondition.GOOD.icon
27+
)
28+
29+
private val defaultPreferences = WeatherPreferences()
30+
31+
@Test
32+
fun testWeatherEditScreenWithDefaultPreferences() {
33+
// Arrange
34+
var closeClicked = false
35+
var backClicked = false
36+
var titleClicked = false
37+
var descriptionClicked = false
38+
var currentFeeClicked = false
39+
var nextBlockFeeClicked = false
40+
var resetClicked = false
41+
var previewClicked = false
42+
43+
// Act
44+
composeTestRule.setContent {
45+
AppThemeSurface {
46+
WeatherEditContent(
47+
onClose = { closeClicked = true },
48+
onBack = { backClicked = true },
49+
onClickShowTitle = { titleClicked = true },
50+
onClickShowDescription = { descriptionClicked = true },
51+
onClickShowCurrentFee = { currentFeeClicked = true },
52+
onClickShowNextBlockFee = { nextBlockFeeClicked = true },
53+
onClickReset = { resetClicked = true },
54+
onClickPreview = { previewClicked = true },
55+
weatherPreferences = defaultPreferences,
56+
weather = testWeatherModel
57+
)
58+
}
59+
}
60+
61+
// Assert main elements exist
62+
composeTestRule.onNodeWithTag("weather_edit_screen").assertExists()
63+
composeTestRule.onNodeWithTag("main_content").assertExists()
64+
65+
// Verify description
66+
composeTestRule.onNodeWithTag("edit_description").assertExists()
67+
68+
// Verify all setting rows exist
69+
listOf("title", "description", "current_fee", "next_block_fee").forEach { prefix ->
70+
composeTestRule.onNodeWithTag("${prefix}_setting_row").assertExists()
71+
composeTestRule.onNodeWithTag("${prefix}_text").assertExists()
72+
composeTestRule.onNodeWithTag("${prefix}_toggle_button").assertExists()
73+
composeTestRule.onNodeWithTag("${prefix}_toggle_icon", useUnmergedTree = true).assertExists()
74+
composeTestRule.onNodeWithTag("${prefix}_divider").assertExists()
75+
}
76+
77+
// Verify buttons
78+
composeTestRule.onNodeWithTag("buttons_row").assertExists()
79+
composeTestRule.onNodeWithTag("reset_button").assertExists()
80+
composeTestRule.onNodeWithTag("preview_button").assertExists()
81+
82+
// Test button clicks
83+
composeTestRule.onNodeWithTag("title_toggle_button").performClick()
84+
assert(titleClicked)
85+
86+
composeTestRule.onNodeWithTag("preview_button").performClick()
87+
assert(previewClicked)
88+
89+
// Reset button should be disabled with default preferences
90+
composeTestRule.onNodeWithTag("reset_button").assertIsNotEnabled()
91+
}
92+
93+
@Test
94+
fun testWeatherEditScreenWithCustomPreferences() {
95+
// Arrange - Some options enabled
96+
val customPreferences = WeatherPreferences(
97+
showTitle = true,
98+
showDescription = true,
99+
showCurrentFee = false,
100+
showNextBlockFee = true
101+
)
102+
103+
var resetClicked = false
104+
105+
// Act
106+
composeTestRule.setContent {
107+
AppThemeSurface {
108+
WeatherEditContent(
109+
onClose = {},
110+
onBack = {},
111+
onClickShowTitle = {},
112+
onClickShowDescription = {},
113+
onClickShowCurrentFee = {},
114+
onClickShowNextBlockFee = {},
115+
onClickReset = { resetClicked = true },
116+
onClickPreview = {},
117+
weatherPreferences = customPreferences,
118+
weather = testWeatherModel
119+
)
120+
}
121+
}
122+
123+
// Assert reset button should be enabled when preferences are customized
124+
composeTestRule.onNodeWithTag("reset_button").assertIsEnabled()
125+
126+
// Test reset button click
127+
composeTestRule.onNodeWithTag("reset_button").performClick()
128+
assert(resetClicked)
129+
}
130+
131+
@Test
132+
fun testPreviewButtonEnabledState() {
133+
// Test when preview should be enabled (at least one option enabled)
134+
val preferencesSomeEnabled = WeatherPreferences(showTitle = true)
135+
136+
composeTestRule.setContent {
137+
AppThemeSurface {
138+
WeatherEditContent(
139+
onClose = {},
140+
onBack = {},
141+
onClickShowTitle = {},
142+
onClickShowDescription = {},
143+
onClickShowCurrentFee = {},
144+
onClickShowNextBlockFee = {},
145+
onClickReset = {},
146+
onClickPreview = {},
147+
weatherPreferences = preferencesSomeEnabled,
148+
weather = testWeatherModel
149+
)
150+
}
151+
}
152+
153+
composeTestRule.onNodeWithTag("preview_button").assertIsEnabled()
154+
}
155+
156+
@Test
157+
fun testPreviewButtonDisabledState() {
158+
// Test when preview should be disabled (all options disabled)
159+
val preferencesAllDisabled = WeatherPreferences(
160+
showTitle = false,
161+
showDescription = false,
162+
showCurrentFee = false,
163+
showNextBlockFee = false
164+
)
165+
166+
composeTestRule.setContent {
167+
AppThemeSurface {
168+
WeatherEditContent(
169+
onClose = {},
170+
onBack = {},
171+
onClickShowTitle = {},
172+
onClickShowDescription = {},
173+
onClickShowCurrentFee = {},
174+
onClickShowNextBlockFee = {},
175+
onClickReset = {},
176+
onClickPreview = {},
177+
weatherPreferences = preferencesAllDisabled,
178+
weather = testWeatherModel
179+
)
180+
}
181+
}
182+
183+
composeTestRule.onNodeWithTag("preview_button").assertIsNotEnabled()
184+
}
185+
186+
@Test
187+
fun testAllCallbacksTriggered() {
188+
// Arrange
189+
var titleClicked = false
190+
var descriptionClicked = false
191+
var currentFeeClicked = false
192+
var nextBlockFeeClicked = false
193+
var resetClicked = false
194+
var previewClicked = false
195+
196+
val customPreferences = WeatherPreferences(
197+
showTitle = false,
198+
showDescription = true,
199+
showCurrentFee = false,
200+
showNextBlockFee = true
201+
)
202+
203+
composeTestRule.setContent {
204+
AppThemeSurface {
205+
WeatherEditContent(
206+
onClose = {},
207+
onBack = {},
208+
onClickShowTitle = { titleClicked = true },
209+
onClickShowDescription = { descriptionClicked = true },
210+
onClickShowCurrentFee = { currentFeeClicked = true },
211+
onClickShowNextBlockFee = { nextBlockFeeClicked = true },
212+
onClickReset = { resetClicked = true },
213+
onClickPreview = { previewClicked = true },
214+
weatherPreferences = customPreferences,
215+
weather = testWeatherModel
216+
)
217+
}
218+
}
219+
220+
// Test all clickable elements
221+
composeTestRule.onNodeWithTag("title_toggle_button").performClick()
222+
assert(titleClicked)
223+
224+
composeTestRule.onNodeWithTag("description_toggle_button").performClick()
225+
assert(descriptionClicked)
226+
227+
composeTestRule.onNodeWithTag("current_fee_toggle_button").performClick()
228+
assert(currentFeeClicked)
229+
230+
composeTestRule.onNodeWithTag("next_block_fee_toggle_button").performClick()
231+
assert(nextBlockFeeClicked)
232+
233+
composeTestRule.onNodeWithTag("preview_button").performClick()
234+
assert(previewClicked)
235+
236+
composeTestRule.onNodeWithTag("reset_button").performClick()
237+
assert(resetClicked)
238+
}
239+
240+
@Test
241+
fun testEmptyValuesDisplay() {
242+
// Arrange - Weather with empty values
243+
val emptyWeather = WeatherModel(
244+
title = R.string.widgets__weather__condition__good__title,
245+
description = R.string.widgets__weather__condition__good__description,
246+
currentFee = "",
247+
nextBlockFee = "",
248+
icon = FeeCondition.GOOD.icon
249+
)
250+
251+
composeTestRule.setContent {
252+
AppThemeSurface {
253+
WeatherEditContent(
254+
onClose = {},
255+
onBack = {},
256+
onClickShowTitle = {},
257+
onClickShowDescription = {},
258+
onClickShowCurrentFee = {},
259+
onClickShowNextBlockFee = {},
260+
onClickReset = {},
261+
onClickPreview = {},
262+
weatherPreferences = defaultPreferences,
263+
weather = emptyWeather
264+
)
265+
}
266+
}
267+
268+
// Assert that fee text elements don't exist when values are empty
269+
listOf("current_fee", "next_block_fee").forEach { prefix ->
270+
composeTestRule.onNodeWithTag("${prefix}_text").assertDoesNotExist()
271+
}
272+
}
273+
274+
@Test
275+
fun testAllElementsExist() {
276+
// Arrange
277+
composeTestRule.setContent {
278+
AppThemeSurface {
279+
WeatherEditContent(
280+
onClose = {},
281+
onBack = {},
282+
onClickShowTitle = {},
283+
onClickShowDescription = {},
284+
onClickShowCurrentFee = {},
285+
onClickShowNextBlockFee = {},
286+
onClickReset = {},
287+
onClickPreview = {},
288+
weatherPreferences = WeatherPreferences(
289+
showTitle = false,
290+
showDescription = true,
291+
showCurrentFee = false,
292+
showNextBlockFee = true
293+
),
294+
weather = testWeatherModel
295+
)
296+
}
297+
}
298+
299+
// Assert all tagged elements exist
300+
composeTestRule.onNodeWithTag("weather_edit_screen").assertExists()
301+
composeTestRule.onNodeWithTag("main_content").assertExists()
302+
composeTestRule.onNodeWithTag("edit_description").assertExists()
303+
304+
listOf("title", "description", "current_fee", "next_block_fee").forEach { prefix ->
305+
composeTestRule.onNodeWithTag("${prefix}_setting_row").assertExists()
306+
composeTestRule.onNodeWithTag("${prefix}_toggle_button").assertExists()
307+
composeTestRule.onNodeWithTag("${prefix}_toggle_icon", useUnmergedTree = true).assertExists()
308+
composeTestRule.onNodeWithTag("${prefix}_divider").assertExists()
309+
}
310+
311+
composeTestRule.onNodeWithTag("buttons_row").assertExists()
312+
composeTestRule.onNodeWithTag("reset_button").assertExists()
313+
composeTestRule.onNodeWithTag("preview_button").assertExists()
314+
}
315+
316+
@Test
317+
fun testToggleIconsColorChange() {
318+
// Arrange
319+
val customPreferences = WeatherPreferences(
320+
showTitle = true,
321+
showDescription = false,
322+
showCurrentFee = true,
323+
showNextBlockFee = false
324+
)
325+
326+
composeTestRule.setContent {
327+
AppThemeSurface {
328+
WeatherEditContent(
329+
onClose = {},
330+
onBack = {},
331+
onClickShowTitle = {},
332+
onClickShowDescription = {},
333+
onClickShowCurrentFee = {},
334+
onClickShowNextBlockFee = {},
335+
onClickReset = {},
336+
onClickPreview = {},
337+
weatherPreferences = customPreferences,
338+
weather = testWeatherModel
339+
)
340+
}
341+
}
342+
343+
// Assert toggle icons have correct color based on preferences
344+
composeTestRule.onNodeWithTag("title_toggle_icon", useUnmergedTree = true).assertExists()
345+
composeTestRule.onNodeWithTag("description_toggle_icon", useUnmergedTree = true).assertExists()
346+
composeTestRule.onNodeWithTag("current_fee_toggle_icon", useUnmergedTree = true).assertExists()
347+
composeTestRule.onNodeWithTag("next_block_fee_toggle_icon", useUnmergedTree = true).assertExists()
348+
}
349+
}

app/src/main/java/to/bitkit/ui/screens/widgets/weather/WeatherEditScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fun WeatherEditContent(
129129
fontFamily = InterFontFamily,
130130
color = Colors.White,
131131
),
132-
modifier = Modifier.weight(1f),
132+
modifier = Modifier.weight(1f).testTag("title_text"),
133133
)
134134

135135
weather?.icon?.let {

0 commit comments

Comments
 (0)