Skip to content

Commit 52de0b9

Browse files
authored
Merge pull request #296 from LookUpGroup27/feat/improve-image-posting-process
feat: improve image posting process
2 parents daf1770 + a55e06b commit 52de0b9

File tree

2 files changed

+214
-83
lines changed

2 files changed

+214
-83
lines changed

app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/image/ImageReviewKtTest.kt

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package com.github.lookupgroup27.lookup.ui.image
22

3-
import androidx.compose.ui.test.assertIsDisplayed
3+
import androidx.compose.ui.test.*
44
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
105
import androidx.test.ext.junit.runners.AndroidJUnit4
116
import com.github.lookupgroup27.lookup.model.collection.CollectionRepository
127
import com.github.lookupgroup27.lookup.model.image.ImageRepository
@@ -21,7 +16,6 @@ import org.junit.Rule
2116
import org.junit.Test
2217
import org.junit.runner.RunWith
2318
import org.mockito.Mockito
24-
import org.mockito.Mockito.`when`
2519
import org.mockito.kotlin.mock
2620
import org.mockito.kotlin.verify
2721

@@ -40,7 +34,6 @@ class ImageReviewTest {
4034
@get:Rule val composeTestRule = createComposeRule()
4135

4236
private val fakeFile: File = File.createTempFile("temp", null)
43-
4437
private val mockNavigationActions: NavigationActions = mock()
4538

4639
@Before
@@ -53,13 +46,10 @@ class ImageReviewTest {
5346

5447
collectionRepository = Mockito.mock(CollectionRepository::class.java)
5548
collectionViewModel = CollectionViewModel(collectionRepository)
56-
57-
// Mock UID generator to return a fixed value
58-
`when`(postsViewModel.generateNewUid()).thenReturn("mocked_uid")
5949
}
6050

6151
@Test
62-
fun testImageReviewIsDisplayed() {
52+
fun testImageReviewScreenIsDisplayed() {
6353
composeTestRule.setContent {
6454
ImageReviewScreen(
6555
mockNavigationActions,
@@ -69,7 +59,6 @@ class ImageReviewTest {
6959
collectionViewModel,
7060
timestamp = 123456789L)
7161
}
72-
7362
composeTestRule.onNodeWithTag("image_review").assertIsDisplayed()
7463
}
7564

@@ -84,7 +73,6 @@ class ImageReviewTest {
8473
collectionViewModel,
8574
timestamp = 123456789L)
8675
}
87-
8876
composeTestRule.onNodeWithTag("confirm_button").performScrollTo().assertIsDisplayed()
8977
composeTestRule.onNodeWithTag("confirm_button").performClick()
9078
}
@@ -100,13 +88,59 @@ class ImageReviewTest {
10088
collectionViewModel,
10189
timestamp = 123456789L)
10290
}
103-
10491
composeTestRule.onNodeWithTag("cancel_button").performScrollTo().assertIsDisplayed()
10592
composeTestRule.onNodeWithTag("cancel_button").performClick()
10693

10794
verify(mockNavigationActions).navigateTo(Screen.TAKE_IMAGE)
10895
}
10996

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+
110144
@Test
111145
fun testImageDisplayedWhenImageFileIsNotNull() {
112146
val imageFile = File("path/to/image")
@@ -137,7 +171,7 @@ class ImageReviewTest {
137171
}
138172

139173
@Test
140-
fun testImageReviewScreenIsScrollable() {
174+
fun testDiscardButtonNavigatesBack() {
141175
composeTestRule.setContent {
142176
ImageReviewScreen(
143177
mockNavigationActions,
@@ -148,15 +182,10 @@ class ImageReviewTest {
148182
timestamp = 123456789L)
149183
}
150184

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)
157187
}
158188

159-
/** Verifies that the background image is displayed in the EditImageScreen. */
160189
@Test
161190
fun testBackgroundImageIsDisplayed() {
162191
composeTestRule.setContent {
@@ -171,19 +200,19 @@ class ImageReviewTest {
171200
composeTestRule.onNodeWithTag("background_image").assertIsDisplayed()
172201
}
173202

174-
/** Verifies that the loading indicator is displayed when the state is set to Loading. */
175203
@Test
176-
fun testLoadingIndicatorIsDisplayedWhenStateIsLoading() {
177-
imageViewModel.setEditImageState(ImageViewModel.UploadStatus(isLoading = true))
204+
fun testTitleIsDisplayed() {
178205
composeTestRule.setContent {
179206
ImageReviewScreen(
180-
mockNavigationActions,
181-
fakeFile,
207+
navigationActions = mockNavigationActions,
208+
imageFile = fakeFile,
182209
imageViewModel,
183210
postsViewModel,
184211
collectionViewModel,
185212
timestamp = 123456789L)
186213
}
187-
composeTestRule.onNodeWithTag("loading_indicator").assertIsDisplayed()
214+
215+
// Verify that the title "Post Your Picture" is displayed
216+
composeTestRule.onNodeWithTag("post_picture_title").assertIsDisplayed()
188217
}
189218
}

0 commit comments

Comments
 (0)