Skip to content

Commit

Permalink
ktfmtFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex720p committed Dec 15, 2024
1 parent 3392c4a commit 34ecd7e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,55 @@
package com.android.streetworkapp.ui.image

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.android.streetworkapp.model.image.ImageRepository
import com.android.streetworkapp.model.image.ImageViewModel
import com.android.streetworkapp.model.park.Park
import com.android.streetworkapp.model.user.User
import com.android.streetworkapp.model.user.UserRepository
import com.android.streetworkapp.model.user.UserViewModel
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.MockitoAnnotations

class FullScreenImagePopupTest {
}

@Mock private lateinit var userRepository: UserRepository
@Mock private lateinit var imageRepository: ImageRepository

@InjectMocks private lateinit var userViewModel: UserViewModel
@InjectMocks private lateinit var imageViewModel: ImageViewModel

private var currentUser =
User(
uid = "12345",
username = "john_doe",
email = "john.doe@example.com",
score = 1200,
friends = listOf("67890", "23456", "34567"),
picture = "https://example.com/profile_pic.jpg",
parks = listOf("park1", "park2", "park3"))

private var park = Park(pid = "parkId123")

@get:Rule val composeTestRule = createComposeRule()

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
}

@Test
fun `NoImagesDisplay is displayed on empty image list`() {
composeTestRule.setContent {
FullScreenImagePopup(emptyList(), park, userViewModel, imageViewModel) {}
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag("noImagesDisplay").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ data class ImageRating(
* all the positive ratings and the second the negative ones.
* @property uploadDate The date the image was uploaded
*/
// * Note: for the rating I would have used an unsigned int but there isn't a built in serializer
// for it and I can't be bothered
data class ParkImage(
val imageUrl: String = "",
val userId: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class ImageRepositoryFirestore(
val docRef =
db.collection(ImageRepositoryFirestore.COLLECTION_PATH).document(imageCollectionId)
val document = docRef.get().await()
val images = document.get("images") as? List<Map<String, Any>> ?: return false
val imageToRemove = images.firstOrNull { it["imageUrl"] == imageUrl } ?: return false

val imageCollection = document.toObject(ParkImageCollection::class.java) ?: return false
val imageToRemove =
imageCollection.images.firstOrNull { it.imageUrl == imageUrl } ?: return false
docRef.update("images", FieldValue.arrayRemove(imageToRemove)).await()

val fileKey = this.storageClient.extractKeyFromUrl(imageUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fun ImageItem(imageUri: String) {
@Composable
fun NoImagesDisplay() {
Column(
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize().testTag("noImagesDisplay"),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
Expand Down

0 comments on commit 34ecd7e

Please sign in to comment.