Skip to content

Commit

Permalink
Merge pull request #223 from SwEnt-Group13/feature/edit-delete-event
Browse files Browse the repository at this point in the history
Feature/edit and delete event
  • Loading branch information
Redd87 authored Nov 29, 2024
2 parents cc55fbc + 54162d9 commit 7648c7a
Show file tree
Hide file tree
Showing 22 changed files with 1,285 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.android.unio.TearDown
import com.android.unio.model.association.AssociationRepositoryFirestore
import com.android.unio.model.event.EventRepository
import com.android.unio.model.event.EventViewModel
import com.android.unio.model.image.ImageRepositoryFirebaseStorage
Expand Down Expand Up @@ -31,6 +32,7 @@ class BottomNavigationTest : TearDown() {
private lateinit var eventViewModel: EventViewModel

@MockK private lateinit var imageRepository: ImageRepositoryFirebaseStorage
@MockK private lateinit var associationRepositoryFirestore: AssociationRepositoryFirestore

private lateinit var userRepository: UserRepository
private lateinit var userViewModel: UserViewModel
Expand All @@ -44,7 +46,8 @@ class BottomNavigationTest : TearDown() {
fun setUp() {
MockKAnnotations.init(this)
eventRepository = mock { EventRepository::class.java }
eventViewModel = EventViewModel(eventRepository, imageRepository)
eventViewModel =
EventViewModel(eventRepository, imageRepository, associationRepositoryFirestore)

userRepository = mock { UserRepositoryFirestore::class.java }
userViewModel = UserViewModel(userRepository, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.unio.TearDown
import com.android.unio.mocks.association.MockAssociation
import com.android.unio.mocks.event.MockEvent
import com.android.unio.mocks.user.MockUser
import com.android.unio.model.association.AssociationRepositoryFirestore
import com.android.unio.model.association.AssociationViewModel
import com.android.unio.model.authentication.AuthViewModel
import com.android.unio.model.event.Event
Expand Down Expand Up @@ -106,6 +107,7 @@ class ScreenDisplayingTest : TearDown() {
longitude = 6.559331096
}

@MockK private lateinit var associationRepositoryFirestore: AssociationRepositoryFirestore
@MockK private lateinit var imageRepositoryFirestore: ImageRepositoryFirebaseStorage

@MockK private lateinit var firebaseAuth: FirebaseAuth
Expand Down Expand Up @@ -138,7 +140,7 @@ class ScreenDisplayingTest : TearDown() {
associationViewModel =
spyk(
AssociationViewModel(
mock(),
associationRepositoryFirestore,
mockk<EventRepositoryFirestore>(),
imageRepositoryFirestore,
mockk<ConcurrentAssociationUserRepositoryFirestore>()))
Expand All @@ -148,7 +150,8 @@ class ScreenDisplayingTest : TearDown() {
val onSuccess = args[0] as (List<Event>) -> Unit
onSuccess(events)
}
eventViewModel = EventViewModel(eventRepository, imageRepositoryFirestore)
eventViewModel =
EventViewModel(eventRepository, imageRepositoryFirestore, associationRepositoryFirestore)
eventViewModel.loadEvents()
eventViewModel.selectEvent(events.first().uid)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AssociationProfileTest : TearDown() {
val onSuccess = args[0] as (List<Event>) -> Unit
onSuccess(events)
}
eventViewModel = EventViewModel(eventRepository, imageRepository)
eventViewModel = EventViewModel(eventRepository, imageRepository, associationRepository)

every { associationRepository.init(any()) } answers { firstArg<() -> Unit>().invoke() }
every { associationRepository.getAssociations(any(), any()) } answers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.android.unio.mocks.association.MockAssociation
import com.android.unio.mocks.event.MockEvent
import com.android.unio.mocks.map.MockLocation
import com.android.unio.mocks.user.MockUser
import com.android.unio.model.association.AssociationRepositoryFirestore
import com.android.unio.model.event.Event
import com.android.unio.model.event.EventRepositoryFirestore
import com.android.unio.model.event.EventType
Expand Down Expand Up @@ -69,6 +70,7 @@ class EventCardTest : TearDown() {
private lateinit var eventViewModel: EventViewModel
@MockK private lateinit var eventRepository: EventRepositoryFirestore
@MockK private lateinit var imageRepository: ImageRepositoryFirebaseStorage
@MockK private lateinit var associationRepository: AssociationRepositoryFirestore
private lateinit var context: Context

@Before
Expand All @@ -79,7 +81,7 @@ class EventCardTest : TearDown() {
context = InstrumentationRegistry.getInstrumentation().targetContext
val user = MockUser.createMockUser(followedAssociations = associations, savedEvents = listOf())
every { NotificationWorker.schedule(any(), any()) } just runs
eventViewModel = EventViewModel(eventRepository, imageRepository)
eventViewModel = EventViewModel(eventRepository, imageRepository, associationRepository)
userViewModel = UserViewModel(userRepository)
every { userRepository.updateUser(user, any(), any()) } answers
{
Expand All @@ -93,7 +95,9 @@ class EventCardTest : TearDown() {
}

private fun setEventScreen(event: Event) {
composeTestRule.setContent { EventCard(navigationAction, event, userViewModel, eventViewModel) }
composeTestRule.setContent {
EventCard(navigationAction, event, userViewModel, eventViewModel, true)
}
}

@Test
Expand Down Expand Up @@ -132,6 +136,10 @@ class EventCardTest : TearDown() {
composeTestRule
.onNodeWithTag(EventCardTestTags.EVENT_SAVE_BUTTON, useUnmergedTree = true)
.assertExists()

composeTestRule
.onNodeWithTag(EventCardTestTags.EDIT_BUTTON, useUnmergedTree = true)
.assertExists()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.android.unio.components.event

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import com.android.unio.TearDown
Expand Down Expand Up @@ -35,16 +38,13 @@ import com.google.firebase.auth.internal.zzac
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.MockKAnnotations
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkAll
import java.net.HttpURLConnection
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -102,7 +102,8 @@ class EventCreationTest : TearDown() {
val onSuccess = args[0] as (List<Event>) -> Unit
onSuccess(events)
}
eventViewModel = EventViewModel(eventRepository, imageRepositoryFirestore)
eventViewModel =
EventViewModel(eventRepository, imageRepositoryFirestore, associationRepositoryFirestore)

searchViewModel = spyk(SearchViewModel(searchRepository))
associationViewModel =
Expand Down Expand Up @@ -165,6 +166,38 @@ class EventCreationTest : TearDown() {
.onNodeWithTag(EventCreationTestTags.TAGGED_ASSOCIATIONS)
.assertDisplayComponentInScroll()

composeTestRule
.onNodeWithTag(EventCreationTestTags.START_DATE_FIELD)
.performScrollTo()
.assertIsDisplayed()
.performClick()
composeTestRule.onNodeWithTag(EventCreationTestTags.START_DATE_PICKER).assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()

composeTestRule
.onNodeWithTag(EventCreationTestTags.START_TIME_FIELD)
.performScrollTo()
.assertIsDisplayed()
.performClick()
composeTestRule.onNodeWithTag(EventCreationTestTags.START_TIME_PICKER).assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()

composeTestRule
.onNodeWithTag(EventCreationTestTags.END_DATE_FIELD)
.performScrollTo()
.assertIsDisplayed()
.performClick()
composeTestRule.onNodeWithTag(EventCreationTestTags.END_DATE_PICKER).assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()

composeTestRule
.onNodeWithTag(EventCreationTestTags.END_TIME_FIELD)
.performScrollTo()
.assertIsDisplayed()
.performClick()
composeTestRule.onNodeWithTag(EventCreationTestTags.END_TIME_PICKER).assertIsDisplayed()
composeTestRule.onNodeWithText("Cancel").performClick()

composeTestRule.onNodeWithTag(EventCreationTestTags.TAGGED_ASSOCIATIONS).performClick()
composeTestRule.waitForIdle()

Expand Down Expand Up @@ -264,10 +297,4 @@ class EventCreationTest : TearDown() {

server.shutdown()
}

@After
fun teardown() {
clearAllMocks()
unmockkAll()
}
}
Loading

0 comments on commit 7648c7a

Please sign in to comment.