Skip to content

Commit c1c7832

Browse files
Merge pull request Eureka-ch#312 from Eureka-ch/feature/add-field-configuration-ui
Feature: Field Configuration UI Components
2 parents 817d13b + a7388dc commit c1c7832

35 files changed

+3138
-191
lines changed

app/src/androidTest/java/ch/eureka/eurekapp/screens/subscreens/tasks/BaseFieldComponentTest.kt

Lines changed: 123 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class BaseFieldComponentTest {
5050
}
5151

5252
@Test
53-
fun baseFieldComponent_whenRequired_displaysAsterisk() {
53+
fun baseFieldComponent_whenRequiredDisplaysAsterisk() {
5454
val requiredField = testFieldDefinition.copy(required = true)
5555

5656
composeTestRule.setContent {
@@ -87,7 +87,7 @@ class BaseFieldComponentTest {
8787
}
8888

8989
@Test
90-
fun baseFieldComponent_whenDescriptionNull_doesNotDisplayDescription() {
90+
fun baseFieldComponent_whenDescriptionNullDoesNotDisplayDescription() {
9191
val fieldWithoutDescription = testFieldDefinition.copy(description = null)
9292

9393
composeTestRule.setContent {
@@ -101,11 +101,13 @@ class BaseFieldComponentTest {
101101
}
102102
}
103103

104-
composeTestRule.onNodeWithTag("field_description_test_field").assertDoesNotExist()
104+
composeTestRule
105+
.onNodeWithTag(FieldComponentTestTags.description("test_field"))
106+
.assertDoesNotExist()
105107
}
106108

107109
@Test
108-
fun baseFieldComponent_whenEditOnly_doesNotShowToggleButton() {
110+
fun baseFieldComponent_whenEditOnlyDoesNotShowToggleButton() {
109111
composeTestRule.setContent {
110112
BaseFieldComponent(
111113
fieldDefinition = testFieldDefinition,
@@ -121,7 +123,7 @@ class BaseFieldComponentTest {
121123
}
122124

123125
@Test
124-
fun baseFieldComponent_whenViewOnly_doesNotShowToggleButton() {
126+
fun baseFieldComponent_whenViewOnlyDoesNotShowToggleButton() {
125127
composeTestRule.setContent {
126128
BaseFieldComponent(
127129
fieldDefinition = testFieldDefinition,
@@ -137,7 +139,7 @@ class BaseFieldComponentTest {
137139
}
138140

139141
@Test
140-
fun baseFieldComponent_whenToggleable_showsToggleButton() {
142+
fun baseFieldComponent_whenToggleableShowsToggleButton() {
141143
composeTestRule.setContent {
142144
BaseFieldComponent(
143145
fieldDefinition = testFieldDefinition,
@@ -153,7 +155,7 @@ class BaseFieldComponentTest {
153155
}
154156

155157
@Test
156-
fun baseFieldComponent_whenToggleableAndToggleClicked_callsOnModeToggle() {
158+
fun baseFieldComponent_whenToggleableAndToggleClickedCallsOnModeToggle() {
157159
var toggleCalled = false
158160

159161
composeTestRule.setContent {
@@ -174,7 +176,7 @@ class BaseFieldComponentTest {
174176
}
175177

176178
@Test
177-
fun baseFieldComponent_rendererReceivesCorrectEditingState_whenEditOnly() {
179+
fun baseFieldComponent_rendererReceivesCorrectEditingStateWhenEditOnly() {
178180
var receivedIsEditing = false
179181

180182
composeTestRule.setContent {
@@ -193,7 +195,7 @@ class BaseFieldComponentTest {
193195
}
194196

195197
@Test
196-
fun baseFieldComponent_rendererReceivesCorrectEditingState_whenViewOnly() {
198+
fun baseFieldComponent_rendererReceivesCorrectEditingStateWhenViewOnly() {
197199
var receivedIsEditing = true
198200

199201
composeTestRule.setContent {
@@ -212,7 +214,7 @@ class BaseFieldComponentTest {
212214
}
213215

214216
@Test
215-
fun baseFieldComponent_rendererReceivesCorrectEditingState_whenToggleableEditing() {
217+
fun baseFieldComponent_rendererReceivesCorrectEditingStateWhenToggleableEditing() {
216218
var receivedIsEditing = false
217219

218220
composeTestRule.setContent {
@@ -231,7 +233,7 @@ class BaseFieldComponentTest {
231233
}
232234

233235
@Test
234-
fun baseFieldComponent_rendererReceivesCorrectEditingState_whenToggleableViewing() {
236+
fun baseFieldComponent_rendererReceivesCorrectEditingStateWhenToggleableViewing() {
235237
var receivedIsEditing = true
236238

237239
composeTestRule.setContent {
@@ -250,7 +252,7 @@ class BaseFieldComponentTest {
250252
}
251253

252254
@Test
253-
fun baseFieldComponent_whenRequiredAndNullValue_showsValidationError() {
255+
fun baseFieldComponent_whenRequiredAndNullValueShowsValidationError() {
254256
val requiredField = testFieldDefinition.copy(required = true)
255257

256258
composeTestRule.setContent {
@@ -270,7 +272,7 @@ class BaseFieldComponentTest {
270272
}
271273

272274
@Test
273-
fun baseFieldComponent_whenInvalidValue_showsValidationError() {
275+
fun baseFieldComponent_whenInvalidValueShowsValidationError() {
274276
val textFieldWithMaxLength = FieldType.Text(maxLength = 5)
275277
val invalidValue = FieldValue.TextValue("Too long text")
276278

@@ -291,7 +293,7 @@ class BaseFieldComponentTest {
291293
}
292294

293295
@Test
294-
fun baseFieldComponent_whenValidationErrorsHidden_doesNotShowErrors() {
296+
fun baseFieldComponent_whenValidationErrorsHiddenDoesNotShowErrors() {
295297
val requiredField = testFieldDefinition.copy(required = true)
296298

297299
composeTestRule.setContent {
@@ -389,7 +391,7 @@ class BaseFieldComponentTest {
389391
}
390392

391393
@Test
392-
fun baseFieldComponent_toggleableEditing_showsSaveAndCancelButtons() {
394+
fun baseFieldComponent_toggleableEditingShowsSaveAndCancelButtons() {
393395
composeTestRule.setContent {
394396
BaseFieldComponent(
395397
fieldDefinition = testFieldDefinition,
@@ -407,7 +409,7 @@ class BaseFieldComponentTest {
407409
}
408410

409411
@Test
410-
fun baseFieldComponent_toggleableViewing_showsEditButton() {
412+
fun baseFieldComponent_toggleableViewingShowsEditButton() {
411413
composeTestRule.setContent {
412414
BaseFieldComponent(
413415
fieldDefinition = testFieldDefinition,
@@ -425,7 +427,7 @@ class BaseFieldComponentTest {
425427
}
426428

427429
@Test
428-
fun baseFieldComponent_saveButton_commitsValueAndCallsCallbacks() {
430+
fun baseFieldComponent_saveButtonCommitsValueAndCallsCallbacks() {
429431
var committedValue: FieldValue.TextValue? = null
430432
var saveCalled = false
431433
var toggleCalled = false
@@ -459,7 +461,7 @@ class BaseFieldComponentTest {
459461
}
460462

461463
@Test
462-
fun baseFieldComponent_cancelButton_discardsChangesAndCallsCallbacks() {
464+
fun baseFieldComponent_cancelButtonDiscardsChangesAndCallsCallbacks() {
463465
var committedValue: FieldValue.TextValue? = FieldValue.TextValue("Original")
464466
var cancelCalled = false
465467
var toggleCalled = false
@@ -494,7 +496,7 @@ class BaseFieldComponentTest {
494496
}
495497

496498
@Test
497-
fun baseFieldComponent_editOnlyMode_callsOnValueChangeImmediately() {
499+
fun baseFieldComponent_editOnlyModeCallsOnValueChangeImmediately() {
498500
var receivedValue: FieldValue.TextValue? = null
499501
val newValue = FieldValue.TextValue("Immediate")
500502

@@ -516,7 +518,7 @@ class BaseFieldComponentTest {
516518
}
517519

518520
@Test
519-
fun baseFieldComponent_toggleableMode_buffersChangesUntilSave() {
521+
fun baseFieldComponent_toggleableModeBuffersChangesUntilSave() {
520522
var committedValue: FieldValue.TextValue? = null
521523
val editedValue = FieldValue.TextValue("Buffered")
522524

@@ -545,4 +547,105 @@ class BaseFieldComponentTest {
545547
// NOW value should be committed
546548
assertEquals(editedValue, committedValue)
547549
}
550+
551+
@Test
552+
fun baseFieldComponent_whenShowHeaderTrueDisplaysHeader() {
553+
composeTestRule.setContent {
554+
BaseFieldComponent(
555+
fieldDefinition = testFieldDefinition,
556+
fieldType = FieldType.Text(),
557+
value = null,
558+
onValueChange = {},
559+
mode = FieldInteractionMode.EditOnly,
560+
showHeader = true) { _, _, _ ->
561+
Text("Test Content")
562+
}
563+
}
564+
565+
// Label should be displayed
566+
composeTestRule.onNodeWithTag(FieldComponentTestTags.label("test_field")).assertIsDisplayed()
567+
// Description should be displayed
568+
composeTestRule
569+
.onNodeWithTag(FieldComponentTestTags.description("test_field"))
570+
.assertIsDisplayed()
571+
}
572+
573+
@Test
574+
fun baseFieldComponent_whenShowHeaderFalseHidesHeader() {
575+
composeTestRule.setContent {
576+
BaseFieldComponent(
577+
fieldDefinition = testFieldDefinition,
578+
fieldType = FieldType.Text(),
579+
value = null,
580+
onValueChange = {},
581+
mode = FieldInteractionMode.EditOnly,
582+
showHeader = false) { _, _, _ ->
583+
Text("Test Content")
584+
}
585+
}
586+
587+
// Label should NOT be displayed
588+
composeTestRule.onNodeWithTag(FieldComponentTestTags.label("test_field")).assertDoesNotExist()
589+
// Description should NOT be displayed
590+
composeTestRule
591+
.onNodeWithTag(FieldComponentTestTags.description("test_field"))
592+
.assertDoesNotExist()
593+
}
594+
595+
@Test
596+
fun baseFieldComponent_whenShowHeaderFalseStillRendersContent() {
597+
composeTestRule.setContent {
598+
BaseFieldComponent(
599+
fieldDefinition = testFieldDefinition,
600+
fieldType = FieldType.Text(),
601+
value = null,
602+
onValueChange = {},
603+
mode = FieldInteractionMode.EditOnly,
604+
showHeader = false) { _, _, _ ->
605+
Text("Test Content")
606+
}
607+
}
608+
609+
// Content should still be displayed
610+
composeTestRule.onNodeWithText("Test Content").assertIsDisplayed()
611+
}
612+
613+
@Test
614+
fun baseFieldComponent_whenShowHeaderFalseHidesActionButtons() {
615+
composeTestRule.setContent {
616+
BaseFieldComponent(
617+
fieldDefinition = testFieldDefinition,
618+
fieldType = FieldType.Text(),
619+
value = null,
620+
onValueChange = {},
621+
mode = FieldInteractionMode.Toggleable(isCurrentlyEditing = false),
622+
showHeader = false) { _, _, _ ->
623+
Text("Test Content")
624+
}
625+
}
626+
627+
// Toggle button should NOT be displayed
628+
composeTestRule.onNodeWithTag(FieldComponentTestTags.toggle("test_field")).assertDoesNotExist()
629+
}
630+
631+
@Test
632+
fun baseFieldComponent_whenShowHeaderFalseRendererStillReceivesCorrectEditingState() {
633+
var receivedIsEditing = false
634+
635+
composeTestRule.setContent {
636+
BaseFieldComponent(
637+
fieldDefinition = testFieldDefinition,
638+
fieldType = FieldType.Text(),
639+
value = null,
640+
onValueChange = {},
641+
mode = FieldInteractionMode.EditOnly,
642+
showHeader = false) { _, _, isEditing ->
643+
receivedIsEditing = isEditing
644+
Text("Test Content")
645+
}
646+
}
647+
648+
// Renderer should still receive correct editing state
649+
assertTrue(receivedIsEditing)
650+
}
548651
}

0 commit comments

Comments
 (0)