Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.example.lambda_bbb_events.model.repository.CampsiteRepository
import com.example.lambda_bbb_events.model.repository.UserRepository
import com.example.lambda_bbb_events.model.user.Entrant
import com.example.lambda_bbb_events.model.user.UserRole
import com.example.lambda_bbb_events.store.CampsiteStore
import com.example.lambda_bbb_events.model.campsite.CampsiteStore
import com.google.firebase.FirebaseApp
import com.google.firebase.firestore.FirebaseFirestore
import io.mockk.clearAllMocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.example.lambda_bbb_events.ui.campsites
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.click
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsSelected
Expand Down Expand Up @@ -54,8 +57,8 @@ class FilterPageUITest {
showResultsCalled = false
// Remembers the filters like the real controller
every { campsiteController.filters } answers { filters }
every { campsiteController.applyFilters(any(), any(), any(), any(), any()) } answers {
filters = CampsiteFilters(arg(0), arg(1), arg(2), arg(3), arg(4))
every { campsiteController.applyFilters(any(), any(), any(), any(), any(), any()) } answers {
filters = CampsiteFilters(arg(0), arg(1), arg(2), arg(3), arg(4), arg(5))
emptyMap()
}
every { campsiteController.guestOptions } answers { guestOptions }
Expand Down Expand Up @@ -314,6 +317,7 @@ class FilterPageUITest {
fun ratingInputWorks() {
composeTestRule
.onNodeWithTag("ratingStar3")
.performScrollTo()
.performClick()

composeTestRule.onNodeWithTag("ratingStar1").assertIsSelected()
Expand All @@ -336,4 +340,84 @@ class FilterPageUITest {
assertTrue(showResultsCalled)
}
}

/** The text under the area map. */
private fun areaSummary(): String =
composeTestRule.onNodeWithTag("areaSummary")
.fetchSemanticsNode()
.config[SemanticsProperties.Text]
.joinToString("") { it.text }

/**
* Taps the middle of the area map until an area is placed, since the map takes a moment to
* load before it reports taps.
*/
private fun placeArea() {
composeTestRule.onNodeWithTag("areaMap").performScrollTo()
repeat(MAP_TAP_ATTEMPTS) {
composeTestRule.onNodeWithTag("areaMap").performTouchInput { click(center) }
composeTestRule.waitForIdle()
if (areaSummary().startsWith("Within")) return
Thread.sleep(MAP_TAP_WAIT_MS)
}
throw AssertionError("Tapping the map never placed an area")
}

@Test
fun areaStartsUnchosen() {
composeTestRule.onNodeWithTag("areaSummary").performScrollTo()

assertTrue(areaSummary().startsWith("Tap the map"))
}

@Test
fun tappingTheMapPlacesAnArea() {
placeArea()

composeTestRule.onNodeWithTag("areaRadiusHandle").assertIsDisplayed()
}

@Test
fun draggingTheHandleResizesTheArea() {
placeArea()
val before = areaSummary()

composeTestRule.onNodeWithTag("areaRadiusHandle").performTouchInput {
swipe(start = center, end = center + Offset(HANDLE_DRAG_PX, 0f), durationMillis = 500)
}
composeTestRule.waitForIdle()

assertTrue("Expected the radius to change from \"$before\"", areaSummary() != before)
}

@Test
fun resettingTheAreaClearsIt() {
placeArea()

composeTestRule.onNodeWithTag("areaResetButton").performScrollTo().performClick()

assertTrue(areaSummary().startsWith("Tap the map"))
}

@Test
fun showResultsAppliesTheArea() {
placeArea()

composeTestRule.onNodeWithTag("showResultsButton").performScrollTo().performClick()

composeTestRule.runOnIdle {
assertTrue(filters.area != null)
}
}

private companion object {
/** How many times [placeArea] taps before giving up. */
const val MAP_TAP_ATTEMPTS = 15

/** How long [placeArea] waits between taps for the map to load. */
const val MAP_TAP_WAIT_MS = 1000L

/** How far the handle is dragged outwards in the resize test. */
const val HANDLE_DRAG_PX = 150f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ class LocationSearchUITest {
composeTestRule.onNodeWithText("Jasper").assertIsDisplayed()
}

/** Where the top of the address field is, in pixels from the top of the screen's content. */
private fun addressFieldTop(): Float =
composeTestRule.onNodeWithTag("create_address").fetchSemanticsNode().boundsInRoot.top

@Test
fun suggestionsCoverWhatIsBelowInsteadOfPushingItDown() {
val before = addressFieldTop()

type("Lake")
waitForSuggestions()

assertEquals(before, addressFieldTop(), 0.5f)
}

@Test
fun choosingAPlaceFillsInTheLocation() {
form.postalCode = "X0X 0X0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.example.lambda_bbb_events.ui.navigation

import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performImeAction
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.lambda_bbb_events.controller.AppControllers
import com.example.lambda_bbb_events.controller.CampsiteController
import com.example.lambda_bbb_events.model.campsite.Campsite
import com.example.lambda_bbb_events.model.campsite.CampsiteStore
import com.example.lambda_bbb_events.view.ui.user_screens.explore.ExploreDefaultScreen
import com.example.lambda_bbb_events.view.ui.user_screens.home.HomeScreen
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import io.mockk.unmockkAll
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* Tests searching from the home screen, which opens the explore screen with the results, using
* a real [CampsiteController] over three campsites.
*/
@RunWith(AndroidJUnit4::class)
class HomeSearchUITest {
@get:Rule
val composeTestRule = createComposeRule()

private lateinit var navController: NavHostController

private val campsites = listOf(
Campsite(campsiteId = "lake", campsiteName = "Lakeside Retreat", address = "Banff"),
Campsite(campsiteId = "forest", campsiteName = "Forest Hideout", address = "Jasper"),
Campsite(campsiteId = "meadow", campsiteName = "Meadow Field", address = "Canmore")
).associateBy { it.campsiteId }.toMutableMap()

@Before
fun setup() {
val store = mockk<CampsiteStore>(relaxed = true)
every { store.campsites } returns campsites
val campsiteController = CampsiteController(store, scope = CoroutineScope(Dispatchers.Unconfined))
val controllers = mockk<AppControllers>(relaxed = true)
every { controllers.campsites } returns campsiteController

composeTestRule.setContent {
navController = rememberNavController()
NavHost(navController, startDestination = "home") {
composable("home") { HomeScreen(navController, controllers) }
composable("explore_default") { ExploreDefaultScreen(navController, controllers) }
}
}
}

@After
fun cleanUp() {
unmockkAll()
clearAllMocks()
}

/** Types [text] into the home search bar, replacing what was there, and presses search. */
private fun searchFromHome(text: String) {
val input = composeTestRule.onNodeWithTag("searchInput")
input.performTextClearance()
if (text.isNotEmpty()) {
input.performTextInput(text)
}
input.performImeAction()
composeTestRule.waitForIdle()
}

/** How many times [name] is shown on the current screen. */
private fun shown(name: String): Int =
composeTestRule.onAllNodesWithText(name).fetchSemanticsNodes().size

@Test
fun searchingFromHomeShowsMatchingCampsites() {
searchFromHome("Lake")

assertEquals("explore_default", navController.currentDestination?.route)
assertEquals(1, shown("Lakeside Retreat"))
assertEquals(0, shown("Forest Hideout"))
}

@Test
fun searchingNothingFromHomeAfterASearchShowsEveryCampsite() {
searchFromHome("Lake")
composeTestRule.runOnIdle { navController.popBackStack() }
composeTestRule.waitForIdle()

searchFromHome("")

assertEquals("explore_default", navController.currentDestination?.route)
assertEquals(1, shown("Forest Hideout"))
assertEquals(1, shown("Meadow Field"))
}

@Test
fun clearingTheHomeSearchBarThenSearchingShowsEveryCampsite() {
val input = composeTestRule.onNodeWithTag("searchInput")
input.performTextInput("Lake")
input.performTextClearance()
input.performImeAction()
composeTestRule.waitForIdle()

assertEquals("explore_default", navController.currentDestination?.route)
assertEquals(1, shown("Forest Hideout"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import com.example.lambda_bbb_events.model.services.GooglePlaceSearch
import com.example.lambda_bbb_events.model.services.ImageProcessor
import com.example.lambda_bbb_events.model.services.IncomingMessageListener
import com.example.lambda_bbb_events.model.user.UserRole
import com.example.lambda_bbb_events.store.CampsiteStore
import com.example.lambda_bbb_events.model.campsite.CampsiteStore
import com.example.lambda_bbb_events.view.ui.theme.Lambda_BBBeventsTheme
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
Expand All @@ -55,7 +55,6 @@ import kotlinx.coroutines.launch
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.example.lambda_bbb_events.model.services.FirebaseNotificationService
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.delay

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import androidx.compose.runtime.mutableStateOf
import com.example.lambda_bbb_events.model.campsite.AvailabilitySchedule
import com.example.lambda_bbb_events.model.campsite.Campsite
import com.example.lambda_bbb_events.model.campsite.CampsiteFilters
import com.example.lambda_bbb_events.model.campsite.SearchArea
import com.example.lambda_bbb_events.model.image.ImageMetaData
import com.example.lambda_bbb_events.model.local.InMemoryRecentlyViewedStore
import com.example.lambda_bbb_events.model.local.RecentlyViewedStore
import com.example.lambda_bbb_events.store.CampsiteStore
import com.example.lambda_bbb_events.model.campsite.CampsiteStore
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand Down Expand Up @@ -336,15 +337,17 @@ class CampsiteController(
endDate: LocalDate? = null,
location: String = "",
starRating: Double? = null,
guestRange: IntRange? = null
guestRange: IntRange? = null,
area: SearchArea? = null
): Map<String, Campsite> {

filters = CampsiteFilters(
startDate = startDate,
endDate = endDate,
location = location.trim(),
starRating = starRating,
guestRange = guestRange
guestRange = guestRange,
area = area
)
return filteredCampsites
}
Expand Down Expand Up @@ -379,9 +382,15 @@ class CampsiteController(
return isAvailable(campsite) &&
meetsStarRating(campsite) &&
meetsGuestRange(campsite) &&
meetsLocation(campsite)
meetsLocation(campsite) &&
meetsArea(campsite)
}

/** Checks the campsite is inside the chosen area, or that no area is chosen. */
private fun meetsArea(
campsite: Campsite
): Boolean = filters.area?.contains(campsite) ?: true

private fun isAvailable(
campsite: Campsite
): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import java.util.Date
* @property location Text the campsite's address or name must contain. Empty for anywhere.
* @property starRating The lowest average rating, or `null` for any rating.
* @property guestRange The numbers of guests the campsite can allow, or `null` for any number.
* @property area The circle on the map the campsite must be inside, or `null` for anywhere.
*/
data class CampsiteFilters(
val startDate: LocalDate? = null,
val endDate: LocalDate? = null,
val location: String = "",
val starRating: Double? = null,
val guestRange: IntRange? = null
val guestRange: IntRange? = null,
val area: SearchArea? = null
)

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.example.lambda_bbb_events.store
package com.example.lambda_bbb_events.model.campsite

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateMapOf
import com.example.lambda_bbb_events.model.campsite.AvailabilitySchedule
import com.example.lambda_bbb_events.model.campsite.Campsite
import com.example.lambda_bbb_events.model.image.ImageMetaData
import com.example.lambda_bbb_events.model.repository.CampsiteRepository
import com.example.lambda_bbb_events.model.repository.LotteryRepository
Expand All @@ -13,16 +11,14 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlin.coroutines.cancellation.CancellationException

/*
* Maintains the observable campsite cache and coordinates persistence with the repositories.
*/

/**
* Maintains the observable campsite cache and coordinates persistence with the repositories.
*
* @property campsiteRepo Repository for campsite data.
* @property scope Coroutine scope used for background operations.
* @property lotteryRepository Repository for lottery data.
*
* Reference: Merge conflict with main resolved with help from Claude (Anthropic), 2026-11-29.
*/
class CampsiteStore(
val campsiteRepo: CampsiteRepository = CampsiteRepository(),
Expand Down Expand Up @@ -207,14 +203,4 @@ class CampsiteStore(
val campsite = campsites.remove(campsiteId) ?: return
campsites[campsiteId] = campsite.copy(imageIds = photos)
}

/**
* Looks up a campsite using [ownerId] as the cache key and throws if the key is absent
*
* @param ownerId The ID used to look up the campsite.
* @return The campsite associated with the ID.
*/
fun getByOwner(ownerId: String): Campsite {
return campsites[ownerId] ?: throw IllegalArgumentException("Campsite not found")
}
}
Loading
Loading