Skip to content

Commit

Permalink
test: resolve all android emulator tests error
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex720p committed Dec 14, 2024
1 parent 4d25029 commit f7532d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ConfirmImageDialogTest {

composeTestRule.setContent {
ConfirmImageDialogWrapper(
mock(), testImageFile, testImageFile.toUri(), showDialogState, imageViewModel, park, user)
mock(), testImageFile, testImageFile.toUri(), showDialogState, imageViewModel, park, user)
}

composeTestRule.waitForIdle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.core.net.toUri
import com.android.streetworkapp.model.image.ParkImageLocal
import com.android.streetworkapp.model.image.ImageRating
import com.android.streetworkapp.model.image.ParkImage
import com.android.streetworkapp.model.park.Park
import com.android.streetworkapp.model.user.UserViewModel
import com.google.firebase.Timestamp
import java.io.File
import java.io.FileOutputStream
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.mockito.Mockito.RETURNS_DEFAULTS
import org.mockito.Mockito.mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.verify

class ImagesCollectionPopUpTest {
private lateinit var testImageFile: File
private lateinit var localParkImages: List<ParkImageLocal>
private lateinit var parkImages: List<ParkImage>

@get:Rule val temporaryFolder = TemporaryFolder()

Expand All @@ -35,22 +38,19 @@ class ImagesCollectionPopUpTest {
outputStream.write(dummyData)
}

localParkImages =
parkImages =
listOf(
ParkImageLocal(
"dummyHash",
testImageFile.toUri(),
"userId",
"username",
Pair(0, 0),
Timestamp.now()))
ParkImage(
"https://dummyfileurl.com", "userId", "username", ImageRating(), Timestamp.now()))
}

// Note: as the image is an AsyncImage, I won't test it
@Test
fun `components are displayed correctly`() {

composeTestRule.setContent { FullScreenImagePopup(localParkImages, mock(), mock(), mock()) {} }
composeTestRule.setContent {
FullScreenImagePopup(parkImages, Park(), UserViewModel(mock(RETURNS_DEFAULTS)), mock()) {}
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag("fullscreenImagePopUp").assertIsDisplayed()
Expand All @@ -63,7 +63,9 @@ class ImagesCollectionPopUpTest {
val onDismiss = mock(Runnable::class.java)

composeTestRule.setContent {
FullScreenImagePopup(localParkImages, mock(), mock(), mock()) { onDismiss.run() }
FullScreenImagePopup(parkImages, Park(), UserViewModel(mock(RETURNS_DEFAULTS)), mock()) {
onDismiss.run()
}
}

composeTestRule.waitForIdle()
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/java/com/android/streetworkapp/ui/park/ParkOverview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -464,20 +464,21 @@ fun EventItem(event: Event, eventViewModel: EventViewModel, navigationActions: N

@Composable
fun CreateEventButton(navigationActions: NavigationActions) {
IconButton(onClick = { navigationActions.navigateTo(Screen.ADD_EVENT) }) {
Box(
modifier =
Modifier.size(38.dp)
.background(color = ColorPalette.INTERACTION_COLOR_DARK, shape = CircleShape)
.padding(1.dp)
.testTag("createEventButton")) {
Icon(
painter = painterResource(id = R.drawable.calendar_add_on_24px),
contentDescription = "Add Event",
tint = Color.White,
modifier = Modifier.align(Alignment.Center).fillMaxSize(0.75f))
}
}
IconButton(
onClick = { navigationActions.navigateTo(Screen.ADD_EVENT) },
modifier = Modifier.testTag("createEventButton")) {
Box(
modifier =
Modifier.size(38.dp)
.background(color = ColorPalette.INTERACTION_COLOR_DARK, shape = CircleShape)
.padding(1.dp)) {
Icon(
painter = painterResource(id = R.drawable.calendar_add_on_24px),
contentDescription = "Add Event",
tint = Color.White,
modifier = Modifier.align(Alignment.Center).fillMaxSize(0.75f))
}
}
}

/**
Expand Down

0 comments on commit f7532d5

Please sign in to comment.