1
1
package com.github.lookupgroup27.lookup.ui.image
2
2
3
- import androidx.compose.ui.test.assertIsDisplayed
3
+ import androidx.compose.ui.test.*
4
4
import androidx.compose.ui.test.junit4.createComposeRule
5
- import androidx.compose.ui.test.onNodeWithContentDescription
6
- import androidx.compose.ui.test.onNodeWithTag
7
- import androidx.compose.ui.test.onNodeWithText
8
- import androidx.compose.ui.test.performClick
9
- import androidx.compose.ui.test.performScrollTo
10
5
import androidx.test.ext.junit.runners.AndroidJUnit4
11
6
import com.github.lookupgroup27.lookup.model.collection.CollectionRepository
12
7
import com.github.lookupgroup27.lookup.model.image.ImageRepository
@@ -21,7 +16,6 @@ import org.junit.Rule
21
16
import org.junit.Test
22
17
import org.junit.runner.RunWith
23
18
import org.mockito.Mockito
24
- import org.mockito.Mockito.`when`
25
19
import org.mockito.kotlin.mock
26
20
import org.mockito.kotlin.verify
27
21
@@ -40,7 +34,6 @@ class ImageReviewTest {
40
34
@get:Rule val composeTestRule = createComposeRule()
41
35
42
36
private val fakeFile: File = File .createTempFile(" temp" , null )
43
-
44
37
private val mockNavigationActions: NavigationActions = mock()
45
38
46
39
@Before
@@ -53,13 +46,10 @@ class ImageReviewTest {
53
46
54
47
collectionRepository = Mockito .mock(CollectionRepository ::class .java)
55
48
collectionViewModel = CollectionViewModel (collectionRepository)
56
-
57
- // Mock UID generator to return a fixed value
58
- `when `(postsViewModel.generateNewUid()).thenReturn(" mocked_uid" )
59
49
}
60
50
61
51
@Test
62
- fun testImageReviewIsDisplayed () {
52
+ fun testImageReviewScreenIsDisplayed () {
63
53
composeTestRule.setContent {
64
54
ImageReviewScreen (
65
55
mockNavigationActions,
@@ -69,7 +59,6 @@ class ImageReviewTest {
69
59
collectionViewModel,
70
60
timestamp = 123456789L )
71
61
}
72
-
73
62
composeTestRule.onNodeWithTag(" image_review" ).assertIsDisplayed()
74
63
}
75
64
@@ -84,7 +73,6 @@ class ImageReviewTest {
84
73
collectionViewModel,
85
74
timestamp = 123456789L )
86
75
}
87
-
88
76
composeTestRule.onNodeWithTag(" confirm_button" ).performScrollTo().assertIsDisplayed()
89
77
composeTestRule.onNodeWithTag(" confirm_button" ).performClick()
90
78
}
@@ -100,13 +88,59 @@ class ImageReviewTest {
100
88
collectionViewModel,
101
89
timestamp = 123456789L )
102
90
}
103
-
104
91
composeTestRule.onNodeWithTag(" cancel_button" ).performScrollTo().assertIsDisplayed()
105
92
composeTestRule.onNodeWithTag(" cancel_button" ).performClick()
106
93
107
94
verify(mockNavigationActions).navigateTo(Screen .TAKE_IMAGE )
108
95
}
109
96
97
+ @Test
98
+ fun testDescriptionFieldIsDisplayedAndEditable () {
99
+ composeTestRule.setContent {
100
+ ImageReviewScreen (
101
+ mockNavigationActions,
102
+ fakeFile,
103
+ imageViewModel,
104
+ postsViewModel,
105
+ collectionViewModel,
106
+ timestamp = 123456789L )
107
+ }
108
+ composeTestRule.onNodeWithTag(" description_title" ).assertIsDisplayed()
109
+ // Initially, the description field is displayed in read-only mode
110
+ composeTestRule.onNodeWithTag(" description_text" ).assertIsDisplayed().performClick()
111
+
112
+ // Enter edit mode and input text
113
+ composeTestRule
114
+ .onNodeWithTag(" edit_description_field" )
115
+ .assertIsDisplayed()
116
+ .performTextInput(" New Description" )
117
+
118
+ // Verify that the input text is displayed correctly
119
+ composeTestRule.onNodeWithTag(" edit_description_field" ).assert (hasText(" New Description" ))
120
+ }
121
+
122
+ @Test
123
+ fun testLoadingIndicatorReplacesPostButtonWhenUploading () {
124
+ // Simulate loading state
125
+ imageViewModel.setEditImageState(ImageViewModel .UploadStatus (isLoading = true ))
126
+
127
+ composeTestRule.setContent {
128
+ ImageReviewScreen (
129
+ mockNavigationActions,
130
+ fakeFile,
131
+ imageViewModel,
132
+ postsViewModel,
133
+ collectionViewModel,
134
+ timestamp = 123456789L )
135
+ }
136
+
137
+ // Verify that the loading indicator is displayed
138
+ composeTestRule.onNodeWithTag(" loading_indicator" ).assertIsDisplayed()
139
+
140
+ // Verify that the Post button is not displayed during loading
141
+ composeTestRule.onNodeWithTag(" confirm_button" ).assertDoesNotExist()
142
+ }
143
+
110
144
@Test
111
145
fun testImageDisplayedWhenImageFileIsNotNull () {
112
146
val imageFile = File (" path/to/image" )
@@ -137,7 +171,7 @@ class ImageReviewTest {
137
171
}
138
172
139
173
@Test
140
- fun testImageReviewScreenIsScrollable () {
174
+ fun testDiscardButtonNavigatesBack () {
141
175
composeTestRule.setContent {
142
176
ImageReviewScreen (
143
177
mockNavigationActions,
@@ -148,15 +182,10 @@ class ImageReviewTest {
148
182
timestamp = 123456789L )
149
183
}
150
184
151
- // Check that the top element is displayed (e.g., image or text)
152
- composeTestRule.onNodeWithTag(" image_review" ).assertIsDisplayed()
153
-
154
- // Attempt to scroll to a specific button at the bottom
155
- composeTestRule.onNodeWithTag(" cancel_button" ).performScrollTo().assertIsDisplayed()
156
- composeTestRule.onNodeWithTag(" confirm_button" ).performScrollTo().assertIsDisplayed()
185
+ composeTestRule.onNodeWithTag(" cancel_button" ).performClick()
186
+ verify(mockNavigationActions).navigateTo(Screen .TAKE_IMAGE )
157
187
}
158
188
159
- /* * Verifies that the background image is displayed in the EditImageScreen. */
160
189
@Test
161
190
fun testBackgroundImageIsDisplayed () {
162
191
composeTestRule.setContent {
@@ -171,19 +200,19 @@ class ImageReviewTest {
171
200
composeTestRule.onNodeWithTag(" background_image" ).assertIsDisplayed()
172
201
}
173
202
174
- /* * Verifies that the loading indicator is displayed when the state is set to Loading. */
175
203
@Test
176
- fun testLoadingIndicatorIsDisplayedWhenStateIsLoading () {
177
- imageViewModel.setEditImageState(ImageViewModel .UploadStatus (isLoading = true ))
204
+ fun testTitleIsDisplayed () {
178
205
composeTestRule.setContent {
179
206
ImageReviewScreen (
180
- mockNavigationActions,
181
- fakeFile,
207
+ navigationActions = mockNavigationActions,
208
+ imageFile = fakeFile,
182
209
imageViewModel,
183
210
postsViewModel,
184
211
collectionViewModel,
185
212
timestamp = 123456789L )
186
213
}
187
- composeTestRule.onNodeWithTag(" loading_indicator" ).assertIsDisplayed()
214
+
215
+ // Verify that the title "Post Your Picture" is displayed
216
+ composeTestRule.onNodeWithTag(" post_picture_title" ).assertIsDisplayed()
188
217
}
189
218
}
0 commit comments