diff --git a/.github/workflows/android-releases.yml b/.github/workflows/android-releases.yml index f6de92f9..4e87eee6 100644 --- a/.github/workflows/android-releases.yml +++ b/.github/workflows/android-releases.yml @@ -4,8 +4,6 @@ on: push: branches: [main] -# Releases run one at a time and are never cancelled part way, so a release -# is not left created without its docs deployed concurrency: group: pages-${{ github.ref }} cancel-in-progress: false @@ -44,13 +42,6 @@ jobs: - name: Tests run: ./code/gradlew -p code test - - name: Upload test reports - if: failure() - uses: actions/upload-artifact@v7 - with: - name: unit-test-reports - path: code/app/build/reports/tests/ - - name: Build Release APK run: ./code/gradlew -p code assembleRelease diff --git a/.github/workflows/pull-requests-tests.yml b/.github/workflows/pull-requests-tests.yml index 97b6d9fb..b73e196b 100644 --- a/.github/workflows/pull-requests-tests.yml +++ b/.github/workflows/pull-requests-tests.yml @@ -38,13 +38,6 @@ jobs: - name: Tests run: ./code/gradlew -p code test - - name: Upload test reports - if: failure() - uses: actions/upload-artifact@v7 - with: - name: unit-test-reports - path: code/app/build/reports/tests/ - - name: Build run: ./code/gradlew -p code assembleDebug @@ -92,6 +85,7 @@ jobs: arch: x86_64 profile: pixel_7_pro disable-animations: true + emulator-options: -no-window -gpu swangle_indirect -no-snapshot -noaudio -no-boot-anim script: ./code/gradlew -p code connectedAndroidTest - name: Upload UI test reports diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/LotteryControllerTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/lottery/LotteryControllerTest.kt similarity index 98% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/LotteryControllerTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/lottery/LotteryControllerTest.kt index 0b4fc690..a55c6d9a 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/LotteryControllerTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/lottery/LotteryControllerTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.lottery import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.lottery.LotteryStatus @@ -18,6 +18,12 @@ import org.junit.Before import org.junit.Test import java.util.Date +/* + * Instrumented tests for LotteryController with its Android dependencies. + * + * Outstanding issues: None known. + */ + /** Verifies lottery controller workflows against their Android dependencies. */ class LotteryControllerTest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/messaging/MessageControllerFirestoreTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/messaging/MessageControllerFirestoreTest.kt new file mode 100644 index 00000000..db04763b --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/messaging/MessageControllerFirestoreTest.kt @@ -0,0 +1,122 @@ +package com.example.lambda_bbb_events.controller.messaging + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.controller.user.UserController +import com.example.lambda_bbb_events.model.message.ConversationType +import com.example.lambda_bbb_events.model.message.Message +import com.example.lambda_bbb_events.model.user.Entrant +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeout +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData +import com.example.lambda_bbb_events.support.OwnerMessagingFixture + +/* + * Tests MessageController opening a chat, sending and deleting messages against the real + * Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests [MessageController] as a camper uses it to chat with a campsite owner: opening the + * conversation, seeing sent messages arrive live, and deleting one. Only the signed-in camper is + * faked; the conversation and its messages are in the real Firestore database. + * + * Everything written uses "test-" IDs and is deleted after each test in [cleanUp]. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class MessageControllerFirestoreTest { + private val testData = FirestoreTestData() + private val fixture = OwnerMessagingFixture(testData) + private val users = mockk() + private val controller = MessageController(users, fixture.conversations) + + @Before + fun setUp() = runBlocking { + val camper = Entrant(deviceId = fixture.entrant, name = "Ed") + every { users.currentUser } returns camper + every { users.user } returns camper + fixture.grantAccess() + fixture.book() + testData.add("conversations/" + fixture.ownerConversationId()) + } + + @After + fun cleanUp() { + controller.closeConversation() + testData.cleanUp() + } + + /** Waits until the open chat's messages satisfy [ready], and returns them. */ + private suspend fun awaitMessages(ready: (List) -> Boolean): List = + withTimeout(15_000) { + while (!ready(controller.messages)) delay(100) + controller.messages + } + + /** Opens the camper's chat with the owner and sends [content], marking it for cleanup. */ + private suspend fun openAndSend(content: String): Message { + val id = controller.createConversation(fixture.owner, ConversationType.OWNER) + controller.openConversation(id) + controller.sendMessage(content) + val sent = awaitMessages { list -> list.any { it.content == content } }.first { it.content == content } + testData.add("conversations/$id/messages/${sent.messageId}") + return sent + } + + @Test + fun camperOpensTheirChatWithTheOwner() = runBlocking { + val id = controller.createConversation(fixture.owner, ConversationType.OWNER) + + assertEquals(fixture.ownerConversationId(), id) + assertEquals(fixture.owner, controller.getConversation(id)?.ownerId) + assertEquals(listOf(id), controller.getUserConversations().map { it.conversationId }) + } + + @Test + fun sentMessageAppearsInTheOpenChat() = runBlocking { + val sent = openAndSend("Is there firewood?") + + assertEquals(fixture.entrant, sent.senderId) + assertEquals(fixture.owner, sent.recipientId) + assertTrue(controller.canDelete(sent)) + } + + @Test + fun newestMessageIsFirst() = runBlocking { + openAndSend("First") + openAndSend("Second") + + val settled = awaitMessages { list -> list.map { it.content } == listOf("Second", "First") } + + assertEquals(listOf("Second", "First"), settled.map { it.content }) + } + + @Test + fun deletedMessageShowsAsDeletedInTheOpenChat() = runBlocking { + val sent = openAndSend("Wrong campsite, sorry") + + controller.deleteMessage(sent.messageId) + + val deleted = awaitMessages { list -> list.any { it.messageId == sent.messageId && it.deleted } } + .first { it.messageId == sent.messageId } + assertEquals("", deleted.content) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/messaging/WaitlistMessageFirestoreTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/messaging/WaitlistMessageFirestoreTest.kt new file mode 100644 index 00000000..8c6c7d20 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/messaging/WaitlistMessageFirestoreTest.kt @@ -0,0 +1,131 @@ +package com.example.lambda_bbb_events.controller.messaging + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.controller.user.UserController +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import com.example.lambda_bbb_events.model.lottery.WaitlistStatus +import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import com.example.lambda_bbb_events.model.repository.MessageRepository +import com.example.lambda_bbb_events.model.user.CampsiteOwner +import io.mockk.coEvery +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeout +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData +import com.example.lambda_bbb_events.support.OwnerMessagingFixture + +/* + * Tests the whole Message Waitlist flow against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests the whole Message Waitlist flow against the real Firestore database: an owner sends + * one message to their lottery's waitlist, it lands in each reachable entrant's chat, and + * one log listing only those entrants is saved for admins and for the owner's sent list. + * + * Only the signed-in owner is faked; every read and write goes to Firestore. Everything + * written uses "test-" IDs and is deleted after each test in [cleanUp]. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "For whatever you are not confident on write more tests." + */ +@RunWith(AndroidJUnit4::class) +class WaitlistMessageFirestoreTest { + private val testData = FirestoreTestData() + private val fixture = OwnerMessagingFixture(testData) + private val stranger = "test-entrant-" + UUID.randomUUID() + private val logs = AdminLogRepository() + private val users = mockk() + private val sender = GroupMessageSender(users) + private val content = "Waitlist test " + UUID.randomUUID() + + /** Waitlist entries for the camper who booked, and for [stranger], who never did. */ + private val waitlist = listOf( + WaitlistEntry(entryId = "test-entry-1", entrantId = fixture.entrant, status = WaitlistStatus.IN_WAITLIST), + WaitlistEntry(entryId = "test-entry-2", entrantId = stranger, status = WaitlistStatus.IN_WAITLIST) + ) + + @Before + fun setUp() = runBlocking { + every { users.user } returns CampsiteOwner(deviceId = fixture.owner, name = "Test Owner") + coEvery { users.getUserName(fixture.entrant) } returns "Test Entrant" + fixture.grantAccess() + fixture.book() + testData.add("conversations/" + fixture.ownerConversationId()) + } + + @After + fun cleanUp() { + testData.cleanUp() + } + + /** + * Waits for the owner's log about the test campsite, and marks it and the messages in the + * entrant's chat for cleanup. + */ + private suspend fun awaitLog(): AdminLog { + val log = withTimeout(15_000) { + logs.observeLogsSentBy(fixture.owner, fixture.campsite).first { it.isNotEmpty() } + }.single() + testData.add("notificationLogs/${log.id}") + chat().forEach { testData.add("conversations/${fixture.ownerConversationId()}/messages/${it.messageId}") } + return log + } + + /** The messages in the entrant's chat with the owner. */ + private suspend fun chat() = MessageRepository(fixture.ownerConversationId()).getAll() + + /** Sends the test message to [waitlist]. */ + private suspend fun send() = + sender.sendToWaitlist(waitlist, content, fixture.campsite, "Test campsite") + + @Test + fun messageReachesOnlyEntrantsWhoCanBeMessaged() = runBlocking { + val result = send() + awaitLog() + + assertEquals(1, result.sentCount) + assertEquals(listOf(stranger), result.failedEntrantIds) + } + + @Test + fun messageLandsInTheEntrantsChatFromTheOwner() = runBlocking { + send() + awaitLog() + + val chat = chat() + + assertEquals(listOf(content), chat.map { it.content }) + assertEquals(fixture.owner, chat.single().senderId) + assertEquals(fixture.entrant, chat.single().recipientId) + } + + @Test + fun oneLogListsOnlyTheEntrantsReached() = runBlocking { + send() + val log = awaitLog() + + assertEquals(content, log.content) + assertEquals(GroupMessageSender.LOG_TITLE, log.title) + assertEquals("Test Owner", log.senderName) + assertEquals(listOf(fixture.entrant), log.recipientIds) + assertEquals(mapOf(fixture.entrant to "Test Entrant"), log.recipientNames) + assertEquals("Test campsite", log.campsiteName) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/notification/NotificationControllerTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/notification/NotificationControllerTest.kt new file mode 100644 index 00000000..a26cd96c --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/notification/NotificationControllerTest.kt @@ -0,0 +1,184 @@ +package com.example.lambda_bbb_events.controller.notification + +import android.Manifest +import android.content.Context +import android.os.Build +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import com.example.lambda_bbb_events.controller.user.UserController +import com.example.lambda_bbb_events.model.local.NotificationCategoryStore +import com.example.lambda_bbb_events.model.local.NotificationHistoryStore +import com.example.lambda_bbb_events.model.notifications.Notification +import com.example.lambda_bbb_events.model.notifications.NotificationCategory +import com.example.lambda_bbb_events.model.notifications.NotificationHistory +import com.example.lambda_bbb_events.model.notifications.NotificationMode +import com.example.lambda_bbb_events.model.user.Entrant +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import java.util.UUID +import java.util.concurrent.TimeUnit + +/* + * Tests NotificationController and the device's notification history and category stores. + * + * Outstanding issues: None known. + */ + +/** + * Tests [NotificationController] with the device's real storage: every notification is kept in + * the user's history, opted-out users get nothing, and each category's mode decides whether a + * notification is shown now, saved for a weekly summary, or dropped. Also tests + * [NotificationHistoryStore] and [NotificationCategoryStore] directly. + * + * Each test uses its own user ID and removes what it saved in [cleanUp]. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class NotificationControllerTest { + private val context = ApplicationProvider.getApplicationContext() + private val userId = "test-user-" + UUID.randomUUID() + private val users = mockk() + private val controller = NotificationController(context, users) + private val history = NotificationHistoryStore(context) + private val categories = NotificationCategoryStore(context) + private val lotteryWon = Notification(id = 1, title = "You won!", message = "You won the Pine Lake lottery.") + + @Before + fun signIn() { + allowNotifications() + signInAs(Entrant(deviceId = userId, name = "Ed")) + } + + /** Lets the app post notifications on Android 13 and later, as a user would on first use. */ + private fun allowNotifications() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + InstrumentationRegistry.getInstrumentation().uiAutomation + .grantRuntimePermission(context.packageName, Manifest.permission.POST_NOTIFICATIONS) + } + } + + @After + fun cleanUp() { + history.clear(userId) + val saved = context.getSharedPreferences("notification_categories", Context.MODE_PRIVATE) + saved.edit().apply { saved.all.keys.filter { it.startsWith(userId) }.forEach { remove(it) } }.commit() + } + + /** Signs in [user]. */ + private fun signInAs(user: Entrant) { + every { users.currentUser } returns user + } + + /** Makes the user's pending [category] notifications look a week old, so they are due. */ + private fun makePendingAWeekOld(category: NotificationCategory) { + context.getSharedPreferences("notification_categories", Context.MODE_PRIVATE).edit() + .putLong("${userId}_${category.name}_startedAt", System.currentTimeMillis() - TimeUnit.DAYS.toMillis(8)) + .commit() + } + + @Test + fun everyNotificationIsKeptInHistory() { + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + + assertEquals(listOf("You won!"), history.getHistory(userId).map { it.title }) + } + + @Test + fun optedOutUserGetsNothing() { + signInAs(Entrant(deviceId = userId, notificationsEnabled = false)) + + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + + assertEquals(emptyList(), history.getHistory(userId)) + } + + @Test + fun weeklyCategorySavesNotificationsForTheSummary() { + controller.setCategoryMode(NotificationCategory.LOTTERY, NotificationMode.WEEKLY) + + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + controller.showNotification(lotteryWon.copy(id = 2), NotificationCategory.LOTTERY) + makePendingAWeekOld(NotificationCategory.LOTTERY) + + assertEquals(2, categories.getDueCount(userId, NotificationCategory.LOTTERY)) + } + + @Test + fun weeklySummaryIsNotDueBeforeAWeek() { + controller.setCategoryMode(NotificationCategory.LOTTERY, NotificationMode.WEEKLY) + + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + + assertEquals(0, categories.getDueCount(userId, NotificationCategory.LOTTERY)) + } + + @Test + fun showingTheWeeklySummaryClearsWhatWasSaved() { + controller.setCategoryMode(NotificationCategory.LOTTERY, NotificationMode.WEEKLY) + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + makePendingAWeekOld(NotificationCategory.LOTTERY) + + controller.showWeeklySummaries() + + makePendingAWeekOld(NotificationCategory.LOTTERY) + assertEquals(0, categories.getDueCount(userId, NotificationCategory.LOTTERY)) + } + + @Test + fun mutedCategoryIsKeptInHistoryButNotSaved() { + controller.setCategoryMode(NotificationCategory.LOTTERY, NotificationMode.MUTED) + + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + makePendingAWeekOld(NotificationCategory.LOTTERY) + + assertEquals(1, history.getHistory(userId).size) + assertEquals(0, categories.getDueCount(userId, NotificationCategory.LOTTERY)) + } + + @Test + fun rejectionsDefaultToHighPriorityAndOthersToImmediate() { + assertEquals(NotificationMode.HIGH_PRIORITY, controller.getCategoryMode(userId, NotificationCategory.REJECTION)) + assertEquals(NotificationMode.IMMEDIATE, controller.getCategoryMode(userId, NotificationCategory.LOTTERY)) + } + + @Test + fun chosenModeIsRemembered() { + controller.setCategoryMode(NotificationCategory.CANCELLATION, NotificationMode.WEEKLY) + + assertEquals(NotificationMode.WEEKLY, NotificationController(context, users).getCategoryMode(userId, NotificationCategory.CANCELLATION)) + } + + @Test + fun historyIsNewestFirstAndClearable() = runBlocking { + controller.showNotification(lotteryWon, NotificationCategory.LOTTERY) + controller.showNotification(Notification(id = 2, title = "Booking cancelled", message = "Pine Lake"), NotificationCategory.CANCELLATION) + + assertEquals(listOf("Booking cancelled", "You won!"), controller.observeHistory(userId).first().map { it.title }) + + controller.clearHistory() + assertEquals(emptyList(), history.getHistory(userId)) + } + + @Test + fun historyKeepsOnlyTheLatestHundred() { + repeat(105) { history.add(userId, NotificationHistory(id = "n-$it", title = "Update $it", message = "")) } + + val kept = history.getHistory(userId) + assertEquals(100, kept.size) + assertEquals("Update 104", kept.first().title) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceFirestoreTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceFirestoreTest.kt new file mode 100644 index 00000000..f09eef15 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceFirestoreTest.kt @@ -0,0 +1,150 @@ +package com.example.lambda_bbb_events.controller.notification + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.controller.user.UserController +import com.example.lambda_bbb_events.model.message.Conversation +import com.example.lambda_bbb_events.model.message.Message +import com.example.lambda_bbb_events.model.repository.NotificationPreferenceRepository +import com.example.lambda_bbb_events.model.user.Entrant +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests muting contacts and deciding which chat messages notify, against the real Firestore + * database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests [NotificationPreferenceController] saving mutes to the real Firestore database, and + * [MessageNotificationController] using them to decide whether a chat message should notify. + * The signed-in user is faked; every preference is read from and written to Firestore. + * + * The user's ID starts with "test-", so the rules let [cleanUp] delete their preferences. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class NotificationPreferenceFirestoreTest { + private val testData = FirestoreTestData() + private val userId = "test-entrant-" + UUID.randomUUID() + private val owner = "test-owner-" + UUID.randomUUID() + private val users = mockk() + private val preferences = NotificationPreferenceController(users) + private val notifications = MessageNotificationController(users) + private val conversation = Conversation(conversationId = "owner_${userId}_$owner") + + @Before + fun signIn() { + signInAs(Entrant(deviceId = userId, name = "Ed")) + testData.add("notificationPreferences/$userId/contacts/$owner") + preferences.startListening() + } + + @After + fun cleanUp() { + preferences.stopListening() + testData.cleanUp() + } + + /** Signs in [user]. */ + private fun signInAs(user: Entrant) { + every { users.currentUser } returns user + every { users.user } returns user + } + + /** The owner's preference as saved on the server, read through a fresh connection. */ + private suspend fun saved() = NotificationPreferenceRepository(userId).get(owner) + + /** A chat message from [sender] to [recipient]. */ + private fun message(sender: String = owner, recipient: String = userId, deleted: Boolean = false) = + Message(messageId = "m-1", content = "Gates open at 9", senderId = sender, recipientId = recipient, deleted = deleted) + + @Test + fun mutingIsSavedAndReadBack() = runBlocking { + preferences.mute(owner) + + assertTrue(preferences.isMuted(owner)) + assertTrue(saved()!!.isMuted()) + assertEquals(null, saved()!!.mutedUntil) + } + + @Test + fun mutingForHoursEndsLater() = runBlocking { + val before = System.currentTimeMillis() + + preferences.muteForHours(owner, 8) + + val until = saved()!!.mutedUntil!!.toDate().time + assertTrue(saved()!!.isMuted()) + assertTrue(until >= before + 8 * 3_600_000 - 1_000) + } + + @Test + fun unmutingIsSaved() = runBlocking { + preferences.mute(owner) + + preferences.unmute(owner) + + assertFalse(preferences.isMuted(owner)) + assertFalse(saved()!!.isMuted()) + } + + @Test + fun messageFromAnUnmutedContactNotifies() = runBlocking { + assertTrue(notifications.shouldNotify(conversation, message())) + } + + @Test + fun messageFromAMutedContactDoesNotNotify() = runBlocking { + preferences.mute(owner) + + assertFalse(notifications.shouldNotify(conversation, message())) + } + + @Test + fun messageNotifiesAgainOnceUnmuted() = runBlocking { + preferences.mute(owner) + preferences.unmute(owner) + + assertTrue(notifications.shouldNotify(conversation, message())) + } + + @Test + fun optedOutUserIsNotNotified() = runBlocking { + signInAs(Entrant(deviceId = userId, notificationsEnabled = false)) + + assertFalse(notifications.shouldNotify(conversation, message())) + } + + @Test + fun ownDeletedOrSomeoneElsesMessagesDoNotNotify() = runBlocking { + assertFalse(notifications.shouldNotify(conversation, message(sender = userId, recipient = owner))) + assertFalse(notifications.shouldNotify(conversation, message(deleted = true))) + assertFalse(notifications.shouldNotify(conversation, message(recipient = "test-someone-else"))) + } + + @Test + fun nobodySignedInIsNotNotified() = runBlocking { + every { users.currentUser } returns null + + assertFalse(notifications.shouldNotify(conversation, message())) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/UserControllerTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/user/UserControllerTest.kt similarity index 97% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/UserControllerTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/user/UserControllerTest.kt index 526e627e..dbe37854 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/UserControllerTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/controller/user/UserControllerTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.user import com.example.lambda_bbb_events.model.repository.UserRepository import com.example.lambda_bbb_events.model.user.CampsiteOwner @@ -22,6 +22,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Instrumented tests for UserController with its Android dependencies. + * + * Outstanding issues: None known. + */ + /** Verifies user controller workflows against their Android dependencies. */ class UserControllerTest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/NotificationLogDatabaseTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/NotificationLogDatabaseTest.kt new file mode 100644 index 00000000..57d9a6cf --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/NotificationLogDatabaseTest.kt @@ -0,0 +1,128 @@ +package com.example.lambda_bbb_events.model.local + +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.model.admin.AdminLog +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +/* + * Tests the SQLite copy of the notification logs, and upgrading the local database to add it. + * + * Outstanding issues: None known. + */ + +/** + * Tests [SqliteNotificationLogStore] against a real SQLite database held in memory, and that + * upgrading [LocalDatabase] from version 2 adds the logs table without losing saved data. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "I realized we have a sqlite db and instead we could just sync to local copy and update + * the sqlite3 db." + */ +@RunWith(AndroidJUnit4::class) +class NotificationLogDatabaseTest { + private val context = ApplicationProvider.getApplicationContext() + private lateinit var database: LocalDatabase + private lateinit var store: SqliteNotificationLogStore + + /** A waitlist message from Olive at Pine Lake to Ed and Sam, sent at [timestamp]. */ + private fun log(id: String, timestamp: Long, content: String = "Gates open at 9") = AdminLog( + id = id, + title = "Message to lottery waitlist", + senderId = "owner-1", + senderName = "Olive", + recipientIds = listOf("user-1", "user-2"), + recipientNames = mapOf("user-1" to "Ed", "user-2" to "Sam"), + content = content, + campsiteId = "site-1", + campsiteName = "Pine Lake", + timestamp = timestamp + ) + + @Before + fun setUp() { + database = LocalDatabase(context, name = null) + store = SqliteNotificationLogStore(database) + } + + @After + fun cleanUp() { + database.close() + } + + @Test + fun savedLogReadsBackUnchanged() { + store.upsert(listOf(log("a", 1))) + + assertEquals(listOf(log("a", 1)), store.page("", 0, 10)) + } + + @Test + fun pagesAreNewestFirst() { + store.upsert((1..5).map { log("log-$it", it.toLong()) }) + + assertEquals(listOf("log-5", "log-4"), store.page("", 0, 2).map { it.id }) + assertEquals(listOf("log-1"), store.page("", 4, 2).map { it.id }) + assertEquals(5, store.count("")) + } + + @Test + fun savingALogAgainReplacesIt() { + store.upsert(listOf(log("a", 1, "first"))) + store.upsert(listOf(log("a", 1, "second"))) + + assertEquals(listOf("second"), store.page("", 0, 10).map { it.content }) + } + + @Test + fun newestTimestampIsZeroUntilSomethingIsSaved() { + assertEquals(0L, store.newestTimestamp()) + + store.upsert(listOf(log("a", 7), log("b", 3))) + + assertEquals(7L, store.newestTimestamp()) + } + + @Test + fun searchFindsTextInAnySearchableField() { + store.upsert(listOf(log("a", 1))) + + listOf("gates", "OLIVE", "owner-1", "Sam", "user-2", "pine lake", "site-1", "waitlist").forEach { + assertEquals("search for $it", 1, store.count(it)) + } + assertEquals(0, store.count("raccoon")) + } + + @Test + fun searchTreatsWildcardsAsPlainText() { + store.upsert(listOf(log("a", 1, "50% off"), log("b", 2, "500 off"))) + + assertEquals(listOf("a"), store.page("50%", 0, 10).map { it.id }) + assertEquals(0, store.count("_")) + } + + @Test + fun upgradeFromVersionTwoAddsLogsAndKeepsSavedData() { + SqliteRecentlyViewedStore(database).record("campsite-a", viewedAt = 1L, limit = 10) + SqliteThemePreferenceStore(database).save(true) + val db = database.writableDatabase + db.execSQL("DROP TABLE ${LocalDatabase.NOTIFICATION_LOGS_TABLE}") + + database.onUpgrade(db, 2, LocalDatabase.DATABASE_VERSION) + store.upsert(listOf(log("a", 1))) + + assertEquals(listOf("campsite-a"), SqliteRecentlyViewedStore(database).load(10)) + assertTrue(SqliteThemePreferenceStore(database).load()!!) + assertEquals(1, store.count("")) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/RecentlyViewedDatabaseTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/RecentlyViewedDatabaseTest.kt similarity index 93% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/RecentlyViewedDatabaseTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/RecentlyViewedDatabaseTest.kt index 2f22b38c..3261a064 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/RecentlyViewedDatabaseTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/RecentlyViewedDatabaseTest.kt @@ -1,10 +1,8 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.local import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.lambda_bbb_events.model.local.LocalDatabase -import com.example.lambda_bbb_events.model.local.SqliteRecentlyViewedStore import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue @@ -13,6 +11,12 @@ import org.junit.Test import org.junit.runner.RunWith import java.util.UUID +/* + * Tests the SQLite store of recently viewed campsites. + * + * Outstanding issues: None known. + */ + /** * Tests [SqliteRecentlyViewedStore] against a real SQLite database held in memory. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ThemePreferenceDatabaseTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/ThemePreferenceDatabaseTest.kt similarity index 91% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ThemePreferenceDatabaseTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/ThemePreferenceDatabaseTest.kt index d875f79a..59c609ca 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ThemePreferenceDatabaseTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/local/ThemePreferenceDatabaseTest.kt @@ -1,11 +1,8 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.local import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.lambda_bbb_events.model.local.LocalDatabase -import com.example.lambda_bbb_events.model.local.SqliteRecentlyViewedStore -import com.example.lambda_bbb_events.model.local.SqliteThemePreferenceStore import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -15,6 +12,12 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +/* + * Tests the SQLite store of the theme preference, and upgrading the local database to add it. + * + * Outstanding issues: None known. + */ + /** * Tests [SqliteThemePreferenceStore] against a real SQLite database held in memory, * and that upgrading [LocalDatabase] from version 1 keeps recently viewed campsites. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/CampsiteRepositoryTests.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryTests.kt similarity index 92% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/CampsiteRepositoryTests.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryTests.kt index 06e86f6e..0b19a73b 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/CampsiteRepositoryTests.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryTests.kt @@ -1,9 +1,8 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository 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 junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertFalse import junit.framework.TestCase.assertNull @@ -14,6 +13,14 @@ import org.junit.Before import org.junit.Test import java.time.LocalDate import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests CampsiteRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests [CampsiteRepository] against the real Firestore database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ConversationRepositoryTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ConversationRepositoryTest.kt new file mode 100644 index 00000000..c230148a --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ConversationRepositoryTest.kt @@ -0,0 +1,117 @@ +package com.example.lambda_bbb_events.model.repository + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.model.message.ConversationType +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeout +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData +import com.example.lambda_bbb_events.support.OwnerMessagingFixture + +/* + * Tests ConversationRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests [ConversationRepository] against the real Firestore database: opening a conversation + * between a camper and a campsite owner, and both of them finding it. + * + * Everything written uses "test-" IDs and is deleted after each test in [cleanUp]. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Now what about the remaining android tests that don't involve mocks since the issue with + * mocks is they don't check db access." + */ +@RunWith(AndroidJUnit4::class) +class ConversationRepositoryTest { + private val testData = FirestoreTestData() + private val fixture = OwnerMessagingFixture(testData) + private val conversations = fixture.conversations + + @Before + fun setUp() = runBlocking { + fixture.grantAccess() + fixture.book() + } + + @After + fun cleanUp() { + testData.cleanUp() + } + + @Test + fun camperOpensOneConversationWithTheOwner() = runBlocking { + val id = fixture.openConversation() + + val conversation = conversations.getConversation(id, fixture.entrant)!! + + assertEquals(fixture.ownerConversationId(), id) + assertEquals(fixture.owner, conversation.ownerId) + assertEquals(fixture.campsite, conversation.campsiteId) + assertEquals(ConversationType.OWNER.name, conversation.type) + } + + @Test + fun openingAgainKeepsTheConversationsMessages() = runBlocking { + val id = fixture.openConversation() + val messages = MessageRepository(id) + messages.sendMessage("Hi, is there firewood?", fixture.entrant) + messages.getAll().forEach { testData.add("conversations/$id/messages/${it.messageId}") } + + assertEquals(id, fixture.openConversation()) + + assertEquals("Hi, is there firewood?", conversations.getConversation(id, fixture.owner)?.lastMessage) + } + + @Test + fun camperWithoutAccessCannotOpenOne() = runBlocking { + val stranger = OwnerMessagingFixture(testData) + + val result = runCatching { + conversations.createConversation(stranger.owner, ConversationType.OWNER, stranger.entrant) + } + + assertTrue(result.exceptionOrNull() is IllegalStateException) + assertNull(conversations.getConversation(stranger.ownerConversationId(), stranger.entrant)) + } + + @Test + fun bothPeopleFindTheConversation() = runBlocking { + val id = fixture.openConversation() + + assertEquals(listOf(id), conversations.getUserConversations(fixture.entrant).map { it.conversationId }) + assertEquals(listOf(id), conversations.getOwnerConversations(fixture.owner).map { it.conversationId }) + } + + @Test + fun someoneElseCannotReadIt() = runBlocking { + val id = fixture.openConversation() + + assertNull(conversations.getConversation(id, "test-someone-else")) + } + + @Test + fun ownerSeesANewConversationLive() = runBlocking { + val id = fixture.openConversation() + + val seen = withTimeout(15_000) { + conversations.observeOwnerConversations(fixture.owner).first { list -> list.any { it.conversationId == id } } + } + + assertEquals(listOf(id), seen.map { it.conversationId }) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/LotteryRepositoryTests.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryTests.kt similarity index 92% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/LotteryRepositoryTests.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryTests.kt index 515eaf1a..3205ffc5 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/LotteryRepositoryTests.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryTests.kt @@ -1,8 +1,7 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.lottery.WaitlistEntry -import com.example.lambda_bbb_events.model.repository.LotteryRepository import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertFalse import junit.framework.TestCase.assertNull @@ -12,6 +11,14 @@ import org.junit.After import org.junit.Before import org.junit.Test import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests LotteryRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests [LotteryRepository] against the real Firestore database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/MakeAdminTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/MakeAdminTest.kt similarity index 91% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/MakeAdminTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/MakeAdminTest.kt index 3d248282..b39b3b57 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/MakeAdminTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/MakeAdminTest.kt @@ -1,8 +1,6 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.lambda_bbb_events.model.repository.UserRepository -import com.example.lambda_bbb_events.model.repository.WrongAdminPasswordException import com.example.lambda_bbb_events.model.user.Entrant import com.google.android.gms.tasks.Tasks import com.google.firebase.firestore.FirebaseFirestore @@ -20,6 +18,12 @@ import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith +/* + * Tests how UserRepository.makeAdmin reports failures. + * + * Outstanding issues: None known. + */ + /** * Tests how [UserRepository.makeAdmin] reports failures. Firestore's error codes only load on a * device, so these are not unit tests. Firestore is mocked, so nothing is written to the database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryTest.kt new file mode 100644 index 00000000..c47d57b0 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryTest.kt @@ -0,0 +1,153 @@ +package com.example.lambda_bbb_events.model.repository + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.model.message.Message +import com.google.firebase.Firebase +import com.google.firebase.firestore.FirebaseFirestoreException +import com.google.firebase.firestore.Source +import com.google.firebase.firestore.firestore +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.tasks.await +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import java.time.LocalDate +import com.example.lambda_bbb_events.support.FirestoreTestData +import com.example.lambda_bbb_events.support.OwnerMessagingFixture + +/* + * Tests MessageRepository and the chat message security rules against the real Firestore + * database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests [MessageRepository] against the real Firestore database: sending and deleting chat + * messages between a camper and a campsite owner, and the security rules that stop a message + * being edited or restored once sent. + * + * Everything written uses "test-" IDs and is deleted after each test in [cleanUp]. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Now what about the remaining android tests that don't involve mocks since the issue with + * mocks is they don't check db access." + */ +@RunWith(AndroidJUnit4::class) +class MessageRepositoryTest { + private val testData = FirestoreTestData() + private val fixture = OwnerMessagingFixture(testData) + + @After + fun cleanUp() { + testData.cleanUp() + } + + /** + * Opens a conversation between a camper with a stay ending on [endDate] and the owner. + * + * @return The conversation's messages. + */ + private suspend fun chat(endDate: LocalDate = LocalDate.now().plusDays(5)): MessageRepository { + fixture.grantAccess() + fixture.book(endDate) + return MessageRepository(fixture.openConversation()) + } + + /** + * Sends [content] from [sender] and marks the message for cleanup. + * + * @return The message as saved. + */ + private suspend fun MessageRepository.send(content: String, sender: String = fixture.entrant): Message { + sendMessage(content, sender) + val sent = getAll().first { it.content == content.trim() } + testData.add("conversations/${fixture.ownerConversationId()}/messages/${sent.messageId}") + return sent + } + + /** Reads a message straight from the server, skipping the device's cache. */ + private suspend fun readFromServer(messageId: String) = Firebase.firestore + .document("conversations/${fixture.ownerConversationId()}/messages/$messageId") + .get(Source.SERVER) + .await() + + /** The conversation's preview of its latest message, as the owner sees it. */ + private suspend fun preview() = + fixture.conversations.getConversation(fixture.ownerConversationId(), fixture.owner)?.lastMessage + + /** Checks that [write] is refused by the security rules. */ + private suspend fun assertRejected(write: suspend () -> Unit) { + val error = runCatching { write() }.exceptionOrNull() + assertTrue( + "expected PERMISSION_DENIED, got $error", + (error as? FirebaseFirestoreException)?.code == FirebaseFirestoreException.Code.PERMISSION_DENIED + ) + } + + @Test + fun sentMessageReachesTheOwner() = runBlocking { + val messages = chat() + + val sent = messages.send(" Is there firewood? ") + + assertEquals("Is there firewood?", sent.content) + assertEquals(fixture.entrant, sent.senderId) + assertEquals(fixture.owner, sent.recipientId) + assertEquals("Is there firewood?", preview()) + } + + @Test + fun deletedMessageIsClearedForBothPeople() = runBlocking { + val messages = chat() + val sent = messages.send("Wrong campsite, sorry") + + messages.deleteMessage(sent.messageId, fixture.entrant) + + val saved = readFromServer(sent.messageId) + assertEquals("", saved.getString("content")) + assertEquals(true, saved.getBoolean("deleted")) + assertEquals(Message.DELETED_TEXT, preview()) + } + + @Test + fun rulesStopAMessageBeingEdited() = runBlocking { + val messages = chat() + val sent = messages.send("Gate code is 1234") + + assertRejected { readFromServer(sent.messageId).reference.update("content", "Gate code is 9999").await() } + + assertEquals("Gate code is 1234", readFromServer(sent.messageId).getString("content")) + } + + @Test + fun rulesStopADeletedMessageComingBack() = runBlocking { + val messages = chat() + val sent = messages.send("Rude message") + messages.deleteMessage(sent.messageId, fixture.entrant) + + assertRejected { + readFromServer(sent.messageId).reference + .update(mapOf("content" to "Rude message", "deleted" to false)).await() + } + + assertEquals(true, readFromServer(sent.messageId).getBoolean("deleted")) + } + + @Test + fun camperCannotMessageOnceTheirStayHasEnded() = runBlocking { + val messages = chat(endDate = LocalDate.now().minusDays(1)) + + val result = runCatching { messages.sendMessage("Still there?", fixture.entrant) } + + assertTrue(result.exceptionOrNull() is IllegalStateException) + assertEquals(emptyList(), messages.getAll()) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/NotificationLogFirestoreTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/NotificationLogFirestoreTest.kt new file mode 100644 index 00000000..1a98166c --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/NotificationLogFirestoreTest.kt @@ -0,0 +1,136 @@ +package com.example.lambda_bbb_events.model.repository + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.controller.admin.AdminLogController +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.admin.LogType +import com.example.lambda_bbb_events.model.local.InMemoryNotificationLogStore +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeout +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests notification logs against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests notification logs against the real Firestore database: the security rules accept the + * log the app writes, an owner sees only their own sent notifications, and a new log reaches + * the admin's local copy live and can be searched. + * + * Senders are named "test-..." so the rules let [cleanUp] delete their logs afterwards. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay but you could do a real firestore test yourself by making a android test right?" + */ +@RunWith(AndroidJUnit4::class) +class NotificationLogFirestoreTest { + private val testData = FirestoreTestData() + private val repository = AdminLogRepository() + private val owner = "test-owner-" + UUID.randomUUID() + private val campsite = "test-campsite-" + UUID.randomUUID() + + /** + * Logs a waitlist message from [sender] about the test campsite to two entrants. + * + * @param sender Device ID of the sender. + * @param content The message text. + */ + private suspend fun send(sender: String, content: String) { + repository.logNotification( + title = "Message to lottery waitlist", + senderId = sender, + senderName = "Android test", + recipientIds = listOf("test-user-1", "test-user-2"), + content = content, + recipientNames = mapOf("test-user-1" to "Ed", "test-user-2" to "Sam"), + campsiteId = campsite, + campsiteName = "Test campsite" + ) + } + + /** + * Waits for [sender]'s logs about the test campsite to number [count], marking each for + * [cleanUp]. + * + * @return Those logs, newest first. + */ + private suspend fun awaitSentBy(sender: String, count: Int): List = + withTimeout(TIMEOUT_MS) { + repository.observeLogsSentBy(sender, campsite).first { it.size == count } + }.onEach { testData.add("notificationLogs/${it.id}") } + + @After + fun cleanUp() { + testData.cleanUp() + } + + @Test + fun ownerSeesOnlyTheirOwnSentNotifications() = runBlocking { + val otherOwner = "test-owner-" + UUID.randomUUID() + send(owner, "Gates open at 9") + send(otherOwner, "Not yours") + + val sent = awaitSentBy(owner, 1) + awaitSentBy(otherOwner, 1) + + assertEquals(listOf("Gates open at 9"), sent.map { it.content }) + assertEquals(mapOf("test-user-1" to "Ed", "test-user-2" to "Sam"), sent.single().recipientNames) + assertEquals("Test campsite", sent.single().campsiteName) + } + + @Test + fun newestSentNotificationComesFirst() = runBlocking { + send(owner, "First") + delay(5) + send(owner, "Second") + + assertEquals(listOf("Second", "First"), awaitSentBy(owner, 2).map { it.content }) + } + + @Test + fun newLogReachesTheAdminLiveAndCanBeSearched() = runBlocking { + val controller = AdminLogController(repository, InMemoryNotificationLogStore()) + val sync = launch(Dispatchers.Default) { controller.syncNotificationLogs() } + val word = "raccoon" + UUID.randomUUID().toString().take(8) + + try { + send(owner, "Live test $word") + awaitSentBy(owner, 1) + + val found = withTimeout(TIMEOUT_MS) { + var logs = controller.getLogs(LogType.NOTIFICATION, word) + while (logs.isEmpty()) { + delay(200) + logs = controller.getLogs(LogType.NOTIFICATION, word) + } + logs + } + + assertEquals(listOf(owner), found.map { it.senderId }) + } finally { + sync.cancel() + } + } + + private companion object { + /** How long to wait for Firestore, in milliseconds. */ + const val TIMEOUT_MS = 15_000L + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ReservationRepositoryTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryTest.kt similarity index 94% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ReservationRepositoryTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryTest.kt index 9717b4b3..ca1e0c2d 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ReservationRepositoryTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryTest.kt @@ -1,8 +1,7 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository import com.example.lambda_bbb_events.model.reservation.Reservation import com.example.lambda_bbb_events.model.reservation.ReservationStatus -import com.example.lambda_bbb_events.model.repository.ReservationRepository import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNull import junit.framework.TestCase.assertTrue @@ -12,6 +11,14 @@ import org.junit.After import org.junit.Before import org.junit.Test import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests ReservationRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests [ReservationRepository] against the real Firestore database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReviewReactionReplyRepositoryTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReviewReactionReplyRepositoryTest.kt new file mode 100644 index 00000000..41fb90d4 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReviewReactionReplyRepositoryTest.kt @@ -0,0 +1,153 @@ +package com.example.lambda_bbb_events.model.repository + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.model.campsite.Campsite +import com.example.lambda_bbb_events.model.review.Review +import com.example.lambda_bbb_events.model.review.ReviewReaction +import com.example.lambda_bbb_events.model.review.ReviewReply +import com.google.firebase.firestore.FirebaseFirestoreException +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests review reactions, replies and their security rules against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests [ReviewReactionRepository] and [ReviewReplyRepository] against the real Firestore + * database, including the security rules: one reaction per person and review, only the listed + * emojis, replies of 1 to 300 characters, and only on reviews that exist. + * + * Everything written uses "test-" IDs and is deleted after each test in [cleanUp]. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Now what about the remaining android tests that don't involve mocks since the issue with + * mocks is they don't check db access." + */ +@RunWith(AndroidJUnit4::class) +class ReviewReactionReplyRepositoryTest { + private val testData = FirestoreTestData() + private val reviews = ReviewRepository() + private val reactions = ReviewReactionRepository() + private val replies = ReviewReplyRepository() + private lateinit var reviewId: String + + @Before + fun setUp() = runBlocking { + val campsiteId = testData.newId("campsites", prefix = "test-campsite") + CampsiteRepository().addCampsite(Campsite(campsiteId = campsiteId, campsiteName = "Test Campsite")) + val review = Review(Review.idFor(campsiteId, "test-reviewer"), campsiteId, "test-reviewer", 4, "Quiet") + testData.add("reviews/" + review.reviewId) + reviews.add(review) + reviewId = review.reviewId + } + + @After + fun cleanUp() { + reviews.stopListening() + reactions.stopListening() + replies.stopListening() + testData.cleanUp() + } + + /** A [reactor]'s [emoji] reaction to [onReview], marked for cleanup. */ + private fun reaction(reactor: String = "test-reactor", emoji: String = "👍", onReview: String = reviewId) = + ReviewReaction(ReviewReaction.idFor(onReview, reactor), onReview, reactor, emoji) + .also { testData.add("reviewReactions/" + it.reactionId) } + + /** A reply saying [text] to [onReview], marked for cleanup. */ + private fun reply(text: String, onReview: String = reviewId) = + ReviewReply(replies.newReplyId(), onReview, "test-replier", text) + .also { testData.add("reviewReplies/" + it.replyId) } + + /** Checks that [write] is refused by the security rules. */ + private suspend fun assertRejected(write: suspend () -> Unit) { + val error = runCatching { write() }.exceptionOrNull() + assertTrue( + "expected PERMISSION_DENIED, got $error", + (error as? FirebaseFirestoreException)?.code == FirebaseFirestoreException.Code.PERMISSION_DENIED + ) + } + + @Test + fun reactionIsSavedAndReadBack() = runBlocking { + val thumbsUp = reaction() + + reactions.add(thumbsUp) + + assertEquals(thumbsUp, reactions.get(thumbsUp.reactionId)) + } + + @Test + fun reactingAgainReplacesTheOldReaction() = runBlocking { + reactions.add(reaction(emoji = "👍")) + + reactions.update(reaction(emoji = "❤️")) + + assertEquals("❤️", reactions.get(reaction().reactionId)?.emoji) + } + + @Test + fun rulesRejectAnEmojiNotOnTheList() = runBlocking { + assertRejected { reactions.add(reaction(emoji = "🔥")) } + } + + @Test + fun rulesRejectAReactionWithTheWrongId() = runBlocking { + val misnamed = reaction().copy(reactionId = "test-wrong-id") + testData.add("reviewReactions/test-wrong-id") + + assertRejected { reactions.add(misnamed) } + } + + @Test + fun rulesRejectAReactionToAMissingReview() = runBlocking { + assertRejected { reactions.add(reaction(onReview = "test-missing-review")) } + } + + @Test + fun replyIsSavedAndReadBack() = runBlocking { + val answer = reply("Thanks for staying!") + + replies.add(answer) + + assertEquals(answer, replies.get(answer.replyId)) + } + + @Test + fun rulesAllowAReplyOfExactlyTheLimit() = runBlocking { + val longest = reply("a".repeat(ReviewReply.MAX_TEXT_LENGTH)) + + replies.add(longest) + + assertEquals(longest.text, replies.get(longest.replyId)?.text) + } + + @Test + fun rulesRejectAReplyOverTheLimit() = runBlocking { + assertRejected { replies.add(reply("a".repeat(ReviewReply.MAX_TEXT_LENGTH + 1))) } + } + + @Test + fun rulesRejectAnEmptyReply() = runBlocking { + assertRejected { replies.add(reply("")) } + } + + @Test + fun rulesRejectAReplyToAMissingReview() = runBlocking { + assertRejected { replies.add(reply("Hello?", onReview = "test-missing-review")) } + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ReviewRepositoryTests.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryTests.kt similarity index 90% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ReviewRepositoryTests.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryTests.kt index b6d15b2b..46fcb1f9 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/ReviewRepositoryTests.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryTests.kt @@ -1,9 +1,7 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.lambda_bbb_events.model.campsite.Campsite -import com.example.lambda_bbb_events.model.repository.CampsiteRepository -import com.example.lambda_bbb_events.model.repository.ReviewRepository import com.example.lambda_bbb_events.model.review.Review import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -15,6 +13,14 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests ReviewRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests [ReviewRepository] against the real Firestore database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/UserRepositoryTests.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/UserRepositoryTests.kt similarity index 89% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/UserRepositoryTests.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/UserRepositoryTests.kt index 11833944..d58a616b 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/UserRepositoryTests.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/UserRepositoryTests.kt @@ -1,7 +1,6 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.lambda_bbb_events.model.repository.UserRepository import com.example.lambda_bbb_events.model.user.Entrant import kotlinx.coroutines.test.runTest import org.junit.After @@ -13,6 +12,14 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests UserRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests [UserRepository] against the real Firestore database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/WaitlistEntryRepositoryTests.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryTests.kt similarity index 91% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/WaitlistEntryRepositoryTests.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryTests.kt index 5e062954..10e454ba 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/WaitlistEntryRepositoryTests.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryTests.kt @@ -1,8 +1,7 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.repository import com.example.lambda_bbb_events.model.lottery.WaitlistEntry import com.example.lambda_bbb_events.model.lottery.WaitlistStatus -import com.example.lambda_bbb_events.model.repository.WaitlistEntryRepository import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertFalse import junit.framework.TestCase.assertNull @@ -12,6 +11,14 @@ import org.junit.After import org.junit.Before import org.junit.Test import java.util.UUID +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests WaitlistEntryRepository against the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests [WaitlistEntryRepository] against the real Firestore database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrarTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrarTest.kt new file mode 100644 index 00000000..ab5b5c2b --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrarTest.kt @@ -0,0 +1,94 @@ +package com.example.lambda_bbb_events.model.services + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.firebase.Firebase +import com.google.firebase.firestore.FieldValue +import com.google.firebase.firestore.FirebaseFirestoreException +import com.google.firebase.firestore.Source +import com.google.firebase.firestore.firestore +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.tasks.await +import org.junit.After +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests that the real Firestore database accepts push tokens and keeps them private. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + +/** + * Tests that the real Firestore database accepts the push token [FcmTokenRegistrar] saves, and + * that the security rules keep tokens private and in the expected shape. If the rules refused + * the token, nobody on that device would get push notifications, and nothing in the app would + * show it. + * + * Each test's device ID starts with "test-", so the rules let [cleanUp] delete its token. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Now what about the remaining android tests that don't involve mocks since the issue with + * mocks is they don't check db access." + */ +@RunWith(AndroidJUnit4::class) +class FcmTokenRegistrarTest { + private val testData = FirestoreTestData() + private val deviceId = testData.newId("fcmTokens", prefix = "test-device") + private val tokenRef = Firebase.firestore.collection("fcmTokens").document(deviceId) + + @After + fun cleanUp() { + testData.cleanUp() + } + + /** Runs [action] and returns the Firestore error code it failed with, or `null`. */ + private suspend fun errorCodeOf(action: suspend () -> Unit) = + (runCatching { action() }.exceptionOrNull() as? FirebaseFirestoreException)?.code + + @Test + fun savedTokenIsAccepted() = runBlocking { + assertEquals(null, errorCodeOf { FcmTokenRegistrar.save(deviceId, "test-token").await() }) + } + + @Test + fun refreshedTokenReplacesTheOldOne() = runBlocking { + FcmTokenRegistrar.save(deviceId, "test-token-1").await() + + assertEquals(null, errorCodeOf { FcmTokenRegistrar.save(deviceId, "test-token-2").await() }) + } + + @Test + fun tokensCannotBeReadByTheApp() = runBlocking { + FcmTokenRegistrar.save(deviceId, "test-token").await() + + assertEquals( + FirebaseFirestoreException.Code.PERMISSION_DENIED, + errorCodeOf { tokenRef.get(Source.SERVER).await() } + ) + } + + @Test + fun rulesRejectExtraFields() = runBlocking { + val withExtra = mapOf("token" to "test-token", "updatedAt" to FieldValue.serverTimestamp(), "owner" to "x") + + assertEquals( + FirebaseFirestoreException.Code.PERMISSION_DENIED, + errorCodeOf { tokenRef.set(withExtra).await() } + ) + } + + @Test + fun rulesRejectAnEmptyToken() = runBlocking { + assertEquals( + FirebaseFirestoreException.Code.PERMISSION_DENIED, + errorCodeOf { FcmTokenRegistrar.save(deviceId, "").await() } + ) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/PlaceSearchParsingTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/services/PlaceSearchParsingTest.kt similarity index 92% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/PlaceSearchParsingTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/model/services/PlaceSearchParsingTest.kt index a9f9f120..f3321c47 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/PlaceSearchParsingTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/model/services/PlaceSearchParsingTest.kt @@ -1,11 +1,6 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.model.services import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.lambda_bbb_events.model.services.PlaceDetails -import com.example.lambda_bbb_events.model.services.PlaceSuggestion -import com.example.lambda_bbb_events.model.services.parsePhotonPlaces -import com.example.lambda_bbb_events.model.services.parsePlace -import com.example.lambda_bbb_events.model.services.parseSuggestions import org.json.JSONObject import org.junit.Assert.assertEquals import org.junit.Assert.assertThrows @@ -13,6 +8,12 @@ import org.junit.Test import org.junit.runner.RunWith import java.io.IOException +/* + * Tests reading place search responses from the Places API and Photon. + * + * Outstanding issues: None known. + */ + /** * Tests reading responses from the Places API and Photon. JSON is only available on a device, so * these are not unit tests. Nothing is sent to either service. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/FirestoreTestData.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/FirestoreTestData.kt similarity index 92% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/FirestoreTestData.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/support/FirestoreTestData.kt index e774438d..a5a75cff 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/FirestoreTestData.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/FirestoreTestData.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.support import com.google.firebase.Firebase import com.google.firebase.firestore.FirebaseFirestore @@ -7,6 +7,13 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.tasks.await import java.util.UUID +/* + * Test helper that tracks what a test writes to the real Firestore database and deletes it + * afterwards. + * + * Outstanding issues: None known. + */ + /** * Keeps track of what a test writes to the real Firestore database so it can be removed. * diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/FirestoreTestDataTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/FirestoreTestDataTest.kt similarity index 86% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/FirestoreTestDataTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/support/FirestoreTestDataTest.kt index 1d29e703..c52f9686 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/FirestoreTestDataTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/FirestoreTestDataTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.support import com.google.firebase.Firebase import com.google.firebase.firestore.firestore @@ -10,6 +10,13 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Tests that FirestoreTestData removes test data from the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ + /** * Tests that [FirestoreTestData] removes test data from the real Firestore database. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/OwnerMessagingFixture.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/OwnerMessagingFixture.kt new file mode 100644 index 00000000..9133b459 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/support/OwnerMessagingFixture.kt @@ -0,0 +1,88 @@ +package com.example.lambda_bbb_events.support + +import com.example.lambda_bbb_events.model.message.Conversation +import com.example.lambda_bbb_events.model.message.ConversationType +import com.example.lambda_bbb_events.model.repository.ConversationRepository +import com.example.lambda_bbb_events.model.repository.MessagingAccessRepository +import com.example.lambda_bbb_events.model.reservation.Reservation +import com.example.lambda_bbb_events.model.reservation.ReservationStatus +import com.google.firebase.Firebase +import com.google.firebase.firestore.firestore +import kotlinx.coroutines.tasks.await +import java.time.LocalDate +import java.util.UUID + +/* + * Test helper that sets up a camper who may message a campsite owner in the real Firestore + * database. + * + * Outstanding issues: None known. + */ + +/** + * Sets up a camper who may message a campsite owner, in the real Firestore database, the way + * the app does once the camper books: messaging access to the owner's campsite and a + * reservation there. Everything written is marked in [testData] for cleanup. + * + * Every ID starts with "test-", which the security rules require before test data can be + * deleted. + * + * @param testData Tracks the documents to delete after the test. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Now what about the remaining android tests that don't involve mocks since the issue with + * mocks is they don't check db access." + */ +class OwnerMessagingFixture(private val testData: FirestoreTestData) { + val entrant = "test-entrant-" + UUID.randomUUID() + val owner = "test-owner-" + UUID.randomUUID() + val campsite = "test-campsite-" + UUID.randomUUID() + val conversations = ConversationRepository() + + /** Gives the camper messaging access to the owner's campsite. */ + suspend fun grantAccess() { + testData.add("messagingAccess/$entrant/campsites/$campsite") + MessagingAccessRepository(entrant).grantAccess(campsite, owner) + } + + /** + * Books the camper a confirmed stay at the campsite. + * + * @param endDate The last night of the stay; a stay that has ended no longer allows + * messaging the owner. + */ + suspend fun book(endDate: LocalDate = LocalDate.now().plusDays(5)) { + val id = testData.newId("reservations", prefix = "test-reservation") + val reservation = Reservation( + reservationId = id, + campsiteId = campsite, + entrantId = entrant, + ownerId = owner, + startDate = endDate.minusDays(2).toString(), + endDate = endDate.toString(), + status = ReservationStatus.CONFIRMED + ) + Firebase.firestore.collection("reservations").document(id).set(reservation).await() + } + + /** + * Opens the camper's conversation with the owner. + * + * @return The conversation's ID. + */ + suspend fun openConversation(): String { + if (!opened) testData.add("conversations/" + ownerConversationId()) + opened = true + return conversations.createConversation(owner, ConversationType.OWNER, entrant) + } + + /** Whether [openConversation] has marked the conversation for cleanup. */ + private var opened = false + + /** The ID the camper's conversation with the owner has. */ + fun ownerConversationId() = Conversation.ownerConversationId(entrant, owner) +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/AccountRemovedUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/AccountRemovedUITest.kt index e6ae0cfb..d4994b32 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/AccountRemovedUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/AccountRemovedUITest.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.test.performScrollTo import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.lambda_bbb_events.LambdaEventsApp import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.UserController +import com.example.lambda_bbb_events.controller.user.UserController 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.User @@ -26,6 +26,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests that the app returns to the welcome screen when the signed-in account is removed. + * + * Outstanding issues: None known. + */ + /** * Tests that the app leaves whatever screen is open and goes back to the welcome screen, without * crashing, when the signed-in user's account is removed by someone else, such as an admin. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ChatAndPolicyScreensUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ChatAndPolicyScreensUITest.kt new file mode 100644 index 00000000..b4a76df6 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ChatAndPolicyScreensUITest.kt @@ -0,0 +1,159 @@ +package com.example.lambda_bbb_events.ui.account + +import androidx.compose.material3.Text +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasClickAction +import androidx.compose.ui.test.hasSetTextAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.longClick +import androidx.compose.ui.test.onNodeWithContentDescription +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.performTextInput +import androidx.compose.ui.test.performTouchInput +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.messaging.MessageController +import com.example.lambda_bbb_events.model.message.Message +import com.example.lambda_bbb_events.view.ui.user_screens.notification.ChatScreen +import com.example.lambda_bbb_events.view.ui.user_screens.profile.AppPoliciesScreen +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests for chatting with a campsite owner and reading the app policy (US 01.11.01, + * 01.14.01, 02.12.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests the chat screen campers and campsite owners use to message each other, and the app + * policy screen. The message controller is mocked, so nothing is sent to the database; sending + * against Firestore is tested in MessageControllerFirestoreTest. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class ChatAndPolicyScreensUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val messages = mockk(relaxed = true) + private val fromOwner = Message(messageId = "m-1", content = "Gates open at 9", senderId = "owner-1", recipientId = "user-1") + private val fromCamper = Message(messageId = "m-2", content = "Is there firewood?", senderId = "user-1", recipientId = "owner-1") + + /** Opens the camper's chat with the owner showing [shown], where sending is [canSend]. */ + private fun openChat(shown: List, canSend: Boolean = true) { + every { messages.messages } returns shown + every { messages.canDelete(any()) } answers { firstArg().senderId == "user-1" } + composeTestRule.setContent { + ChatScreen( + conversationId = "owner_user-1_owner-1", + title = "Olive", + subtitle = "Pine Lake", + currentUserId = "user-1", + messageController = messages, + navController = rememberNavController(), + canSend = canSend + ) + } + composeTestRule.waitForIdle() + } + + @Test + fun openingTheChatLoadsTheConversation() { + openChat(listOf(fromOwner, fromCamper)) + + verify { messages.openConversation("owner_user-1_owner-1") } + composeTestRule.onNodeWithText("Olive").assertIsDisplayed() + composeTestRule.onNodeWithText("Gates open at 9").assertIsDisplayed() + composeTestRule.onNodeWithText("Is there firewood?").assertIsDisplayed() + } + + @Test + fun emptyChatSaysSo() { + openChat(emptyList()) + + composeTestRule.onNodeWithText("No messages yet").assertIsDisplayed() + } + + @Test + fun camperSendsAMessage() { + openChat(emptyList()) + + composeTestRule.onNode(hasSetTextAction()).performTextInput(" Can I bring a dog? ") + composeTestRule.onNodeWithContentDescription("Send message").performClick() + composeTestRule.waitForIdle() + + coVerify { messages.sendMessage("Can I bring a dog?") } + } + + @Test + fun failedSendIsExplained() { + coEvery { messages.sendMessage(any()) } throws IllegalStateException("The lottery enrollment or reservation has ended") + openChat(emptyList()) + + composeTestRule.onNode(hasSetTextAction()).performTextInput("Hello?") + composeTestRule.onNodeWithContentDescription("Send message").performClick() + composeTestRule.waitForIdle() + + composeTestRule.onNode(hasText("Failed to send message", substring = true)).assertIsDisplayed() + } + + @Test + fun readOnlyChatHasNoMessageBox() { + openChat(listOf(fromOwner), canSend = false) + + composeTestRule.onNodeWithText("This conversation is read-only.").assertIsDisplayed() + composeTestRule.onAllNodes(hasSetTextAction()).fetchSemanticsNodes().let { assert(it.isEmpty()) } + } + + @Test + fun camperDeletesTheirOwnMessage() { + openChat(listOf(fromCamper)) + + composeTestRule.onNodeWithText("Is there firewood?").performTouchInput { longClick() } + composeTestRule.onNodeWithText("Delete message?").assertIsDisplayed() + composeTestRule.onNode(hasText("Delete") and hasClickAction()).performClick() + composeTestRule.waitForIdle() + + coVerify { messages.deleteMessage("m-2") } + } + + @Test + fun appPolicyShowsTheRulesAndAcceptGoesBack() { + composeTestRule.setContent { + val navController = rememberNavController() + NavHost(navController, startDestination = "home") { + composable("home") { Text("Home screen") } + composable("policy") { AppPoliciesScreen(navController) } + } + LaunchedEffect(Unit) { navController.navigate("policy") } + } + + composeTestRule.onNodeWithText("3. Lottery and Reservation Rules").assertIsDisplayed() + composeTestRule.onNodeWithText("9. Policy Updates").performScrollTo().assertIsDisplayed() + composeTestRule.onNodeWithTag("button_accept_policy").performScrollTo().performClick() + + composeTestRule.onNodeWithText("Home screen").assertIsDisplayed() + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/NotificationOptOutUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/NotificationOptOutUITest.kt index 7fcc1f1a..2a6847c8 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/NotificationOptOutUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/NotificationOptOutUITest.kt @@ -14,7 +14,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import com.example.lambda_bbb_events.LambdaEventsApp import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.UserController +import com.example.lambda_bbb_events.controller.user.UserController import com.example.lambda_bbb_events.model.repository.UserRepository import com.example.lambda_bbb_events.model.user.Entrant import io.mockk.clearAllMocks @@ -28,6 +28,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for opting out of and back in to notifications (US 01.10.01). + * + * Outstanding issues: None known. + */ + /** * Tests that an entrant can opt out of, and back in to, notifications from the notification * settings screen (US 01.10.01). diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/PhoneNumberFieldUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/PhoneNumberFieldUITest.kt index a6f0f683..acb02a75 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/PhoneNumberFieldUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/PhoneNumberFieldUITest.kt @@ -19,6 +19,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for choosing a country calling code for a phone number on sign up. + * + * Outstanding issues: None known. + */ + /** * Tests picking a country calling code from the dropdown for the phone number on the sign up screen. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfilePictureUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfilePictureUITest.kt index 16e0d6b3..cca8e2f1 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfilePictureUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfilePictureUITest.kt @@ -21,6 +21,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for adding, changing and removing a profile picture (US 01.08.02). + * + * Outstanding issues: None known. + */ + /** * Tests adding and removing a profile picture on the edit profile screen. * diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfileScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfileScreenUITest.kt index 7bb1f0cd..ff91fef4 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfileScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/ProfileScreenUITest.kt @@ -28,6 +28,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for viewing and editing profile information (US 01.07.03). + * + * Outstanding issues: None known. + */ + /** Verifies how the profile screen displays and edits account information. */ @RunWith(AndroidJUnit4::class) class ProfileScreenUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SettingsScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SettingsScreenUITest.kt index a43aace8..c9ebcdae 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SettingsScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SettingsScreenUITest.kt @@ -1,10 +1,11 @@ package com.example.lambda_bbb_events.ui.account import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasTestTag import androidx.compose.ui.test.junit4.v2.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick -import androidx.compose.ui.test.performScrollTo +import androidx.compose.ui.test.performScrollToNode import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController @@ -26,6 +27,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for logging out and deleting the account from settings (US 01.08.01). + * + * Outstanding issues: None known. + */ + /** * Verifies the log out and delete account dialogs on the settings screen. * @@ -69,12 +76,15 @@ class SettingsScreenUITest { } /** - * Taps a settings row by its route. + * Taps a settings row by its route, scrolling the list to it first. The list scrolls itself + * to the row, because a row just below the screen is already built but not yet placed, and + * scrolling to that row directly does not move the list on small screens. * * @param route The row's route, such as "log_out". */ private fun tapRow(route: String) { - composeTestRule.onNodeWithTag("settings_$route").performScrollTo().performClick() + composeTestRule.onNodeWithTag("screen_settings").performScrollToNode(hasTestTag("settings_$route")) + composeTestRule.onNodeWithTag("settings_$route").performClick() } @Test diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SignUpScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SignUpScreenUITest.kt index fb476abc..67cf9636 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SignUpScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/SignUpScreenUITest.kt @@ -16,6 +16,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the sign up screen. + * + * Outstanding issues: None known. + */ + /** Verifies the sign-up flow through the Android UI. */ @RunWith(AndroidJUnit4::class) class SignUpScreenUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/StartupScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/StartupScreenUITest.kt index bd33e2fb..0fde82c2 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/StartupScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/account/StartupScreenUITest.kt @@ -20,6 +20,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the loading and welcome screens shown when the app starts. + * + * Outstanding issues: None known. + */ + /** * Tests the screens shown when the app starts, before the main app: the loading screen * while the account is checked, and sign up for devices without an account. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminBrowseScreensUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminBrowseScreensUITest.kt new file mode 100644 index 00000000..2ec0256c --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminBrowseScreensUITest.kt @@ -0,0 +1,272 @@ +package com.example.lambda_bbb_events.ui.admin + +import androidx.compose.material3.Text +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasClickAction +import androidx.compose.ui.test.hasSetTextAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onAllNodesWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTextInput +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.admin.AdminLogController +import com.example.lambda_bbb_events.controller.AppControllers +import com.example.lambda_bbb_events.controller.campsite.CampsiteController +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.admin.LogType +import com.example.lambda_bbb_events.model.campsite.Campsite +import com.example.lambda_bbb_events.model.campsite.CampsiteStore +import com.example.lambda_bbb_events.model.image.ImageMetaData +import com.example.lambda_bbb_events.model.local.InMemoryNotificationLogStore +import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import com.example.lambda_bbb_events.model.user.Admin +import com.example.lambda_bbb_events.model.user.Entrant +import com.example.lambda_bbb_events.view.ui.admin_screens.AdminCampsitesScreen +import com.example.lambda_bbb_events.view.ui.admin_screens.AdminImagesScreen +import com.example.lambda_bbb_events.view.ui.admin_screens.logs.AdminLogsScreen +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.emptyFlow +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests for admins browsing campsites, images and message logs (US 03.01.01, 03.03.01, + * 03.04.01, 03.06.01, 03.12.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests the admin screens for browsing and searching campsites, browsing and removing images, + * and reviewing the messages campsite owners sent. Campsite search uses a real + * [CampsiteController] and the logs a real [AdminLogController]; only the database behind them + * is faked. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class AdminBrowseScreensUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val controllers = mockk(relaxed = true) + private val pineLake = Campsite( + campsiteId = "site-1", + campsiteName = "Pine Lake", + address = "Banff", + active = true, + imageIds = listOf(ImageMetaData(imageId = "img-site")) + ) + private val birchBay = Campsite(campsiteId = "site-2", campsiteName = "Birch Bay", address = "Jasper", active = true) + private val ed = Entrant(deviceId = "user-1", name = "Ed", profilePictureImageId = "img-ed") + + @Before + fun signInAsAdmin() { + every { controllers.users.currentUser } returns Admin(deviceId = "admin-1", name = "Ada") + } + + /** Opens [screen], with a stand-in for the campsite page admins open from the list. */ + private fun open(screen: @androidx.compose.runtime.Composable (androidx.navigation.NavController) -> Unit) { + composeTestRule.setContent { + val navController = rememberNavController() + NavHost(navController, startDestination = "screen") { + composable("screen") { screen(navController) } + composable("owner_campsite_details/{campsiteId}") { + Text("Details of ${it.arguments?.getString("campsiteId")}") + } + } + } + composeTestRule.waitForIdle() + } + + /** Uses a real campsite controller over Pine Lake and Birch Bay. */ + private fun useRealCampsites() { + val store = mockk(relaxed = true) + every { store.campsites } returns mutableMapOf("site-1" to pineLake, "site-2" to birchBay) + every { controllers.campsites } returns CampsiteController(store, scope = CoroutineScope(Dispatchers.Unconfined)) + } + + /** Taps the clickable element labelled [label]. */ + private fun tap(label: String) { + composeTestRule.onNode(hasText(label) and hasClickAction()).performClick() + composeTestRule.waitForIdle() + } + + @Test + fun adminSeesEveryCampsite() { + useRealCampsites() + open { AdminCampsitesScreen(it, controllers) } + + composeTestRule.onAllNodesWithTag("adminCampsiteItem").assertCountEquals(2) + composeTestRule.onNodeWithText("Pine Lake").assertIsDisplayed() + composeTestRule.onNodeWithText("Birch Bay").assertIsDisplayed() + } + + @Test + fun adminSearchesCampsites() { + useRealCampsites() + open { AdminCampsitesScreen(it, controllers) } + + composeTestRule.onNode(hasSetTextAction()).performTextInput("birch") + composeTestRule.waitForIdle() + + composeTestRule.onAllNodesWithTag("adminCampsiteItem").assertCountEquals(1) + composeTestRule.onNodeWithText("Birch Bay").assertIsDisplayed() + } + + @Test + fun adminOpensACampsiteToRemoveIt() { + useRealCampsites() + open { AdminCampsitesScreen(it, controllers) } + + composeTestRule.onNodeWithText("Pine Lake").performClick() + + composeTestRule.onNodeWithText("Details of site-1").assertIsDisplayed() + } + + @Test + fun nonAdminsCannotBrowseCampsites() { + useRealCampsites() + every { controllers.users.currentUser } returns ed + open { AdminCampsitesScreen(it, controllers) } + + composeTestRule.onAllNodesWithTag("adminCampsiteItem").assertCountEquals(0) + } + + /** Opens the image gallery with Pine Lake's photo and Ed's profile picture. */ + private fun openImages() { + every { controllers.campsites.getAllCampsites() } returns listOf(pineLake) + every { controllers.campsites.getCampsite("site-1") } returns pineLake + coEvery { controllers.users.getAllUsers() } returns listOf(ed) + coEvery { controllers.images.deleteImage(any()) } returns true + open { AdminImagesScreen(it, controllers) } + } + + @Test + fun adminSeesCampsiteAndProfileImages() { + openImages() + + composeTestRule.onAllNodesWithTag("adminImageItem").assertCountEquals(2) + composeTestRule.onNodeWithText("Pine Lake #1").assertIsDisplayed() + composeTestRule.onNodeWithText("Ed").assertIsDisplayed() + } + + @Test + fun tabsSeparateCampsiteAndProfileImages() { + openImages() + + tap("Campsites") + composeTestRule.onAllNodesWithTag("adminImageItem").assertCountEquals(1) + composeTestRule.onNodeWithText("Pine Lake #1").assertIsDisplayed() + + tap("Users") + composeTestRule.onAllNodesWithTag("adminImageItem").assertCountEquals(1) + composeTestRule.onNodeWithText("Ed").assertIsDisplayed() + } + + @Test + fun adminRemovesACampsitePhoto() { + openImages() + + composeTestRule.onNodeWithText("Pine Lake #1").performClick() + composeTestRule.onNodeWithText("Remove Image?").assertIsDisplayed() + tap("Remove") + + verify { controllers.campsites.updateCampsite("site-1", pineLake.copy(imageIds = emptyList()), any()) } + coVerify { controllers.images.deleteImage("img-site") } + } + + @Test + fun adminRemovesAProfilePicture() { + openImages() + + composeTestRule.onNodeWithText("Ed").performClick() + tap("Remove") + + coVerify { controllers.users.removeProfilePicture("user-1") } + coVerify { controllers.images.deleteImage("img-ed") } + } + + @Test + fun cancellingKeepsTheImage() { + openImages() + + composeTestRule.onNodeWithText("Ed").performClick() + tap("Cancel") + + coVerify(exactly = 0) { controllers.images.deleteImage(any()) } + } + + /** Opens the Messages tab of the admin logs with one owner-to-entrant message. */ + private fun openMessageLogs() { + val repository = mockk() + every { repository.observeNotificationLogsSince(any()) } returns emptyFlow() + coEvery { repository.getMessageLogs() } returns listOf( + AdminLog( + id = "m-1", + type = LogType.MESSAGE, + senderId = "owner-1", + senderName = "Olive", + recipientIds = listOf("user-1"), + recipientNames = mapOf("user-1" to "Ed"), + content = "Gates open at 9", + timestamp = 1_000L + ), + AdminLog( + id = "m-2", + type = LogType.MESSAGE, + senderId = "owner-2", + senderName = "Bram", + recipientIds = listOf("user-2"), + recipientNames = mapOf("user-2" to "Sam"), + content = "Bring bug spray", + timestamp = 2_000L + ) + ) + every { controllers.adminLogs } returns AdminLogController(repository, InMemoryNotificationLogStore()) + every { controllers.users.userRepository.users } returns emptyList() + every { controllers.campsites.campsites } returns emptyMap() + open { AdminLogsScreen(it, controllers) } + tap("Messages") + } + + @Test + fun adminReviewsMessagesOwnersSent() { + openMessageLogs() + + composeTestRule.onNodeWithText("From: Olive").assertIsDisplayed() + composeTestRule.onNodeWithText("To: Ed").assertIsDisplayed() + composeTestRule.onNodeWithText("From: Bram").assertIsDisplayed() + } + + @Test + fun adminSearchesMessages() { + openMessageLogs() + + composeTestRule.onNode(hasSetTextAction()).performTextInput("bug spray") + composeTestRule.waitForIdle() + + composeTestRule.onNodeWithText("From: Bram").assertIsDisplayed() + composeTestRule.onAllNodes(hasText("From: Olive")).assertCountEquals(0) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminLogsLiveUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminLogsLiveUITest.kt new file mode 100644 index 00000000..4d453ff0 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminLogsLiveUITest.kt @@ -0,0 +1,157 @@ +package com.example.lambda_bbb_events.ui.admin + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertTextContains +import androidx.compose.ui.test.hasSetTextAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onFirst +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTextInput +import androidx.navigation.compose.rememberNavController +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.controller.admin.AdminLogController +import com.example.lambda_bbb_events.controller.AppControllers +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.local.InMemoryNotificationLogStore +import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import com.example.lambda_bbb_events.model.user.Admin +import com.example.lambda_bbb_events.view.ui.admin_screens.logs.AdminLogsScreen +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.flow +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests that the admin Logs screen shows new notification logs live (US 03.08.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests that the admin Logs screen shows a notification log as soon as it is sent, without + * refreshing, that searching finds it, and that a failed sync can be retried. + * + * The real [AdminLogController] and its local copy are used; only the database connection is + * faked, so a test can send logs through it as another device would. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "For whatever you are not confident on write more tests." + */ +@RunWith(AndroidJUnit4::class) +class AdminLogsLiveUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val controllers = mockk(relaxed = true) + private val repository = mockk() + private val database = MutableSharedFlow>(extraBufferCapacity = 16) + + /** A waitlist message titled [title] saying [content], sent at [timestamp]. */ + private fun log(id: String, title: String, content: String, timestamp: Long) = AdminLog( + id = id, + title = title, + senderId = "owner-1", + senderName = "Olive", + recipientIds = listOf("user-1"), + recipientNames = mapOf("user-1" to "Ed"), + content = content, + timestamp = timestamp + ) + + @Before + fun setUp() { + every { controllers.users.currentUser } returns Admin(deviceId = "admin-1", name = "Ada") + every { controllers.users.userRepository.users } returns emptyList() + every { controllers.campsites.campsites } returns emptyMap() + } + + /** Opens the Logs screen, with the database sending logs from [logsFromDatabase]. */ + private fun openLogs(logsFromDatabase: Flow> = database) { + every { repository.observeNotificationLogsSince(any()) } returns logsFromDatabase + every { controllers.adminLogs } returns AdminLogController(repository, InMemoryNotificationLogStore()) + composeTestRule.setContent { + AdminLogsScreen(rememberNavController(), controllers) + } + } + + /** Sends [logs] from the database, as if another device had just written them. */ + private fun arrive(vararg logs: AdminLog) { + composeTestRule.waitUntil(5_000) { database.subscriptionCount.value > 0 } + check(database.tryEmit(logs.toList())) { "the fake database's buffer is full" } + } + + /** Waits until text matching [text] is on screen. */ + private fun awaitText(text: String) { + composeTestRule.waitUntil(5_000) { + composeTestRule.onAllNodes(hasText(text)).fetchSemanticsNodes().isNotEmpty() + } + } + + @Test + fun newLogAppearsWithoutRefreshing() { + openLogs() + awaitText("No notification logs available.") + + arrive(log("log-1", "Gate notice", "Gates open at 9", 1)) + + awaitText("Gate notice") + composeTestRule.onNodeWithText("Gate notice").assertIsDisplayed() + } + + @Test + fun newestLogIsListedFirstAsMoreArrive() { + openLogs() + arrive(log("log-1", "First notice", "a", 1)) + awaitText("First notice") + + arrive(log("log-2", "Second notice", "b", 2)) + awaitText("Second notice") + + composeTestRule.onAllNodes(hasText("notice", substring = true)).onFirst() + .assertTextContains("Second notice") + } + + @Test + fun searchFindsALogThatArrivedLive() { + openLogs() + arrive( + log("log-1", "Gate notice", "Gates open at 9", 1), + log("log-2", "Bear notice", "Raccoon in the trash", 2) + ) + awaitText("Bear notice") + + composeTestRule.onNode(hasSetTextAction()).performTextInput("raccoon") + + composeTestRule.waitUntil(5_000) { + composeTestRule.onAllNodes(hasText("Gate notice")).fetchSemanticsNodes().isEmpty() + } + composeTestRule.onNodeWithText("Bear notice").assertIsDisplayed() + } + + @Test + fun failedSyncCanBeRetried() { + var attempts = 0 + openLogs(flow { + attempts++ + if (attempts == 1) throw IllegalStateException("Offline") + emit(listOf(log("log-1", "Gate notice", "Gates open at 9", 1))) + }) + awaitText("Offline") + + composeTestRule.onNodeWithText("Retry").performClick() + + awaitText("Gate notice") + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminProfileDetailsScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminProfileDetailsScreenUITest.kt index de49e0ed..d7c3287b 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminProfileDetailsScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/admin/AdminProfileDetailsScreenUITest.kt @@ -42,6 +42,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for admins messaging, promoting and removing users (US 03.02.01, 03.07.01). + * + * Outstanding issues: None known. + */ + /** * Tests messaging, promoting users to admin, and removing users from [AdminProfileDetailsScreen], opened * by clicking the user in [AdminProfilesScreen]. Controllers are mocked, so nothing is written diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/MyReservationsScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/MyReservationsScreenUITest.kt index 8818ff5a..338ce51f 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/MyReservationsScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/MyReservationsScreenUITest.kt @@ -22,6 +22,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the bookings screens' active, past and lottery tabs (US 01.06.01, 01.06.02). + * + * Outstanding issues: None known. + */ + /** Verifies reservation information shown in the bookings UI. */ @RunWith(AndroidJUnit4::class) class MyReservationsScreenUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RegistrationStatusScreenTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RegistrationStatusScreenTest.kt index 12a35e8b..da3c5933 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RegistrationStatusScreenTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RegistrationStatusScreenTest.kt @@ -30,6 +30,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the screen showing a lottery entry's status. + * + * Outstanding issues: None known. + */ + /** * Tests the screen showing the status of an entrant's lottery registration. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/ReservationConfirmationUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/ReservationConfirmationUITest.kt new file mode 100644 index 00000000..3e10d5c9 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/ReservationConfirmationUITest.kt @@ -0,0 +1,168 @@ +package com.example.lambda_bbb_events.ui.bookings + +import androidx.compose.material3.Text +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onAllNodesWithText +import androidx.compose.ui.test.onFirst +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollTo +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.reservation.ReservationController +import com.example.lambda_bbb_events.model.campsite.Campsite +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import com.example.lambda_bbb_events.model.lottery.WaitlistStatus +import com.example.lambda_bbb_events.model.user.Entrant +import com.example.lambda_bbb_events.view.ui.user_screens.bookings.BookingReceiptScreen +import com.example.lambda_bbb_events.view.ui.user_screens.bookings.CampsiteWinnerAvailabilityScreen +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.mockk +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.time.YearMonth + +/* + * UI tests for a lottery winner confirming a reservation and seeing the receipt (US 01.05.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests that an entrant who won a lottery can confirm their reservation and then sees the + * booking confirmation. + * + * Dates are picked in next month, so they are always in the future and never fall on the + * leading or trailing days of the calendar grid. + */ +@RunWith(AndroidJUnit4::class) +class ReservationConfirmationUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val controllers = mockk(relaxed = true) + private val reservations = mockk(relaxed = true) + private val nextMonth = YearMonth.now().plusMonths(1) + private var openedWinnerScreen = false + + /** + * Opens the date picker for a won entry, coming from its registration status screen like + * in the app. The receipt route is a stand-in that shows which reservation it was given. + */ + private fun openDatePicker() { + val campsite = mockk(relaxed = true) + every { campsite.campsiteId } returns "site-1" + every { campsite.campsiteName } returns "Pine Lake" + every { campsite.maxOccupancy } returns 6 + every { controllers.campsites.getCampsite("site-1") } returns campsite + every { controllers.waitlistEntries.getEntryById("entry-1") } returns WaitlistEntry( + entryId = "entry-1", + entrantId = "device-1", + lotteryId = "lottery-1", + numberOfGuests = 2, + status = WaitlistStatus.WON + ) + every { controllers.users.user } returns Entrant(deviceId = "device-1") + every { controllers.reservations } returns reservations + every { reservations.getFullyBookedDates(any(), any(), any()) } returns emptySet() + + composeTestRule.setContent { + val navController = rememberNavController() + + NavHost(navController = navController, startDestination = "registrationStatus/{entryId}") { + composable("registrationStatus/{entryId}") { + Text("Registration status") + LaunchedEffect(Unit) { + if (!openedWinnerScreen) { + openedWinnerScreen = true + navController.navigate("winner_availability") + } + } + } + composable("winner_availability") { + CampsiteWinnerAvailabilityScreen(navController, controllers, "entry-1", "site-1") + } + composable("booking_receipt/{reservationId}") { backStackEntry -> + Text("Receipt for ${backStackEntry.arguments?.getString("reservationId")}") + } + } + } + } + + /** Taps the 10th and 12th of next month in the calendar. */ + private fun pickDates() { + composeTestRule.onNodeWithText("›").performScrollTo().performClick() + composeTestRule.onNodeWithText("10").performScrollTo().performClick() + composeTestRule.onNodeWithText("12").performScrollTo().performClick() + } + + @Test + fun confirmIsDisabledUntilDatesArePicked() { + openDatePicker() + + composeTestRule.onNodeWithText("Confirm Reservation").performScrollTo().assertIsNotEnabled() + } + + @Test + fun confirmingSavesTheReservationAndOpensTheReceipt() { + coEvery { reservations.confirmLotteryReservation(any(), any(), any(), any(), any(), any()) } returns Unit + openDatePicker() + + pickDates() + composeTestRule.onNodeWithText("Confirm Reservation").performScrollTo().performClick() + + composeTestRule.onNodeWithText("Receipt for lottery_entry-1").assertIsDisplayed() + coVerify(exactly = 1) { + reservations.confirmLotteryReservation( + entryId = "entry-1", + entrantId = "device-1", + campsiteId = "site-1", + fromDate = nextMonth.atDay(10), + endDate = nextMonth.atDay(12), + numberOfGuests = 2 + ) + } + } + + @Test + fun failedConfirmationShowsTheErrorAndStays() { + coEvery { + reservations.confirmLotteryReservation(any(), any(), any(), any(), any(), any()) + } throws IllegalStateException("The booking period has already ended.") + openDatePicker() + + pickDates() + composeTestRule.onNodeWithText("Confirm Reservation").performScrollTo().performClick() + + composeTestRule.onNodeWithText("The booking period has already ended.").assertIsDisplayed() + composeTestRule.onNodeWithText("Receipt for lottery_entry-1").assertDoesNotExist() + } + + @Test + fun receiptShowsTheConfirmedBooking() { + composeTestRule.setContent { + BookingReceiptScreen( + navController = rememberNavController(), + campsiteName = "Pine Lake", + fromDate = "2026-12-10", + endDate = "2026-12-12", + numberOfGuests = 2 + ) + } + + composeTestRule.onNodeWithText("Booking Confirmed").assertIsDisplayed() + composeTestRule.onAllNodesWithText("Pine Lake").onFirst().assertIsDisplayed() + composeTestRule.onNodeWithText("From: 2026-12-10").assertIsDisplayed() + composeTestRule.onNodeWithText("To: 2026-12-12").assertIsDisplayed() + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RuleConfirmScreenTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RuleConfirmScreenTest.kt index e2818508..e8dd3716 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RuleConfirmScreenTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/bookings/RuleConfirmScreenTest.kt @@ -23,6 +23,12 @@ import org.junit.Test import org.junit.runner.RunWith import java.time.LocalDate +/* + * UI tests for confirming campsite rules before joining a lottery (US 02.11.01). + * + * Outstanding issues: None known. + */ + /** Verifies the rules confirmation screen and its user interactions. */ @RunWith(AndroidJUnit4::class) class RuleConfirmScreenTest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteDetailsScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteDetailsScreenUITest.kt index 4e1e560b..fa25d153 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteDetailsScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteDetailsScreenUITest.kt @@ -23,6 +23,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the campsite details screen (US 01.01.05). + * + * Outstanding issues: None known. + */ + /** Verifies the campsite details screen and its user interactions. */ @RunWith(AndroidJUnit4::class) class CampsiteDetailsScreenUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteImageCarouselUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteImageCarouselUITest.kt index 155dd2ba..8fe3bb79 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteImageCarouselUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/CampsiteImageCarouselUITest.kt @@ -21,6 +21,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for moving between a campsite's photos. + * + * Outstanding issues: None known. + */ + /** * Tests moving between a campsite's images with the carousel's Previous and Next buttons. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreScreenUITest.kt index f22dc213..0b787cdc 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreScreenUITest.kt @@ -6,6 +6,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick @@ -18,6 +19,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.lambda_bbb_events.controller.AppControllers import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.view.ui.user_screens.explore.CampsiteDetailsScreen +import com.example.lambda_bbb_events.view.ui.user_screens.explore.CampsiteSection +import com.example.lambda_bbb_events.view.ui.user_screens.explore.SeeAllCampsitesScreen import com.example.lambda_bbb_events.view.ui.user_screens.explore.ExploreMapScreen import com.example.lambda_bbb_events.view.ui.user_screens.explore.ExploreDefaultScreen import io.mockk.clearAllMocks @@ -30,6 +33,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for browsing campsites on the Explore screen (US 01.01.01, 01.01.03). + * + * Outstanding issues: None known. + */ + /** Verifies campsite browsing through the Explore screen. */ @RunWith(AndroidJUnit4::class) class ExploreScreenUITest { @@ -77,6 +86,17 @@ class ExploreScreenUITest { } } + composable("see_all_campsites/{source}/{section}") { backStackEntry -> + val section = CampsiteSection.valueOf( + backStackEntry.arguments?.getString("section") ?: return@composable + ) + Box( + Modifier.fillMaxSize().testTag("test_see_all") + ) { + SeeAllCampsitesScreen(navController, section, emptyList()) + } + } + composable("campsite_details/{campsiteId}") { backStackEntry -> val campsiteId = backStackEntry.arguments?.getString("campsiteId") ?: return@composable @@ -126,7 +146,7 @@ class ExploreScreenUITest { composeTestRule.onNodeWithTag("seeAllButton") .performClick() - composeTestRule.onNodeWithTag("test_explore_default") + composeTestRule.onNodeWithTag("test_see_all") .assertIsDisplayed() } @@ -135,10 +155,10 @@ class ExploreScreenUITest { composeTestRule.onNodeWithTag("seeAllButton") .performClick() - composeTestRule.onNodeWithTag("test_explore_default") + composeTestRule.onNodeWithTag("test_see_all") .assertIsDisplayed() - composeTestRule.onNodeWithTag("nav_explore") + composeTestRule.onNodeWithContentDescription("Back") .performClick() composeTestRule.onNodeWithTag("test_explore_map") diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreSearchUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreSearchUITest.kt new file mode 100644 index 00000000..75dc6843 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/ExploreSearchUITest.kt @@ -0,0 +1,97 @@ +package com.example.lambda_bbb_events.ui.campsites + +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.hasSetTextAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.performImeAction +import androidx.compose.ui.test.performTextClearance +import androidx.compose.ui.test.performTextInput +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.campsite.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 io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests for searching campsites from the Explore screen's own search bar (US 01.01.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests that typing in the Explore screen's search bar narrows the list straight away, using a + * real [CampsiteController] over three campsites. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class ExploreSearchUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val campsites = listOf( + Campsite(campsiteId = "lake", campsiteName = "Lakeside Retreat", address = "Banff", active = true), + Campsite(campsiteId = "forest", campsiteName = "Forest Hideout", address = "Jasper", active = true), + Campsite(campsiteId = "meadow", campsiteName = "Meadow Field", address = "Canmore", active = true) + ).associateBy { it.campsiteId }.toMutableMap() + + @Before + fun setUp() { + val store = mockk(relaxed = true) + every { store.campsites } returns campsites + val controllers = mockk(relaxed = true) + every { controllers.campsites } returns CampsiteController(store, scope = CoroutineScope(Dispatchers.Unconfined)) + composeTestRule.setContent { ExploreDefaultScreen(rememberNavController(), controllers) } + } + + /** How many times [name] is shown. */ + private fun shown(name: String) = composeTestRule.onAllNodes(hasText(name)) + + @Test + fun typingNarrowsTheListStraightAway() { + composeTestRule.onNode(hasSetTextAction()).performTextInput("forest") + composeTestRule.waitForIdle() + + shown("Forest Hideout").assertCountEquals(1) + shown("Lakeside Retreat").assertCountEquals(0) + shown("Meadow Field").assertCountEquals(0) + } + + @Test + fun searchingByPlaceFindsTheCampsiteThere() { + composeTestRule.onNode(hasSetTextAction()).performTextInput("Canmore") + composeTestRule.onNode(hasSetTextAction()).performImeAction() + composeTestRule.waitForIdle() + + shown("Meadow Field").assertCountEquals(1) + shown("Forest Hideout").assertCountEquals(0) + } + + @Test + fun clearingTheSearchShowsEveryCampsiteAgain() { + composeTestRule.onNode(hasSetTextAction()).performTextInput("forest") + composeTestRule.waitForIdle() + composeTestRule.onNode(hasSetTextAction()).performTextClearance() + composeTestRule.waitForIdle() + + shown("Lakeside Retreat").assertCountEquals(1) + shown("Meadow Field").assertCountEquals(1) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/FilterPageUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/FilterPageUITest.kt index 6280da21..4c621c2d 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/FilterPageUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/FilterPageUITest.kt @@ -19,7 +19,7 @@ import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.swipe import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.example.lambda_bbb_events.controller.CampsiteController +import com.example.lambda_bbb_events.controller.campsite.CampsiteController import com.example.lambda_bbb_events.model.campsite.CampsiteFilters import com.example.lambda_bbb_events.view.ui.components.filter.HomeCampsiteFilter import io.mockk.clearAllMocks @@ -37,6 +37,12 @@ import org.junit.Test import org.junit.runner.RunWith import java.time.LocalDate +/* + * UI tests for the campsite filters and their effect on results (US 01.01.02). + * + * Outstanding issues: None known. + */ + /** Verifies the campsite filter controls and their effects on results. */ @RunWith(AndroidJUnit4::class) class FilterPageUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/OpenStreetMapUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/OpenStreetMapUITest.kt index 657f0ff7..f4ac4b63 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/OpenStreetMapUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/campsites/OpenStreetMapUITest.kt @@ -24,6 +24,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the OpenStreetMap maps drawn by MapLibre. + * + * Outstanding issues: None known. + */ + /** * Tests the native OpenStreetMap maps drawn by MapLibre. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/CreateCampsiteScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/CreateCampsiteScreenUITest.kt index d43629cf..4905bbe6 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/CreateCampsiteScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/CreateCampsiteScreenUITest.kt @@ -43,6 +43,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the campsite creation form (US 02.01.01, 02.01.02). + * + * Outstanding issues: None known. + */ + /** Verifies the campsite creation flow across its form steps. */ @RunWith(AndroidJUnit4::class) class CreateCampsiteScreenUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/LocationSearchUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/LocationSearchUITest.kt index a5ba9faf..a1f53973 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/LocationSearchUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/LocationSearchUITest.kt @@ -32,6 +32,12 @@ import org.junit.Test import org.junit.runner.RunWith import java.io.IOException +/* + * UI tests for searching for a campsite's location by name. + * + * Outstanding issues: None known. + */ + /** * Tests searching for a campsite's location by name. The search is mocked, so nothing is sent * to the search service. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/PhotoFocusDialogUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/PhotoFocusDialogUITest.kt index 0d47115c..287e8c9f 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/PhotoFocusDialogUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/create/PhotoFocusDialogUITest.kt @@ -18,6 +18,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for choosing which part of a photo stays in view when cropped. + * + * Outstanding issues: None known. + */ + /** * Tests choosing the part of a photo that stays in view when it is cropped. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/BackNavigationUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/BackNavigationUITest.kt index abf0a0c5..f0b405ef 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/BackNavigationUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/BackNavigationUITest.kt @@ -15,6 +15,12 @@ import org.junit.Before import org.junit.Rule import org.junit.Test +/* + * UI tests that tapping back repeatedly only goes back one screen at a time. + * + * Outstanding issues: None known. + */ + /** * Tests that spamming the back arrow only goes back one screen. */ diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeScreenUITest.kt index 5015770d..6ec422d8 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeScreenUITest.kt @@ -13,8 +13,10 @@ import androidx.compose.ui.test.performTextInput 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.model.campsite.CampsiteFilters 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 org.junit.After @@ -23,6 +25,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for the home screen's content and controls. + * + * Outstanding issues: None known. + */ + /** Verifies campsite content and user interactions on the home screen. */ @RunWith(AndroidJUnit4::class) class HomeScreenUITest { @@ -32,6 +40,7 @@ class HomeScreenUITest { @Before fun setup() { val controllers = mockk(relaxed = true) + every { controllers.campsites.filters } returns CampsiteFilters() composeTestRule.setContent { HomeScreen( diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeSearchUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeSearchUITest.kt index e4f0cd22..97959a61 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeSearchUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/HomeSearchUITest.kt @@ -12,7 +12,7 @@ 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.controller.campsite.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 @@ -30,6 +30,12 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +/* + * UI tests for searching campsites from the home screen (US 01.01.01). + * + * Outstanding issues: None known. + */ + /** * Tests searching from the home screen, which opens the explore screen with the results, using * a real [CampsiteController] over three campsites. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/NavigationScreenUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/NavigationScreenUITest.kt index 4e094c44..5d1e15ae 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/NavigationScreenUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/navigation/NavigationScreenUITest.kt @@ -28,6 +28,12 @@ import org.junit.runner.RunWith import androidx.navigation.NavHostController import com.example.lambda_bbb_events.view.ui.user_screens.explore.ExploreMapScreen +/* + * UI tests for moving between the app's main screens with the bottom bar. + * + * Outstanding issues: None known. + */ + /** Verifies navigation between the app's main destinations. */ @RunWith(AndroidJUnit4::class) class NavigationScreenUITest { diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManageLotterySentMessagesUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManageLotterySentMessagesUITest.kt new file mode 100644 index 00000000..8be783d1 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManageLotterySentMessagesUITest.kt @@ -0,0 +1,104 @@ +package com.example.lambda_bbb_events.ui.owner + +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +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.model.admin.AdminLog +import com.example.lambda_bbb_events.model.campsite.Campsite +import com.example.lambda_bbb_events.view.ui.owner_screens.OwnerManageLotteryScreen +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.flow.MutableStateFlow +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests that Manage Lottery shows the owner the messages they sent (US 02.10.02). + * + * Outstanding issues: None known. + */ + +/** + * Tests that the Manage Lottery screen shows the signed-in owner the messages they sent about + * that campsite, asking for exactly that owner's and campsite's messages, and shows new ones + * as they are sent. Controllers are mocked, so nothing is read from the database. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "For whatever you are not confident on write more tests." + */ +@RunWith(AndroidJUnit4::class) +class ManageLotterySentMessagesUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val controllers = mockk(relaxed = true) + private val sent = MutableStateFlow>(emptyList()) + + private val gatesLog = AdminLog( + id = "log-1", + senderId = "owner-1", + recipientIds = listOf("user-1"), + recipientNames = mapOf("user-1" to "Ed"), + content = "Gates open at 9", + campsiteId = "site-1", + timestamp = 1_000L + ) + + @Before + fun setUp() { + every { controllers.users.deviceId } returns "owner-1" + every { controllers.campsites.getCampsite("site-1") } returns + Campsite(campsiteId = "site-1", campsiteName = "Pine Lake") + every { controllers.lotteries.getLotteriesForCampsite(any(), any()) } returns emptyList() + every { controllers.adminLogs.observeSentBy("owner-1", "site-1") } returns sent + } + + /** Opens the Manage Lottery screen for the test campsite. */ + private fun openScreen() { + composeTestRule.setContent { + OwnerManageLotteryScreen(rememberNavController(), controllers, "site-1") + } + } + + @Test + fun asksForThisOwnersMessagesAboutThisCampsite() { + openScreen() + composeTestRule.waitForIdle() + + verify { controllers.adminLogs.observeSentBy("owner-1", "site-1") } + } + + @Test + fun showsTheMessagesTheOwnerSent() { + sent.value = listOf(gatesLog) + + openScreen() + + composeTestRule.onNodeWithTag("text_sent_messages_title").assertTextEquals("Sent Messages (1)") + composeTestRule.onNodeWithText("Gates open at 9").assertExists() + composeTestRule.onNodeWithText("Sent to Ed").assertExists() + } + + @Test + fun messageSentWhileOpenAppears() { + openScreen() + composeTestRule.onNodeWithTag("text_sent_messages_title").assertTextEquals("Sent Messages (0)") + + sent.value = listOf(gatesLog) + + composeTestRule.onNodeWithTag("text_sent_messages_title").assertTextEquals("Sent Messages (1)") + composeTestRule.onNodeWithText("Gates open at 9").assertExists() + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManagePhotosUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManagePhotosUITest.kt index 065cb599..1751e184 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManagePhotosUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/ManagePhotosUITest.kt @@ -41,6 +41,12 @@ import org.junit.Test import org.junit.runner.RunWith import java.io.File +/* + * UI tests for changing a campsite's photos (US 02.01.03). + * + * Outstanding issues: None known. + */ + /** * Tests changing a campsite's photos from the edit campsite screen. Photos are stored by a mock, * and Android's photo picker is replaced, so nothing is uploaded. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/OwnerBookingScreensUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/OwnerBookingScreensUITest.kt new file mode 100644 index 00000000..893b57d9 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/OwnerBookingScreensUITest.kt @@ -0,0 +1,191 @@ +package com.example.lambda_bbb_events.ui.owner + +import androidx.compose.material3.Text +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasScrollAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.v2.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.performScrollToNode +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.lottery.LotteryFilter +import com.example.lambda_bbb_events.controller.lottery.LotteryPhase +import com.example.lambda_bbb_events.controller.reservation.ReservationFilter +import com.example.lambda_bbb_events.model.campsite.Campsite +import com.example.lambda_bbb_events.model.lottery.Lottery +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import com.example.lambda_bbb_events.model.lottery.WaitlistStatus +import com.example.lambda_bbb_events.model.reservation.Reservation +import com.example.lambda_bbb_events.model.reservation.ReservationStatus +import com.example.lambda_bbb_events.model.user.Entrant +import com.example.lambda_bbb_events.view.ui.owner_screens.OwnerLotteryDetailsScreen +import com.example.lambda_bbb_events.view.ui.owner_screens.ViewBookedDatesScreen +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.mockk +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.time.LocalDate + +/* + * UI tests for the owner's view of a lottery's waitlist and of their campsite's bookings + * (US 02.06.01, 02.08.01, 02.09.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests the screens where a campsite owner sees who joined a lottery's waitlist, deletes a + * lottery, sees who has booked their campsite, and rejects a booking. Controllers are mocked, + * so nothing is read from or written to the database. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class OwnerBookingScreensUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val controllers = mockk(relaxed = true) + private val pineLake = Campsite(campsiteId = "site-1", ownerId = "owner-1", campsiteName = "Pine Lake", maxOccupancy = 6) + private val lottery = Lottery(lotteryId = "lottery-1", campsiteIds = listOf("site-1"), ownerIds = listOf("owner-1"), waitlistCapacity = 10) + private val edsEntry = WaitlistEntry(entryId = "e-1", entrantId = "user-1", lotteryId = "lottery-1", numberOfGuests = 2, status = WaitlistStatus.IN_WAITLIST) + private val samsEntry = WaitlistEntry(entryId = "e-2", entrantId = "user-2", lotteryId = "lottery-1", numberOfGuests = 1, status = WaitlistStatus.WON) + private val edsStay = Reservation( + reservationId = "r-1", + campsiteId = "site-1", + entrantId = "user-1", + ownerId = "owner-1", + startDate = LocalDate.now().plusDays(3).toString(), + endDate = LocalDate.now().plusDays(5).toString(), + guests = 3, + status = ReservationStatus.CONFIRMED + ) + + @Before + fun setUp() { + every { controllers.campsites.getCampsite("site-1") } returns pineLake + coEvery { controllers.lotteries.getLottery("lottery-1") } returns lottery + every { controllers.lotteries.getLotteriesForCampsite("site-1", LotteryFilter.ALL) } returns listOf(lottery) + every { controllers.lotteries.getPhase(any()) } returns LotteryPhase.REGISTRATION_OPEN + coEvery { controllers.users.getUserName("user-1") } returns "Ed" + coEvery { controllers.users.getUserName("user-2") } returns "Sam" + coEvery { controllers.users.getUser("user-1") } returns Entrant(deviceId = "user-1", name = "Ed") + every { controllers.reservations.getFullyBookedDates(any(), any(), any()) } returns emptySet() + } + + /** Opens [screen] on top of a home screen, so going back can be seen. */ + private fun open(screen: @androidx.compose.runtime.Composable (androidx.navigation.NavController) -> Unit) { + composeTestRule.setContent { + val navController = rememberNavController() + NavHost(navController, startDestination = "home") { + composable("home") { Text("Home screen") } + composable("screen") { screen(navController) } + } + LaunchedEffect(Unit) { navController.navigate("screen") } + } + composeTestRule.waitForIdle() + } + + /** Opens the lottery details screen with [entries] on the waitlist. */ + private fun openLottery(entries: List) { + every { controllers.waitlistEntries.getEntriesForLottery("lottery-1") } returns entries + open { OwnerLotteryDetailsScreen(it, controllers, "lottery-1") } + } + + /** Scrolls the lottery details list until [text] is shown. */ + private fun scrollTo(text: String) { + composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(text, substring = true)) + } + + @Test + fun ownerSeesEachEntrantOnTheWaitlist() { + openLottery(listOf(edsEntry, samsEntry)) + + scrollTo("Waitlist (2 / 10)") + scrollTo("Ed") + composeTestRule.onNodeWithText("Ed").assertIsDisplayed() + composeTestRule.onNodeWithText("In waitlist").assertIsDisplayed() + scrollTo("Sam") + composeTestRule.onNodeWithText("Won").assertIsDisplayed() + composeTestRule.onNode(hasText("2 guests", substring = true)).assertExists() + } + + @Test + fun emptyWaitlistSaysSo() { + openLottery(emptyList()) + + scrollTo("Nobody has joined this lottery yet.") + composeTestRule.onNodeWithText("Nobody has joined this lottery yet.").assertIsDisplayed() + } + + @Test + fun deletingTheLotteryAsksFirstThenGoesBack() { + openLottery(listOf(edsEntry)) + + scrollTo("Delete Lottery") + composeTestRule.onNodeWithText("Delete Lottery").performClick() + composeTestRule.onNodeWithText("Delete Lottery?").assertIsDisplayed() + composeTestRule.onNodeWithText("Delete").performClick() + composeTestRule.waitForIdle() + + coVerify { controllers.lotteries.deleteLottery(lottery) } + composeTestRule.onNodeWithText("Home screen").assertIsDisplayed() + } + + @Test + fun ownerSeesWhoHasBookedTheirCampsite() { + every { controllers.reservations.getReservationsForCampsite("site-1", any()) } returns listOf(edsStay) + open { ViewBookedDatesScreen(it, controllers, "site-1") } + + composeTestRule.onNodeWithText("Entrants who have booked:").performScrollTo().assertIsDisplayed() + composeTestRule.onNodeWithText("Ed").performScrollTo().assertIsDisplayed() + composeTestRule.onNodeWithText("3 people").assertExists() + } + + @Test + fun campsiteWithNoBookingsSaysSo() { + every { controllers.reservations.getReservationsForCampsite("site-1", any()) } returns emptyList() + open { ViewBookedDatesScreen(it, controllers, "site-1") } + + composeTestRule.onNodeWithText("Nobody has booked yet.").performScrollTo().assertIsDisplayed() + } + + @Test + fun ownerRejectsABooking() { + every { controllers.reservations.getReservationsForCampsite("site-1", any()) } returns listOf(edsStay) + open { ViewBookedDatesScreen(it, controllers, "site-1") } + + composeTestRule.onNodeWithTag("cancelReservationButton").performScrollTo().performClick() + composeTestRule.waitForIdle() + + coVerify { controllers.reservations.rejectReservation(edsStay) } + coVerify(atLeast = 2) { controllers.reservations.getReservationsForCampsite("site-1", ReservationFilter.ALL) } + } + + @Test + fun bookingWhoseGuestCannotBeFoundShowsUnknownGuest() { + coEvery { controllers.users.getUser("user-1") } throws IllegalStateException("offline") + every { controllers.reservations.getReservationsForCampsite("site-1", any()) } returns listOf(edsStay) + open { ViewBookedDatesScreen(it, controllers, "site-1") } + + composeTestRule.onNodeWithText("Unknown guest").performScrollTo().assertIsDisplayed() + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/OwnerLotteryScreensUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/OwnerLotteryScreensUITest.kt new file mode 100644 index 00000000..f59aa892 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/OwnerLotteryScreensUITest.kt @@ -0,0 +1,256 @@ +package com.example.lambda_bbb_events.ui.owner + +import androidx.compose.material3.Text +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.test.SemanticsNodeInteraction +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasClickAction +import androidx.compose.ui.test.hasSetTextAction +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollTo +import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.test.performTextReplacement +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.lottery.LotteryController +import com.example.lambda_bbb_events.model.campsite.Campsite +import com.example.lambda_bbb_events.model.lottery.Lottery +import com.example.lambda_bbb_events.model.lottery.LotteryStatus +import com.example.lambda_bbb_events.model.repository.LotteryRepository +import com.example.lambda_bbb_events.model.user.CampsiteOwner +import com.example.lambda_bbb_events.view.ui.owner_screens.CreateLotteryScreen +import com.example.lambda_bbb_events.view.ui.owner_screens.CreateMultipleCampsiteLotteryScreen +import com.example.lambda_bbb_events.view.ui.owner_screens.EditLotteryScreen +import com.example.lambda_bbb_events.view.ui.owner_screens.LotteryRequestsScreen +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.runs +import io.mockk.slot +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.time.LocalDate +import java.time.ZoneId +import java.util.Date + +/* + * UI tests for creating, editing and accepting lotteries (US 02.04.01 to 02.04.08). + * + * Outstanding issues: None known. + */ + +/** + * Tests the campsite owner's lottery screens: creating a lottery for one campsite or several, + * editing one, and accepting or declining a lottery other owners added their campsite to. + * + * A real [LotteryController] checks every form, so the same rules as in the app apply; only the + * database behind it is faked. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +@RunWith(AndroidJUnit4::class) +class OwnerLotteryScreensUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val controllers = mockk(relaxed = true) + private val repository = mockk(relaxed = true) + private val saved = slot() + + private val olive = CampsiteOwner(deviceId = "owner-1", name = "Olive") + private val pineLake = Campsite(campsiteId = "site-1", ownerId = "owner-1", campsiteName = "Pine Lake", active = true) + private val birchBay = Campsite(campsiteId = "site-2", ownerId = "owner-2", campsiteName = "Birch Bay", active = true) + + private val registrationStart = LocalDate.now().plusDays(1) + private val registrationEnd = LocalDate.now().plusDays(10) + private val bookingStart = LocalDate.now().plusDays(20) + private val bookingEnd = LocalDate.now().plusDays(25) + + @Before + fun setUp() { + every { controllers.lotteries } returns LotteryController(repository) + every { controllers.users.user } returns olive + every { controllers.campsites.getCampsite("site-1") } returns pineLake + every { controllers.campsites.getCampsite("site-2") } returns birchBay + every { controllers.campsites.campsites } returns mapOf("site-1" to pineLake, "site-2" to birchBay) + every { repository.getLotteriesForCampsite(any()) } returns emptyList() + coEvery { repository.addLottery(capture(saved)) } just runs + coEvery { repository.updateLottery(capture(saved)) } just runs + } + + /** Opens [screen] on top of a home screen, so going back after saving can be seen. */ + private fun open(screen: @androidx.compose.runtime.Composable (androidx.navigation.NavController) -> Unit) { + composeTestRule.setContent { + val navController = rememberNavController() + NavHost(navController, startDestination = "home") { + composable("home") { Text("Home screen") } + composable("screen") { screen(navController) } + } + LaunchedEffect(Unit) { navController.navigate("screen") } + } + composeTestRule.waitForIdle() + } + + /** The [index]th text field on the screen, scrolled into view. */ + private fun field(index: Int): SemanticsNodeInteraction = + composeTestRule.onAllNodes(hasSetTextAction())[index].performScrollTo() + + /** Types the four lottery dates, starting from the [first] text field. */ + private fun enterDates(first: Int = 0) { + listOf(registrationStart, registrationEnd, bookingStart, bookingEnd).forEachIndexed { i, date -> + field(first + i).performTextReplacement("") + field(first + i).performTextInput(date.toString().replace("-", "")) + } + } + + /** Taps the button or card labelled [label], scrolling to it first when the screen scrolls. */ + private fun tap(label: String) { + val node = composeTestRule.onNode(hasText(label) and hasClickAction()) + runCatching { node.performScrollTo() } + node.performClick() + composeTestRule.waitForIdle() + } + + /** Converts [date] to the start of that day, as lotteries store it. */ + private fun startOf(date: LocalDate): Date = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()) + + /** A lottery at Pine Lake run by Olive, with Birch Bay's owner [pending] if given. */ + private fun lottery(pending: List = emptyList()) = Lottery( + lotteryId = "lottery-1", + campsiteIds = listOf("site-1", "site-2"), + ownerIds = listOf("owner-2", "owner-1"), + pendingOwnerIds = pending, + registrationStart = startOf(registrationStart), + registrationEnd = startOf(registrationEnd), + bookingStart = startOf(bookingStart), + bookingEnd = startOf(bookingEnd), + numberOfWinners = 2 + ) + + @Test + fun ownerCreatesALotteryForTheirCampsite() { + open { CreateLotteryScreen(it, controllers, "site-1") } + + enterDates() + field(4).performTextReplacement("3") + field(5).performTextInput("20") + tap("Create lottery") + + composeTestRule.onNodeWithText("Home screen").assertIsDisplayed() + assertEquals(listOf("site-1"), saved.captured.campsiteIds) + assertEquals(listOf("owner-1"), saved.captured.ownerIds) + assertEquals(3, saved.captured.numberOfWinners) + assertEquals(20, saved.captured.waitlistCapacity) + assertEquals(startOf(registrationStart), saved.captured.registrationStart) + } + + @Test + fun missingDatesAreExplainedAndNothingIsSaved() { + open { CreateLotteryScreen(it, controllers, "site-1") } + + tap("Create lottery") + + composeTestRule.onNodeWithText("Please pick all four dates.").assertIsDisplayed() + coVerify(exactly = 0) { repository.addLottery(any()) } + } + + @Test + fun bookingMustStartAfterRegistrationEnds() { + open { CreateLotteryScreen(it, controllers, "site-1") } + enterDates() + + field(2).performTextReplacement("") + field(2).performTextInput(registrationStart.toString().replace("-", "")) + tap("Create lottery") + + composeTestRule.onNodeWithText("The booking period must start after the registration period ends.") + .assertIsDisplayed() + } + + @Test + fun waitlistMustHoldAtLeastTheWinners() { + open { CreateLotteryScreen(it, controllers, "site-1") } + enterDates() + + field(4).performTextReplacement("5") + field(5).performTextInput("2") + tap("Create lottery") + + composeTestRule.onNodeWithText("The waitlist capacity must be at least the number of winners.") + .assertIsDisplayed() + } + + @Test + fun ownerEditsTheNumberOfWinners() { + coEvery { repository.getLottery("lottery-1") } returns lottery() + open { EditLotteryScreen(it, controllers, "lottery-1") } + + field(4).performTextReplacement("4") + tap("Save changes") + + composeTestRule.onNodeWithText("Home screen").assertIsDisplayed() + assertEquals("lottery-1", saved.captured.lotteryId) + assertEquals(4, saved.captured.numberOfWinners) + } + + @Test + fun ownerSeesAndAcceptsALotteryRequest() { + var requests = listOf(lottery(pending = listOf("owner-1"))) + coEvery { repository.getLotteriesByOwner("owner-1") } answers { requests } + coEvery { repository.updateLottery(capture(saved)) } answers { requests = listOf(saved.captured) } + open { LotteryRequestsScreen(it, controllers) } + composeTestRule.onNode(hasText("Pine Lake", substring = true)).assertIsDisplayed() + composeTestRule.onNodeWithText("2 winners").assertIsDisplayed() + + tap("Accept") + + assertEquals(emptyList(), saved.captured.pendingOwnerIds) + composeTestRule.onNodeWithText("You don't currently have any lottery requests.").assertIsDisplayed() + } + + @Test + fun decliningALotteryRequestCancelsIt() { + var requests = listOf(lottery(pending = listOf("owner-1"))) + coEvery { repository.getLotteriesByOwner("owner-1") } answers { requests } + coEvery { repository.updateLottery(capture(saved)) } answers { requests = listOf(saved.captured) } + open { LotteryRequestsScreen(it, controllers) } + + tap("Decline") + + assertEquals(LotteryStatus.CANCELLED, saved.captured.status) + composeTestRule.onNodeWithText("You don't currently have any lottery requests.").assertIsDisplayed() + } + + @Test + fun ownerCreatesALotteryWithAnotherOwnersCampsite() { + open { CreateMultipleCampsiteLotteryScreen(it, controllers) } + + tap("Pine Lake") + tap("Select Other Peoples Campsites (optional)") + tap("Birch Bay") + enterDates() + tap("Create lottery") + + composeTestRule.onNodeWithText("Home screen").assertIsDisplayed() + assertEquals(setOf("site-1", "site-2"), saved.captured.campsiteIds.toSet()) + assertEquals(setOf("owner-1", "owner-2"), saved.captured.ownerIds.toSet()) + assertEquals(listOf("owner-2"), saved.captured.pendingOwnerIds) + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/SentMessagesSectionUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/SentMessagesSectionUITest.kt new file mode 100644 index 00000000..45124fb0 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/SentMessagesSectionUITest.kt @@ -0,0 +1,102 @@ +package com.example.lambda_bbb_events.ui.owner + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.view.ui.components.messaging.SentMessagesSection +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.flow +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests for the list of messages an owner sent to their waitlists (US 02.10.02). + * + * Outstanding issues: None known. + */ + +/** + * Tests that a campsite owner sees the messages they sent to their lotteries' waitlists, and + * that new ones appear without leaving the screen. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "As a campsite owner, I want to view a list of all notifications I have sent." + */ +@RunWith(AndroidJUnit4::class) +class SentMessagesSectionUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val gatesLog = AdminLog( + id = "log-1", + senderId = "owner-1", + recipientIds = listOf("user-1", "user-2"), + recipientNames = mapOf("user-1" to "Ed", "user-2" to "Sam"), + content = "Gates open at 9", + campsiteId = "site-1", + timestamp = 1_000L + ) + + /** + * Shows the section for [sentLogs]. + * + * @param sentLogs The owner's sent notifications. + */ + private fun showSection(sentLogs: Flow>) { + composeTestRule.setContent { SentMessagesSection(sentLogs = sentLogs) } + } + + @Test + fun showsEachSentMessageWithWhoItReached() { + showSection(MutableStateFlow(listOf(gatesLog))) + + composeTestRule.onNodeWithTag("text_sent_messages_title").assertTextEquals("Sent Messages (1)") + composeTestRule.onNodeWithText("Gates open at 9").assertIsDisplayed() + composeTestRule.onNodeWithText("Sent to Ed, Sam").assertIsDisplayed() + } + + @Test + fun countsRecipientsWhoseNamesWereNotSaved() { + showSection(MutableStateFlow(listOf(gatesLog.copy(recipientNames = emptyMap())))) + + composeTestRule.onNodeWithText("Sent to 2 entrants").assertIsDisplayed() + } + + @Test + fun newMessageAppearsWithoutReloading() { + val sent = MutableStateFlow(listOf(gatesLog)) + showSection(sent) + + sent.value = listOf(gatesLog.copy(id = "log-2", content = "Bring bug spray"), gatesLog) + + composeTestRule.onNodeWithTag("text_sent_messages_title").assertTextEquals("Sent Messages (2)") + composeTestRule.onNodeWithText("Bring bug spray").assertIsDisplayed() + } + + @Test + fun saysSoWhenNothingWasSent() { + showSection(MutableStateFlow(emptyList())) + + composeTestRule.onNodeWithTag("text_sent_messages_notice") + .assertTextEquals("You haven't messaged a waitlist for this campsite yet.") + } + + @Test + fun saysSoWhenLoadingFails() { + showSection(flow { throw IllegalStateException("offline") }) + + composeTestRule.onNodeWithTag("text_sent_messages_notice") + .assertTextEquals("Couldn't load your sent messages.") + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/WaitlistMessageButtonUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/WaitlistMessageButtonUITest.kt new file mode 100644 index 00000000..5e231249 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/owner/WaitlistMessageButtonUITest.kt @@ -0,0 +1,101 @@ +package com.example.lambda_bbb_events.ui.owner + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsEnabled +import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.junit4.v2.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTextInput +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.example.lambda_bbb_events.controller.messaging.GroupMessageResult +import com.example.lambda_bbb_events.controller.messaging.GroupMessageSender +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import com.example.lambda_bbb_events.model.lottery.WaitlistStatus +import com.example.lambda_bbb_events.view.ui.components.messaging.WaitlistMessageButton +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.mockk +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/* + * UI tests for an owner messaging their lottery's waitlist (US 02.10.01). + * + * Outstanding issues: None known. + */ + +/** + * Tests that a campsite owner can write one message and send it to their lottery's waitlist. + */ +@RunWith(AndroidJUnit4::class) +class WaitlistMessageButtonUITest { + + @get:Rule + val composeTestRule = createComposeRule() + + private val sender = mockk() + + private val waitlist = listOf( + WaitlistEntry(entryId = "entry-1", entrantId = "user-1", lotteryId = "lottery-1"), + WaitlistEntry(entryId = "entry-2", entrantId = "user-2", lotteryId = "lottery-1") + ) + + /** + * Shows the button for [entries]. + * + * @param entries The lottery's waitlist entries. + */ + private fun showButton(entries: List = waitlist) { + composeTestRule.setContent { + WaitlistMessageButton(entries = entries, sender = sender) + } + } + + @Test + fun disabledWhenNobodyCanBeMessaged() { + showButton(waitlist.map { it.copy(status = WaitlistStatus.LOST) }) + + composeTestRule.onNodeWithTag("button_message_waitlist").assertIsNotEnabled() + } + + @Test + fun dialogSaysHowManyEntrantsWillReceiveIt() { + showButton() + + composeTestRule.onNodeWithTag("button_message_waitlist").performClick() + + composeTestRule.onNodeWithText("Sent to 2 entrants in their chats with you.").assertIsDisplayed() + composeTestRule.onNodeWithTag("button_send_waitlist_message").assertIsNotEnabled() + } + + @Test + fun sendingMessagesTheWaitlistAndShowsTheResult() { + coEvery { sender.sendToWaitlist(waitlist, "Gates open at 9") } returns + GroupMessageResult(1, listOf("user-2")) + showButton() + + composeTestRule.onNodeWithTag("button_message_waitlist").performClick() + composeTestRule.onNodeWithTag("field_waitlist_message").performTextInput(" Gates open at 9 ") + composeTestRule.onNodeWithTag("button_send_waitlist_message").assertIsEnabled().performClick() + + composeTestRule.onNodeWithTag("text_waitlist_message_result") + .assertTextEquals("Sent to 1 of 2 entrants. 1 could not be reached.") + coVerify(exactly = 1) { sender.sendToWaitlist(waitlist, "Gates open at 9") } + } + + @Test + fun cancellingSendsNothing() { + showButton() + + composeTestRule.onNodeWithTag("button_message_waitlist").performClick() + composeTestRule.onNodeWithTag("field_waitlist_message").performTextInput("Never mind") + composeTestRule.onNodeWithText("Cancel").performClick() + + composeTestRule.onNodeWithTag("field_waitlist_message").assertDoesNotExist() + coVerify(exactly = 0) { sender.sendToWaitlist(any(), any()) } + } +} diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/review/ReviewSectionUITest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/review/ReviewSectionUITest.kt index ba89dc55..6efcb099 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/review/ReviewSectionUITest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/review/ReviewSectionUITest.kt @@ -26,9 +26,9 @@ import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performTextReplacement import androidx.test.ext.junit.runners.AndroidJUnit4 import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.ReviewController -import com.example.lambda_bbb_events.controller.ReviewReactionController -import com.example.lambda_bbb_events.controller.ReviewReplyController +import com.example.lambda_bbb_events.controller.review.ReviewController +import com.example.lambda_bbb_events.controller.review.ReviewReactionController +import com.example.lambda_bbb_events.controller.review.ReviewReplyController import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.model.repository.ReviewReactionRepository import com.example.lambda_bbb_events.model.repository.ReviewReplyRepository @@ -56,6 +56,12 @@ import org.junit.runner.RunWith import java.util.Date import kotlin.math.abs +/* + * UI tests for writing, editing, deleting and reacting to reviews (US 01.13.01, 01.13.02). + * + * Outstanding issues: None known. + */ + /** * Tests reading, writing, editing, and deleting reviews on a campsite's page. The repository is * replaced with one that keeps reviews in memory, so nothing is written to the database. diff --git a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/RemoteChangesTest.kt b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/sync/RemoteChangesTest.kt similarity index 91% rename from code/app/src/androidTest/java/com/example/lambda_bbb_events/data/RemoteChangesTest.kt rename to code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/sync/RemoteChangesTest.kt index 8067e0df..09b17b21 100644 --- a/code/app/src/androidTest/java/com/example/lambda_bbb_events/data/RemoteChangesTest.kt +++ b/code/app/src/androidTest/java/com/example/lambda_bbb_events/ui/sync/RemoteChangesTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.data +package com.example.lambda_bbb_events.ui.sync import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.hasTestTag @@ -7,7 +7,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import com.example.lambda_bbb_events.LambdaEventsApp import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.UserController +import com.example.lambda_bbb_events.controller.user.UserController import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.model.repository.CampsiteRepository import com.example.lambda_bbb_events.model.repository.UserRepository @@ -27,6 +27,14 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import com.example.lambda_bbb_events.support.FirestoreTestData + +/* + * Tests that the open app follows changes made elsewhere in the real Firestore database. + * + * Outstanding issues: Needs a network connection and the published Firestore rules. A test that + * stops before reading its data back can leave a "test-" document behind. + */ /** * Tests that the open app follows changes made by someone else in the real Firestore database. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt b/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt index 4a4f9b7a..557e989d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/LambdaEventsApp.kt @@ -61,7 +61,6 @@ import com.example.lambda_bbb_events.view.ui.user_screens.profile.Theme_Toggle import com.example.lambda_bbb_events.view.ui.user_screens.signup.LoginScreen import com.example.lambda_bbb_events.view.ui.user_screens.signup.RuleConfirmScreen import com.example.lambda_bbb_events.view.ui.user_screens.signup.SignupScreen -import com.example.lambda_bbb_events.view.ui.user_screens.signup.Test_screen import com.example.lambda_bbb_events.view.ui.user_screens.signup.WelcomeScreen import androidx.compose.runtime.remember import java.time.LocalDate @@ -87,6 +86,8 @@ import com.example.lambda_bbb_events.view.ui.user_screens.explore.SeeAllCampsite * campsite browsing, reservations, lotteries, and profiles. * * layout issues on smaller screens could be an issue. + * + * Outstanding issues: None known. */ /** @@ -480,7 +481,6 @@ private fun MainApp( composable("profile") { ProfileScreen(navController, controllers) } composable("edit_profile") { EditProfileScreen(navController, controllers) } composable("settings") { Settings(navController, controllers) } - composable("test_nav"){ Test_screen(navController, controllers) } composable("theme_toggle"){ Theme_Toggle( navController, controllers, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt b/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt index 9d94bbd7..85fec33d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/MainActivity.kt @@ -21,15 +21,17 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope +import com.example.lambda_bbb_events.controller.admin.AdminLogController import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.CampsiteController -import com.example.lambda_bbb_events.controller.LotteryController -import com.example.lambda_bbb_events.controller.ReservationController -import com.example.lambda_bbb_events.controller.ReviewController -import com.example.lambda_bbb_events.controller.UserController -import com.example.lambda_bbb_events.controller.WaitlistEntryController -import com.example.lambda_bbb_events.controller.NotificationController +import com.example.lambda_bbb_events.controller.campsite.CampsiteController +import com.example.lambda_bbb_events.controller.lottery.LotteryController +import com.example.lambda_bbb_events.controller.reservation.ReservationController +import com.example.lambda_bbb_events.controller.review.ReviewController +import com.example.lambda_bbb_events.controller.user.UserController +import com.example.lambda_bbb_events.controller.lottery.WaitlistEntryController +import com.example.lambda_bbb_events.controller.notification.NotificationController import com.example.lambda_bbb_events.model.local.LocalDatabase +import com.example.lambda_bbb_events.model.local.SqliteNotificationLogStore import com.example.lambda_bbb_events.model.local.SharedPreferencesSessionStore import com.example.lambda_bbb_events.model.local.SqliteRecentlyViewedStore import com.example.lambda_bbb_events.model.local.SqliteThemePreferenceStore @@ -61,6 +63,8 @@ import kotlinx.coroutines.delay * Defines the application's main Android activity. * Initializes repositories and controllers, retrieves * the device identifier, and launches the Compose UI. + * + * Outstanding issues: None known. */ /** @@ -158,7 +162,8 @@ class MainActivity : ComponentActivity() { places = FallbackPlaceSearch( google = GooglePlaceSearch(app = AndroidAppIdentity.of(applicationContext)) ), - notifications = notifications + notifications = notifications, + adminLogs = AdminLogController(logStore = SqliteNotificationLogStore(localDatabase)) ) syncController = controllers diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/AppControllers.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/AppControllers.kt index ddb72a65..f895de04 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/AppControllers.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/AppControllers.kt @@ -3,6 +3,26 @@ package com.example.lambda_bbb_events.controller import com.example.lambda_bbb_events.model.services.FallbackPlaceSearch import com.example.lambda_bbb_events.model.services.ImageProcessor import com.example.lambda_bbb_events.model.services.PlaceSearch +import com.example.lambda_bbb_events.controller.admin.AdminLogController +import com.example.lambda_bbb_events.controller.admin.AdminLotteryController +import com.example.lambda_bbb_events.controller.campsite.CampsiteController +import com.example.lambda_bbb_events.controller.lottery.LotteryController +import com.example.lambda_bbb_events.controller.lottery.WaitlistEntryController +import com.example.lambda_bbb_events.controller.messaging.MessageController +import com.example.lambda_bbb_events.controller.notification.MessageNotificationController +import com.example.lambda_bbb_events.controller.notification.NotificationController +import com.example.lambda_bbb_events.controller.notification.NotificationPreferenceController +import com.example.lambda_bbb_events.controller.reservation.ReservationController +import com.example.lambda_bbb_events.controller.review.ReviewController +import com.example.lambda_bbb_events.controller.review.ReviewReactionController +import com.example.lambda_bbb_events.controller.review.ReviewReplyController +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Holds every controller the app uses, so screens receive them as one object. + * + * Outstanding issues: None known. + */ /** * Groups the application's controllers into a single container. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/AdminLogController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/AdminLogController.kt similarity index 59% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/AdminLogController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/AdminLogController.kt index 31fda6b6..050dd58e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/AdminLogController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/AdminLogController.kt @@ -1,8 +1,25 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.admin import com.example.lambda_bbb_events.model.admin.AdminLog import com.example.lambda_bbb_events.model.admin.LogType +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.setValue +import com.example.lambda_bbb_events.model.local.InMemoryNotificationLogStore +import com.example.lambda_bbb_events.model.local.NotificationLogStore import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.withContext + +/* + * Controller for the admin logs screen: keeps the local copy of the notification logs in sync, + * pages and searches it, and loads message logs. + * + * Outstanding issues: Message logs are not paged; every conversation and message is read at + * once. + */ /** * Controller responsible for managing notification and message @@ -12,23 +29,49 @@ import com.example.lambda_bbb_events.model.repository.AdminLogRepository * resolves user and campsite identifiers into display names, * and supports filtering logs based on a search query. * + * Notification logs are read from a local copy kept in sync with the database, so paging and + * searching them needs no database reads. + * * @property repository The repository used to retrieve admin logs. + * @property logStore The local copy of the notification logs. + * @property ioDispatcher Where disk work runs. */ class AdminLogController( private val repository: AdminLogRepository = - AdminLogRepository() + AdminLogRepository(), + private val logStore: NotificationLogStore = InMemoryNotificationLogStore(), + private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO ) { + /** Splits the local notification logs into numbered pages. */ + val notificationPages = LogPager(logStore) + + /** Goes up by one each time new notification logs reach the local copy. */ + var syncedCount by mutableIntStateOf(0) + private set + /** - * Retrieves all notification logs. - * - * @return A list of notification logs sorted by timestamp - * in descending order. + * Copies new and changed notification logs into the local copy for as long as the caller + * keeps running it, starting from the newest log already saved. */ - suspend fun getNotificationLogs(): List { - return repository.getNotificationLogs() + suspend fun syncNotificationLogs() { + val since = withContext(ioDispatcher) { logStore.newestTimestamp() } + repository.observeNotificationLogsSince(since).collect { logs -> + withContext(ioDispatcher) { logStore.upsert(logs) } + syncedCount++ + } } + /** + * Observes the notifications an owner sent about one of their campsites, newest first. + * + * @param ownerId Device ID of the owner. + * @param campsiteId The campsite they were about. + * @return The owner's sent notifications, each time one is added. + */ + fun observeSentBy(ownerId: String, campsiteId: String): Flow> = + repository.observeLogsSentBy(ownerId, campsiteId) + /** * Retrieves all owner-to-entrant message logs. * @@ -40,14 +83,17 @@ class AdminLogController( } /** - * Retrieves logs based on the specified log type. + * Retrieves logs of the specified type. Notification logs are the current page of + * [notificationPages] matching [query], searched across every saved log; message logs + * are all loaded and [query] is ignored, so filter them with [searchLogs]. * * @param type The type of logs to retrieve. - * @return A list of logs matching the specified type. + * @param query Text to search notification logs for; blank matches all. + * @return The logs, newest first. */ - suspend fun getLogs(type: LogType): List { + suspend fun getLogs(type: LogType, query: String = ""): List { return when (type) { - LogType.NOTIFICATION -> getNotificationLogs() + LogType.NOTIFICATION -> withContext(ioDispatcher) { notificationPages.load(query) } LogType.MESSAGE -> getMessageLogs() } } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/AdminLotteryController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/AdminLotteryController.kt similarity index 91% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/AdminLotteryController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/AdminLotteryController.kt index aa6afa6f..9481fd34 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/AdminLotteryController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/AdminLotteryController.kt @@ -1,9 +1,15 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.admin import com.google.firebase.functions.FirebaseFunctions import com.google.firebase.functions.FirebaseFunctionsException import kotlinx.coroutines.tasks.await +/* + * Controller for admin-only lottery actions, which run in Firebase Cloud Functions. + * + * Outstanding issues: None known. + */ + /** * Handles admin-only lottery actions backed by Firebase Cloud Functions. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/LogPager.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/LogPager.kt new file mode 100644 index 00000000..17b8b856 --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/admin/LogPager.kt @@ -0,0 +1,90 @@ +package com.example.lambda_bbb_events.controller.admin + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.local.NotificationLogStore + +/* + * Splits the local copy of the notification logs into numbered pages for the admin logs screen. + * + * Outstanding issues: None known. + */ + +/** + * Splits the local copy of the notification logs into numbered pages, newest first, so only + * one page is shown at a time however many logs there are. + * + * @param store The local copy of the logs. + * @param pageSize How many logs a page holds. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Because my worry is overwhelming the device with like 10000 logs." + * - "I realized we have a sqlite db and instead we could just sync to local copy and update + * the sqlite3 db." + */ +class LogPager( + private val store: NotificationLogStore, + private val pageSize: Int = DEFAULT_PAGE_SIZE +) { + /** The page being shown, counting from 0. */ + var pageIndex by mutableIntStateOf(0) + private set + + /** Whether there is a page after the one being shown. */ + var hasNext by mutableStateOf(false) + private set + + /** Whether there is a page before the one being shown. */ + val hasPrevious: Boolean + get() = pageIndex > 0 + + /** + * Loads the current page of logs matching [query]. If the logs no longer reach this page, + * for example after a narrower search, the last page that has logs is loaded instead. + * Reads the disk, so call it off the main thread. + * + * @param query Text to search for; blank matches every log. + * @return The page's logs, newest first. + */ + fun load(query: String): List { + val total = store.count(query) + pageIndex = pageIndex.coerceAtMost(lastPageIndex(total)) + hasNext = (pageIndex + 1) * pageSize < total + return store.page(query, pageIndex * pageSize, pageSize) + } + + /** Moves to the next page, if there is one. */ + fun next() { + if (hasNext) pageIndex++ + } + + /** Moves to the previous page, if there is one. */ + fun previous() { + if (hasPrevious) pageIndex-- + } + + /** Goes back to the first page. */ + fun reset() { + pageIndex = 0 + } + + /** + * The index of the last page that holds any of [total] logs. + * + * @param total How many logs there are. + * @return The index, 0 when there are none. + */ + private fun lastPageIndex(total: Int): Int = maxOf(0, (total - 1) / pageSize) + + companion object { + /** How many logs a page holds unless told otherwise. */ + const val DEFAULT_PAGE_SIZE = 20 + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/CampsiteController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/campsite/CampsiteController.kt similarity index 98% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/CampsiteController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/campsite/CampsiteController.kt index 4d757588..4c60e212 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/CampsiteController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/campsite/CampsiteController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.campsite import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.campsite.isAvailableThroughLottery @@ -19,6 +19,13 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import java.time.LocalDate +/* + * Controller for campsites: creating and editing them, searching and filtering, and recently + * viewed campsites. + * + * Outstanding issues: None known. + */ + /** * Handles campsite operations, searching, filtering, and recently viewed campsites. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/CampsitePhotoController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/campsite/CampsitePhotoController.kt similarity index 96% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/CampsitePhotoController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/campsite/CampsitePhotoController.kt index 0b13f3aa..064c392d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/CampsitePhotoController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/campsite/CampsitePhotoController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.campsite import android.graphics.Bitmap import com.example.lambda_bbb_events.model.image.ImageMetaData @@ -8,6 +8,12 @@ import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.withContext import java.util.UUID +/* + * Controller for changing the photos of an existing campsite. + * + * Outstanding issues: None known. + */ + /** * Changes the photos of campsites that already exist. Every change is saved straight away. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/LotteryController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/lottery/LotteryController.kt similarity index 99% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/LotteryController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/lottery/LotteryController.kt index 3b61660e..237a661e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/LotteryController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/lottery/LotteryController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.lottery import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.lottery.LotteryStatus @@ -12,6 +12,8 @@ import java.util.UUID /* * Manages lottery operations and filtering through the repository pattern. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/WaitlistEntryController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/lottery/WaitlistEntryController.kt similarity index 96% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/WaitlistEntryController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/lottery/WaitlistEntryController.kt index 7915000b..727a169a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/WaitlistEntryController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/lottery/WaitlistEntryController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.lottery import com.example.lambda_bbb_events.model.lottery.WaitlistEntry import com.example.lambda_bbb_events.model.lottery.WaitlistStatus @@ -9,6 +9,12 @@ import com.example.lambda_bbb_events.model.repository.MessagingAccessRepository import com.example.lambda_bbb_events.model.repository.ReservationRepository import java.util.Date +/* + * Controller for lottery waitlist entries: joining, leaving and checking their status. + * + * Outstanding issues: None known. + */ + /** * Controller for [WaitlistEntry]-related operations. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/messaging/GroupMessageSender.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/messaging/GroupMessageSender.kt new file mode 100644 index 00000000..44e7247d --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/messaging/GroupMessageSender.kt @@ -0,0 +1,191 @@ +package com.example.lambda_bbb_events.controller.messaging + +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import com.example.lambda_bbb_events.model.lottery.WaitlistStatus +import com.example.lambda_bbb_events.model.message.ConversationType +import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import com.example.lambda_bbb_events.model.repository.ConversationRepository +import com.example.lambda_bbb_events.model.repository.MessageRepository +import kotlin.coroutines.cancellation.CancellationException +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Sends one message from a campsite owner to everyone on a lottery's waitlist, and logs the + * send for admins. + * + * Outstanding issues: If writing the admin log fails, the messages still go out but that send + * is missing from the logs. + */ + +/** + * The outcome of sending one message to a group of entrants. + * + * @property sentCount How many entrants received the message. + * @property failedEntrantIds Device IDs of the entrants it could not be sent to, such as those + * whose messaging access to the owner has ended. + */ +data class GroupMessageResult( + val sentCount: Int, + val failedEntrantIds: List +) { + /** + * A short summary for the owner, such as "Sent to 4 of 5 entrants. 1 could not be reached." + * + * @return The summary text. + */ + fun summary(): String { + val total = sentCount + failedEntrantIds.size + if (failedEntrantIds.isEmpty()) return "Sent to ${entrants(total)}." + return "Sent to $sentCount of ${entrants(total)}. " + + "${failedEntrantIds.size} could not be reached." + } + + /** + * Writes [count] with the right form of "entrant". + * + * @param count The number of entrants. + * @return For example "1 entrant" or "3 entrants". + */ + private fun entrants(count: Int): String = + if (count == 1) "1 entrant" else "$count entrants" +} + +/** + * Lets a campsite owner send one message to everyone on a lottery's waitlist. + * + * This is group messaging, not a group chat: the message is posted into each entrant's own + * conversation with the owner, so replies stay private and each entrant's notification + * settings, mutes and opt-out still apply. + * + * Each send is logged once for admins to review, listing only the entrants it reached. + * + * @param userController Identifies the signed-in owner. + * @param conversationRepository Finds or creates each entrant's conversation with the owner. + * @param logs Records each send for admins. + * @param messagesIn Gives the message repository for a conversation ID. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "As a campsite owner, I want to send notifications to entrants who have joined the + * waitlist for my campsite lottery." + * - "That's what I was thinking make group chats possible. technically it doesn't need to be + * a group chat but a group messaging system." + */ +class GroupMessageSender( + private val userController: UserController, + private val conversationRepository: ConversationRepository = ConversationRepository(), + private val logs: AdminLogRepository = AdminLogRepository(), + private val messagesIn: (String) -> MessageRepository = { MessageRepository(it) } +) { + + /** + * Sends [content] from the signed-in owner to every entrant in [entries] who can still + * message them, then logs the send. Each entrant is messaged once even if they have + * several entries, and one failure does not stop the rest. + * + * @param entries The lottery's waitlist entries. + * @param content The message text. + * @param campsiteId The campsite the lottery is for, recorded in the log. + * @param campsiteName That campsite's name, recorded in the log. + * @return How many entrants were messaged and which could not be. + * @throws IllegalArgumentException If [content] is blank. + */ + suspend fun sendToWaitlist( + entries: List, + content: String, + campsiteId: String = "", + campsiteName: String = "" + ): GroupMessageResult { + require(content.isNotBlank()) { "Message cannot be empty" } + + val owner = userController.user + val recipients = recipientsOf(entries) + val failed = recipients.filterNot { entrantId -> trySend(owner.deviceId, entrantId, content) } + val reached = recipients - failed.toSet() + if (reached.isNotEmpty()) { + tryLog(owner.deviceId, owner.name, reached, content, campsiteId, campsiteName) + } + return GroupMessageResult(reached.size, failed) + } + + /** + * Logs a send for admins. A failure is ignored, since the messages have already gone out. + * + * @param ownerId Device ID of the owner who sent it. + * @param ownerName The owner's name. + * @param reached Device IDs of the entrants it reached. + * @param content The message text. + * @param campsiteId The campsite it was about. + * @param campsiteName That campsite's name. + */ + private suspend fun tryLog( + ownerId: String, + ownerName: String, + reached: List, + content: String, + campsiteId: String, + campsiteName: String + ) { + try { + logs.logNotification( + title = LOG_TITLE, + senderId = ownerId, + senderName = ownerName, + recipientIds = reached, + content = content.trim(), + recipientNames = reached.associateWith { userController.getUserName(it) }, + campsiteId = campsiteId, + campsiteName = campsiteName + ) + } catch (cancelled: CancellationException) { + throw cancelled + } catch (_: Exception) { + return + } + } + + /** + * Sends [content] into the conversation between [ownerId] and [entrantId]. + * + * @return `true` if the message was sent, `false` if it could not be. + */ + private suspend fun trySend(ownerId: String, entrantId: String, content: String): Boolean = + try { + val conversationId = conversationRepository.createConversation( + contactId = ownerId, + type = ConversationType.OWNER, + userId = entrantId + ) + messagesIn(conversationId).sendMessage(content, ownerId) + true + } catch (cancelled: CancellationException) { + throw cancelled + } catch (_: Exception) { + false + } + + companion object { + /** The title of the log written for each send. */ + const val LOG_TITLE = "Message to lottery waitlist" + + /** + * Entry statuses whose entrants can still message the owner, matching the messaging + * access check in [MessageRepository]. + */ + val MESSAGEABLE_STATUSES = setOf(WaitlistStatus.IN_WAITLIST, WaitlistStatus.WON) + + /** + * The distinct entrants in [entries] who can still be messaged. + * + * @param entries Waitlist entries to choose from. + * @return Their device IDs, in waitlist order. + */ + fun recipientsOf(entries: List): List = + entries.filter { it.status in MESSAGEABLE_STATUSES } + .map { it.entrantId } + .distinct() + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/MessageController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/messaging/MessageController.kt similarity index 98% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/MessageController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/messaging/MessageController.kt index 16ee323a..3bcb4fe8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/MessageController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/messaging/MessageController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.messaging import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -10,6 +10,13 @@ import com.example.lambda_bbb_events.model.repository.MessageRepository import com.example.lambda_bbb_events.model.repository.ConversationRepository import com.example.lambda_bbb_events.model.user.UserRole import kotlinx.coroutines.flow.Flow +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Controller for chat messaging between campers, campsite owners and admins. + * + * Outstanding issues: None known. + */ /** * Controls messaging operations between the user interface diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/MessageNotificationController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/MessageNotificationController.kt similarity index 95% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/MessageNotificationController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/MessageNotificationController.kt index 808b0f17..9e76cc78 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/MessageNotificationController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/MessageNotificationController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.notification import android.Manifest import android.app.NotificationChannel @@ -16,6 +16,14 @@ import com.example.lambda_bbb_events.R import com.example.lambda_bbb_events.model.message.Conversation import com.example.lambda_bbb_events.model.message.Message import com.example.lambda_bbb_events.model.repository.NotificationPreferenceRepository +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Shows Android notifications for incoming chat messages, respecting each user's mutes and + * opt-out. + * + * Outstanding issues: None known. + */ /** * Manages Android notifications for incoming chat messages. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/NotificationController.kt similarity index 97% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/NotificationController.kt index fbecf5aa..4d9546b3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/NotificationController.kt @@ -1,8 +1,10 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.notification /* * builds notifications and verifies if app and user preference both have notification enabled + * + * Outstanding issues: None known. */ import android.app.PendingIntent @@ -20,6 +22,7 @@ import java.util.UUID import com.example.lambda_bbb_events.model.local.NotificationCategoryStore import com.example.lambda_bbb_events.model.notifications.NotificationCategory import com.example.lambda_bbb_events.model.notifications.NotificationMode +import com.example.lambda_bbb_events.controller.user.UserController /** * Builds notification and delivery as wel as preferences and history @@ -37,6 +40,10 @@ class NotificationController( private val historyStore = NotificationHistoryStore(context) private val categoryStore = NotificationCategoryStore(context) + fun logMessage() { + + } + /** * Creates the notification channel and calls at app startup. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationPreferenceController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceController.kt similarity index 92% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationPreferenceController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceController.kt index 8e1d5092..3325ff71 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/NotificationPreferenceController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceController.kt @@ -1,10 +1,17 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.notification import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import com.example.lambda_bbb_events.model.message.NotificationPreference import com.example.lambda_bbb_events.model.repository.NotificationPreferenceRepository +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Controller for muting and unmuting notifications from individual contacts. + * + * Outstanding issues: None known. + */ /** * Controls notification preferences for the current user. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReservationController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/reservation/ReservationController.kt similarity index 97% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/ReservationController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/reservation/ReservationController.kt index 0daacd7e..2bb1ac0b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReservationController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/reservation/ReservationController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.reservation import com.example.lambda_bbb_events.model.formatting.parseDateOrNull import com.example.lambda_bbb_events.model.reservation.Reservation @@ -6,6 +6,12 @@ import com.example.lambda_bbb_events.model.reservation.ReservationStatus import com.example.lambda_bbb_events.model.repository.ReservationRepository import java.time.LocalDate +/* + * Controller for reservations: listing, filtering, confirming, cancelling and rejecting them. + * + * Outstanding issues: None known. + */ + /** * The groups for the owner reservations view. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewController.kt similarity index 96% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewController.kt index 832d7917..f2b243d6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.review import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.model.repository.ReviewRepository @@ -6,6 +6,12 @@ import com.example.lambda_bbb_events.model.review.Review import com.example.lambda_bbb_events.model.user.User import com.example.lambda_bbb_events.model.user.UserRole +/* + * Controller for reading, writing and deleting campsite reviews. + * + * Outstanding issues: None known. + */ + /** * Controller for reading, writing, and deleting campsite reviews. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewReactionController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewReactionController.kt similarity index 96% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewReactionController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewReactionController.kt index 2073518d..51d5f28c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewReactionController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewReactionController.kt @@ -1,10 +1,16 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.review import com.example.lambda_bbb_events.model.repository.ReviewReactionRepository import com.example.lambda_bbb_events.model.review.Review import com.example.lambda_bbb_events.model.review.ReviewReaction import com.example.lambda_bbb_events.model.user.User +/* + * Controller for emoji reactions to campsite reviews. + * + * Outstanding issues: None known. + */ + /** * Controller for the emoji reactions to campsite reviews. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewReplyController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewReplyController.kt similarity index 95% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewReplyController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewReplyController.kt index f54a5773..e7723277 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/ReviewReplyController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/review/ReviewReplyController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.review import com.example.lambda_bbb_events.model.repository.ReviewReplyRepository import com.example.lambda_bbb_events.model.review.Review @@ -6,6 +6,12 @@ import com.example.lambda_bbb_events.model.review.ReviewReply import com.example.lambda_bbb_events.model.user.User import com.example.lambda_bbb_events.model.user.UserRole +/* + * Controller for replies under campsite reviews. + * + * Outstanding issues: None known. + */ + /** * Controller for the replies under campsite reviews. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/controller/UserController.kt b/code/app/src/main/java/com/example/lambda_bbb_events/controller/user/UserController.kt similarity index 98% rename from code/app/src/main/java/com/example/lambda_bbb_events/controller/UserController.kt rename to code/app/src/main/java/com/example/lambda_bbb_events/controller/user/UserController.kt index 5869cc95..7df8fb70 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/controller/UserController.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/controller/user/UserController.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.user import android.util.Patterns import androidx.compose.runtime.getValue @@ -13,11 +13,15 @@ import com.example.lambda_bbb_events.model.repository.WrongAdminPasswordExceptio import com.example.lambda_bbb_events.model.user.CampsiteOwner import com.example.lambda_bbb_events.model.user.Entrant import com.example.lambda_bbb_events.model.user.UserRole +import com.example.lambda_bbb_events.controller.campsite.CampsiteController +import com.example.lambda_bbb_events.controller.lottery.LotteryController /* * Manages user profiles, roles, and notification settings * through the repository. * + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/admin/AdminLog.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/admin/AdminLog.kt index 491e132c..67856e77 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/admin/AdminLog.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/admin/AdminLog.kt @@ -1,5 +1,15 @@ package com.example.lambda_bbb_events.model.admin +import com.google.firebase.Firebase +import com.google.firebase.firestore.firestore + +/* + * Model of a notification or message log that admins review. + * + * Outstanding issues: Sender and recipient names are saved when a notification is sent, so a + * later name change is not reflected in searches. + */ + /** * Represents the types of logs available to an administrator. */ @@ -76,4 +86,11 @@ data class AdminLog( get() = campsiteName.ifBlank { "Unknown campsite" } + + /** + * Downloads all notification info in selectable amounts. + */ + + suspend fun downloadNotifications(offsetAmount: Int) { + } } \ No newline at end of file diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/AvailabilitySchedule.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/AvailabilitySchedule.kt index f970dd56..848ac681 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/AvailabilitySchedule.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/AvailabilitySchedule.kt @@ -4,6 +4,8 @@ import java.time.LocalDate /* * Tracks campsite availability and manages bookings across date ranges. + * + * Outstanding issues: None known. */ /** Tracks campsite availability by date alongside the date ranges of current bookings. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/Campsite.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/Campsite.kt index 58423874..b63e0352 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/Campsite.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/Campsite.kt @@ -4,6 +4,8 @@ import com.example.lambda_bbb_events.model.image.ImageMetaData /* * Defines campsite information to represent a listing for campsite + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteFilters.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteFilters.kt index 935df3db..ed2417d5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteFilters.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteFilters.kt @@ -9,6 +9,8 @@ import java.util.Date /* * Defines filters for browsing campsites and checks campsite availability * through lotteries. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteStore.kt index 50027029..ad2cdc0d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/CampsiteStore.kt @@ -11,6 +11,12 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import kotlin.coroutines.cancellation.CancellationException +/* + * Keeps the observable cache of campsites and saves changes through the repositories. + * + * Outstanding issues: None known. + */ + /** * Maintains the observable campsite cache and coordinates persistence with the repositories. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/SearchArea.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/SearchArea.kt index 4704a230..98095a83 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/SearchArea.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/campsite/SearchArea.kt @@ -9,6 +9,8 @@ import kotlin.math.sqrt /* * Describes a circle on the map that campsites can be filtered by. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/DateParsing.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/DateParsing.kt index de575218..929bf417 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/DateParsing.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/DateParsing.kt @@ -5,6 +5,8 @@ import java.time.format.DateTimeParseException /* * Provides date parsing text into LocalDate values. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/PhoneNumber.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/PhoneNumber.kt index ebae6c50..2107db7c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/PhoneNumber.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/formatting/PhoneNumber.kt @@ -5,6 +5,8 @@ import java.util.Locale /* * Defines country calling codes and how phone numbers are stored. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/image/Image.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/image/Image.kt index ff6700ba..569e3fd4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/image/Image.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/image/Image.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.image /* * Stores image metadata and URLs for user-uploaded images. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt index 69ac0743..a181ef3b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationCategoryStore.kt @@ -5,6 +5,12 @@ import com.example.lambda_bbb_events.model.notifications.NotificationCategory import com.example.lambda_bbb_events.model.notifications.NotificationMode import java.util.concurrent.TimeUnit +/* + * Saves each user's notification category settings on the device. + * + * Outstanding issues: None known. + */ + /** * Stores notification category preferences for each user. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt index f5afb5e3..5c377a50 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationHistoryStore.kt @@ -8,6 +8,12 @@ import android.content.SharedPreferences import org.json.JSONArray import org.json.JSONObject +/* + * Saves each user's notification history on the device. + * + * Outstanding issues: None known. + */ + /** * Stores notification history locally for each user. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationLogStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationLogStore.kt new file mode 100644 index 00000000..091d1866 --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/NotificationLogStore.kt @@ -0,0 +1,264 @@ +package com.example.lambda_bbb_events.model.local + +import android.content.ContentValues +import android.database.Cursor +import android.database.sqlite.SQLiteDatabase +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.admin.LogType +import org.json.JSONArray +import org.json.JSONObject + +/* + * The device's local copy of the notification logs, in SQLite, so admins can page and search + * them without database reads. + * + * Outstanding issues: Searches match names as they were when each notification was sent. + */ + +/** + * A local copy of the notification logs admins review. Paging and searching it needs no + * database reads, however many logs there are. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Can you get things to start logging. Non delivered ones shouldn't be logged only ones that + * the admins need to know to enforce app policies. Another thing is I realized we have a + * sqlite db and instead we could just sync to local copy and update the sqlite3 db." + */ +interface NotificationLogStore { + /** + * Saves [logs], replacing any saved log with the same ID. + * + * @param logs The logs to save. + */ + fun upsert(logs: List) + + /** + * The newest saved log's timestamp, so syncing can continue from there. + * + * @return The timestamp in milliseconds, or 0 if nothing is saved. + */ + fun newestTimestamp(): Long + + /** + * Loads one page of the logs matching [query], newest first. + * + * @param query Text to look for in a log's title, content, IDs and names; blank matches all. + * @param offset How many matching logs to skip. + * @param limit The most logs to load. + * @return The page's logs. + */ + fun page(query: String, offset: Int, limit: Int): List + + /** + * Counts the logs matching [query]. + * + * @param query Text to look for, as in [page]. + * @return How many logs match. + */ + fun count(query: String): Int +} + +/** + * Keeps notification logs in memory only. Used in tests, where no database is available. + */ +class InMemoryNotificationLogStore : NotificationLogStore { + /** The saved logs, by ID. */ + private val logs = mutableMapOf() + + override fun upsert(logs: List) { + logs.forEach { this.logs[it.id] = it } + } + + override fun newestTimestamp(): Long = logs.values.maxOfOrNull { it.timestamp } ?: 0L + + override fun page(query: String, offset: Int, limit: Int): List = + matching(query).drop(offset).take(limit) + + override fun count(query: String): Int = matching(query).size + + /** + * The saved logs matching [query], newest first. + * + * @param query Text to look for; blank matches all. + * @return The matching logs. + */ + private fun matching(query: String): List { + val text = query.trim() + return logs.values + .filter { log -> text.isEmpty() || searchableText(log).any { it.contains(text, ignoreCase = true) } } + .sortedByDescending { it.timestamp } + } + + /** + * The parts of [log] a search looks in, matching the columns [SqliteNotificationLogStore] + * searches. + * + * @param log The log. + * @return Its searchable text. + */ + private fun searchableText(log: AdminLog): List = + listOf(log.title, log.content, log.senderId, log.senderName, log.campsiteId, log.campsiteName) + + log.recipientIds + log.recipientNames.values +} + +/** + * Stores notification logs in the [LocalDatabase]. + * + * Calls read and write the disk, so they should be made off the main thread. + * + * @property database The local database holding the logs. + */ +class SqliteNotificationLogStore( + private val database: LocalDatabase +) : NotificationLogStore { + + override fun upsert(logs: List) { + val db = database.writableDatabase + db.beginTransaction() + try { + logs.forEach { log -> + db.insertWithOnConflict(TABLE, null, valuesOf(log), SQLiteDatabase.CONFLICT_REPLACE) + } + db.setTransactionSuccessful() + } finally { + db.endTransaction() + } + } + + override fun newestTimestamp(): Long = + database.readableDatabase.rawQuery("SELECT MAX($TIMESTAMP) FROM $TABLE", null).use { cursor -> + if (cursor.moveToFirst()) cursor.getLong(0) else 0L + } + + override fun page(query: String, offset: Int, limit: Int): List { + val (where, arguments) = searchFilter(query) + return database.readableDatabase.query( + TABLE, null, where, arguments, null, null, "$TIMESTAMP DESC", "$offset, $limit" + ).use { cursor -> generateSequence { if (cursor.moveToNext()) logAt(cursor) else null }.toList() } + } + + override fun count(query: String): Int { + val (where, arguments) = searchFilter(query) + val sql = "SELECT COUNT(*) FROM $TABLE" + (where?.let { " WHERE $it" } ?: "") + return database.readableDatabase.rawQuery(sql, arguments).use { cursor -> + if (cursor.moveToFirst()) cursor.getInt(0) else 0 + } + } + + /** + * Builds the WHERE clause that finds [query] in any searchable column, ignoring case. + * `%` and `_` in the query are matched literally. + * + * @param query Text to look for; blank matches all. + * @return The clause and its arguments, or nulls when every log matches. + */ + private fun searchFilter(query: String): Pair?> { + val text = query.trim() + if (text.isEmpty()) return null to null + val pattern = "%" + text.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "%" + val clause = SEARCHABLE_COLUMNS.joinToString(" OR ") { "$it LIKE ? ESCAPE '\\'" } + return clause to Array(SEARCHABLE_COLUMNS.size) { pattern } + } + + /** + * Converts [log] into a table row. Recipient lists and names are stored as JSON text. + * + * @param log The log. + * @return The row's values. + */ + private fun valuesOf(log: AdminLog) = ContentValues().apply { + put(ID, log.id) + put(TYPE, log.type.name) + put(TITLE, log.title) + put(SENDER_ID, log.senderId) + put(SENDER_NAME, log.senderName) + put(RECIPIENT_IDS, JSONArray(log.recipientIds).toString()) + put(RECIPIENT_NAMES, JSONObject(log.recipientNames).toString()) + put(CONTENT, log.content) + put(CAMPSITE_ID, log.campsiteId) + put(CAMPSITE_NAME, log.campsiteName) + put(TIMESTAMP, log.timestamp) + } + + /** + * Reads the log in the cursor's current row. + * + * @param cursor A cursor over the table's rows. + * @return The log. + */ + private fun logAt(cursor: Cursor): AdminLog { + val recipientIds = JSONArray(cursor.text(RECIPIENT_IDS)) + val recipientNames = JSONObject(cursor.text(RECIPIENT_NAMES)) + return AdminLog( + id = cursor.text(ID), + type = LogType.valueOf(cursor.text(TYPE)), + title = cursor.text(TITLE), + senderId = cursor.text(SENDER_ID), + senderName = cursor.text(SENDER_NAME), + recipientIds = List(recipientIds.length()) { recipientIds.getString(it) }, + recipientNames = recipientNames.keys().asSequence().associateWith { recipientNames.getString(it) }, + content = cursor.text(CONTENT), + campsiteId = cursor.text(CAMPSITE_ID), + campsiteName = cursor.text(CAMPSITE_NAME), + timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)) + ) + } + + /** + * Reads a text column in the cursor's current row. + * + * @param column The column's name. + * @return The column's text. + */ + private fun Cursor.text(column: String): String = getString(getColumnIndexOrThrow(column)) + + companion object { + private const val TABLE = LocalDatabase.NOTIFICATION_LOGS_TABLE + private const val ID = "id" + private const val TYPE = "type" + private const val TITLE = "title" + private const val SENDER_ID = "sender_id" + private const val SENDER_NAME = "sender_name" + private const val RECIPIENT_IDS = "recipient_ids" + private const val RECIPIENT_NAMES = "recipient_names" + private const val CONTENT = "content" + private const val CAMPSITE_ID = "campsite_id" + private const val CAMPSITE_NAME = "campsite_name" + private const val TIMESTAMP = "timestamp" + + /** The columns a search looks in. */ + private val SEARCHABLE_COLUMNS = listOf( + TITLE, CONTENT, SENDER_ID, SENDER_NAME, RECIPIENT_IDS, RECIPIENT_NAMES, CAMPSITE_ID, CAMPSITE_NAME + ) + + /** + * Creates the notification logs table and its timestamp index, used by [LocalDatabase]. + * + * @param db The database to create the table in. + */ + fun createTable(db: SQLiteDatabase) { + db.execSQL( + """ + CREATE TABLE IF NOT EXISTS $TABLE ( + $ID TEXT PRIMARY KEY NOT NULL, + $TYPE TEXT NOT NULL, + $TITLE TEXT NOT NULL, + $SENDER_ID TEXT NOT NULL, + $SENDER_NAME TEXT NOT NULL, + $RECIPIENT_IDS TEXT NOT NULL, + $RECIPIENT_NAMES TEXT NOT NULL, + $CONTENT TEXT NOT NULL, + $CAMPSITE_ID TEXT NOT NULL, + $CAMPSITE_NAME TEXT NOT NULL, + $TIMESTAMP INTEGER NOT NULL + ) + """.trimIndent() + ) + db.execSQL("CREATE INDEX IF NOT EXISTS ${TABLE}_by_time ON $TABLE ($TIMESTAMP DESC)") + } + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt index 306ccc56..43836f74 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/RecentlyViewedStore.kt @@ -7,6 +7,8 @@ import android.database.sqlite.SQLiteOpenHelper /* * Provides local storage for recently viewed campsites and device settings. + * + * Outstanding issues: None known. */ /** @@ -82,6 +84,8 @@ class InMemoryRecentlyViewedStore : RecentlyViewedStore { * - [RECENTLY_VIEWED_TABLE]: campsites viewed on this device, used by [SqliteRecentlyViewedStore]. * - [SETTINGS_TABLE]: device settings as key-value pairs, such as the theme saved by * [SqliteThemePreferenceStore]. Added in version 2. + * - [NOTIFICATION_LOGS_TABLE]: a local copy of the notification logs admins review, kept in + * sync by [SqliteNotificationLogStore]. Added in version 3. * * @param context The application context. * @param name The database file name, or `null` for a database held in memory. @@ -105,7 +109,7 @@ class LocalDatabase( const val DATABASE_NAME = "lambda_local.db" /** The current database version. */ - const val DATABASE_VERSION = 2 + const val DATABASE_VERSION = 3 /** The recently viewed campsites table. */ const val RECENTLY_VIEWED_TABLE = "recently_viewed" @@ -124,6 +128,9 @@ class LocalDatabase( /** The setting's value column. */ const val COLUMN_VALUE = "value" + + /** The local copy of the notification logs. */ + const val NOTIFICATION_LOGS_TABLE = "notification_logs" } /** @@ -141,11 +148,12 @@ class LocalDatabase( """.trimIndent() ) createSettingsTable(db) + SqliteNotificationLogStore.createTable(db) } /** - * Adds the settings table to databases made before version 2, - * keeping the recently viewed campsites already saved. + * Adds the tables that databases made by older versions are missing, keeping the data + * already saved: the settings table (version 2) and the notification logs table (version 3). * * @param db The database to upgrade. * @param oldVersion The previous database version. @@ -155,6 +163,9 @@ class LocalDatabase( if (oldVersion < 2) { createSettingsTable(db) } + if (oldVersion < 3) { + SqliteNotificationLogStore.createTable(db) + } } /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/SessionStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/SessionStore.kt index e8328e44..9fd0dd95 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/SessionStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/SessionStore.kt @@ -4,6 +4,8 @@ import android.content.Context /* * Remembers whether the user has logged out on this device. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt index ff495dca..3f6ca2b3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/local/ThemePreferenceStore.kt @@ -4,6 +4,8 @@ import android.content.ContentValues import android.database.sqlite.SQLiteDatabase /* * Stores and retrieves user's theme preference using the local SQLite database. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/Lottery.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/Lottery.kt index 9fa9f4cd..384cb2a5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/Lottery.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/Lottery.kt @@ -5,6 +5,8 @@ import java.util.Date /* * Defines lottery information such as registration periods and waitlist capacity + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt index 3239d35a..cd260b6e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntry.kt @@ -5,6 +5,8 @@ import java.util.Date /* * Defines lottery waitlist entries, participant details, * and possible entry statuses. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt index 01510b5c..3e1a7d88 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Conversation.kt @@ -16,6 +16,8 @@ import com.google.firebase.Timestamp * chats per admin". * - "Okay so there are no conversations yet so can I have admins be able to message users from * the profile admin screen" + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/ConversationType.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/ConversationType.kt index 5bd21e79..5ab1599d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/ConversationType.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/ConversationType.kt @@ -1,5 +1,11 @@ package com.example.lambda_bbb_events.model.message +/* + * The kinds of conversation: camper with campsite owner, or camper with admin. + * + * Outstanding issues: None known. + */ + /** * Defines the supported conversation types. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt index 8b9fb15d..17689e7b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/Message.kt @@ -3,6 +3,8 @@ package com.example.lambda_bbb_events.model.message import com.google.firebase.Timestamp /* * Defines messages exchanged between users, campsite owners, and administrators. + * + * Outstanding issues: None known. */ //Reference: diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt index f728178c..12a154ff 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/MessagingAccess.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.message /* * Defines messaging permissions between users and campsite owners. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt index 3d8277e1..f9568bc4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/message/NotificationPreference.kt @@ -4,6 +4,8 @@ import com.google.firebase.Timestamp /* * Stores notification preferences for individual contacts. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt index 9fd4d72e..f5f3b0dd 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/Notification.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.notifications /* * Model classes for notifications. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt index 3defd033..d19ddb66 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationCategory.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.notifications /* * Defines notification categories and delivery modes. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt index 94570a36..931cb1d8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/notifications/NotificationHistory.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.notifications /* * Defines notification history entries saved locally for each user. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt index d1fc83b2..5c89c423 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/AdminRepository.kt @@ -3,11 +3,20 @@ package com.example.lambda_bbb_events.model.repository import com.example.lambda_bbb_events.model.admin.AdminLog import com.example.lambda_bbb_events.model.admin.LogType import com.google.firebase.Timestamp +import com.google.firebase.firestore.DocumentChange import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.Query +import com.google.firebase.firestore.snapshots +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map import kotlinx.coroutines.tasks.await + /* - * Retrieves admin notification and message logs from Firebase. + * Repository for the notification and message logs admins review. + * + * Outstanding issues: Message logs read every conversation and message at once, so loading them + * slows as messaging grows. */ /** @@ -31,18 +40,107 @@ class AdminLogRepository( db.collection("notificationLogs") /** - * Retrieves all stored notification logs. + * Records a notification a user sent to others, so admins can review it. Only the + * recipients it actually reached should be passed in. * - * The logs are sorted by timestamp in descending order, - * with the most recent notification displayed first. + * The log's ID is its document's ID. The fields are written explicitly, so the log's + * display-only properties are not stored. * - * @return A list of notification logs. + * @param title A short description of the notification. + * @param senderId Device ID of the user who sent it. + * @param senderName Name of the user who sent it, when it was sent. + * @param recipientIds Device IDs of the users it reached. + * @param content The notification's text. + * @param recipientNames Names of the recipients when it was sent, by device ID. + * @param campsiteId The campsite it was about, if any. + * @param campsiteName Name of that campsite when it was sent. */ - fun getNotificationLogs(): List { - // TODO: Retrieve notification logs once implemented. - return emptyList() + suspend fun logNotification( + title: String, + senderId: String, + senderName: String, + recipientIds: List, + content: String, + recipientNames: Map = emptyMap(), + campsiteId: String = "", + campsiteName: String = "" + ) { + val logRef = notificationLogsRef.document() + logRef.set( + mapOf( + "id" to logRef.id, + "type" to LogType.NOTIFICATION.name, + "title" to title, + "senderId" to senderId, + "senderName" to senderName, + "recipientIds" to recipientIds, + "recipientNames" to recipientNames, + "content" to content, + "campsiteId" to campsiteId, + "campsiteName" to campsiteName, + "timestamp" to System.currentTimeMillis() + ) + ).await() } + /** + * Observes notification logs from [since] onwards, oldest first, for keeping a local copy + * up to date. The first result holds every such log; later results hold only the logs + * added or changed since the previous one. + * + * @param since The earliest timestamp to include, in milliseconds. + * @return The new or changed logs, each time there are some. + */ + fun observeNotificationLogsSince(since: Long): Flow> = + notificationLogsRef + .whereGreaterThanOrEqualTo("timestamp", since) + .orderBy("timestamp", Query.Direction.ASCENDING) + .snapshots() + .map { snapshot -> + snapshot.documentChanges + .filter { it.type != DocumentChange.Type.REMOVED } + .mapNotNull { toNotificationLog(it.document) } + } + + /** + * Observes the notifications one user sent about one campsite, newest first, so an owner + * can look back at what they sent. Both filters are equality checks, which Firestore + * serves without a composite index, and the logs are sorted on the device. + * + * @param senderId Device ID of the user who sent them. + * @param campsiteId The campsite they were about. + * @return Every such log, each time one is added. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "As a campsite owner, I want to view a list of all notifications I have sent." + * - "you can manage lottery and there you should be able to see your past notifications + * sent" + */ + fun observeLogsSentBy(senderId: String, campsiteId: String): Flow> = + notificationLogsRef + .whereEqualTo("senderId", senderId) + .whereEqualTo("campsiteId", campsiteId) + .snapshots() + .map { snapshot -> + snapshot.documents + .mapNotNull { toNotificationLog(it) } + .sortedByDescending { it.timestamp } + } + + /** + * Reads a notification log from its document. The ID always comes from the document, so + * older logs saved without an ID still get a unique one. + * + * @param document The log's Firestore document. + * @return The log, or null if the document cannot be read as one. + */ + fun toNotificationLog(document: DocumentSnapshot): AdminLog? = + document.toObject(AdminLog::class.java)?.copy(id = document.id) + /** * Retrieves messages sent by campsite owners to entrants. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt index 2e9e8473..fe62decb 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/CampsiteRepository.kt @@ -15,6 +15,8 @@ import java.time.LocalDate /* * Defines Firestore campsite data models and handles campsite data conversion and storage. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt index 0dfe0cfc..32229529 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ConversationRepository.kt @@ -17,6 +17,8 @@ import kotlinx.coroutines.tasks.await /* * Handles creating, retrieving, and observing conversations in Firestore. + * + * Outstanding issues: None known. */ /* diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt index 06ca8d03..d21f5ef3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ImageRepository.kt @@ -11,6 +11,8 @@ import kotlinx.coroutines.tasks.await /* * Image functions such as storing, retrieving and deleting metadata and chunks in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt index 31db2ea4..de06ad64 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/LotteryRepository.kt @@ -21,6 +21,8 @@ import java.util.Date /* * Manages lottery and waitlist data in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt index dc831e26..b65824f8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessageRepository.kt @@ -19,6 +19,8 @@ import java.util.Date /* * Handles storing, retrieving, and deleting messages within a conversation. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt index 27844efe..d8b826c6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/MessagingAccessRepository.kt @@ -8,6 +8,8 @@ import com.google.firebase.firestore.firestore /* * Manages a user's campsite messaging access records in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt index 1ed778f2..ef7a01e6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationPreferenceRepository.kt @@ -9,6 +9,8 @@ import com.google.firebase.firestore.firestore /* * Manages a user's notification preferences in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt index 5e584948..dba2bd84 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/NotificationRepository.kt @@ -9,6 +9,8 @@ import androidx.core.app.NotificationManagerCompat /* * Creates notification channels and posts notifications through the Android push notifications. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt index d393c416..33626fff 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/Repository.kt @@ -12,6 +12,8 @@ import kotlinx.coroutines.tasks.await /* * Provides common Firestore operations and caching for repository subclasses. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt index 3ed7efc3..55fe1a52 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReservationRepository.kt @@ -19,6 +19,8 @@ import java.util.Date /* * Manages campsite reservations in Firestore and maintains messaging eligibility. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt index 5c058494..b39deb0a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReactionRepository.kt @@ -10,6 +10,8 @@ import com.google.firebase.firestore.firestore /* * Manages emoji reactions to campsite reviews in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt index 3400f5cf..d2d19d5b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewReplyRepository.kt @@ -10,6 +10,8 @@ import com.google.firebase.firestore.firestore /* * Manages replies to campsite reviews in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt index 7740595a..36c92593 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/ReviewRepository.kt @@ -14,6 +14,8 @@ import kotlin.math.roundToInt /* * Manages campsite reviews in Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt index df83a729..7b275982 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/UserRepository.kt @@ -19,6 +19,8 @@ import kotlinx.coroutines.tasks.await /* * Manages user data and cached profiles using Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt index 8ebd6c33..b874a25f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepository.kt @@ -16,6 +16,8 @@ import kotlinx.coroutines.tasks.await /* * Manages waitlist entries in Firestore using the repository pattern. * + * + * Outstanding issues: None known. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt index e8e05583..fff4b0e4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/reservation/Reservation.kt @@ -6,6 +6,8 @@ import java.time.format.DateTimeParseException /* * Defines campsite reservations and its details. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt index 5a61a1a8..1a53d2f2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/Review.kt @@ -5,6 +5,8 @@ import java.util.Date /* * Defines the reviews users write about campsites. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt index d431adc8..193c2e5a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReaction.kt @@ -4,6 +4,8 @@ import com.google.firebase.firestore.Exclude /* * Defines the emoji reactions users leave on campsite reviews. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt index 04c7a701..62bd7d90 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/review/ReviewReply.kt @@ -5,6 +5,8 @@ import java.util.Date /* * Defines the replies users write under campsite reviews. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt index 1a43d71f..ea967bd2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/AndroidAppIdentity.kt @@ -13,6 +13,8 @@ import java.security.MessageDigest * * Reference: * https://cloud.google.com/docs/authentication/api-keys#adding-application-restrictions + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt index 18f1cce7..018d538b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearch.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.services /* * Searches for places with Google, or with OpenStreetMap if Google's API key does not work. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt index f925554a..875d6f68 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FcmTokenRegistrar.kt @@ -1,6 +1,7 @@ package com.example.lambda_bbb_events.model.services import android.util.Log +import com.google.android.gms.tasks.Task import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.Firebase import com.google.firebase.firestore.FieldValue @@ -8,6 +9,8 @@ import com.google.firebase.firestore.firestore /* * Registers and saves the device's Firebase Cloud Messaging token. + * + * Outstanding issues: None known. */ /** @@ -31,11 +34,11 @@ object FcmTokenRegistrar { * * @param deviceId The ID of the current device. * @param token The FCM token. + * @return The write, which callers can wait on to know whether the token was saved. */ - fun save(deviceId: String, token: String) { + fun save(deviceId: String, token: String): Task = Firebase.firestore.collection("fcmTokens").document(deviceId) .set(mapOf("token" to token, "updatedAt" to FieldValue.serverTimestamp())) .addOnSuccessListener { Log.d("FCM", "Token saved for $deviceId") } .addOnFailureListener { Log.e("FCM", "Failed to save token", it) } - } } \ No newline at end of file diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt index 7537721b..8685fdd0 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/FirebaseNotificationService.kt @@ -9,6 +9,8 @@ import kotlinx.coroutines.flow.asSharedFlow /* * Receives Firebase Cloud Messaging messages and handles token updates. + * + * Outstanding issues: None known. */ /** @@ -32,11 +34,16 @@ class FirebaseNotificationService : FirebaseMessagingService() { /** * Handles an incoming Firebase Cloud Messaging message. * + * Chat message pushes are skipped, since this only runs while the app is open and + * [IncomingMessageListener] already notifies about chat messages then. + * * @param message The message received from Firebase. */ override fun onMessageReceived(message: RemoteMessage) { super.onMessageReceived(message) + if (isChatMessage(message)) return + val title = message.notification?.title ?: message.data["title"] ?: "Campsite Notification" @@ -55,6 +62,16 @@ class FirebaseNotificationService : FirebaseMessagingService() { Log.d("FCM", "Notification received") } + /** + * Whether [message] is a push for a new chat message, which the `notifyNewChatMessage` + * Cloud Function marks with `type` = `chat`. + * + * @param message The message received from Firebase. + * @return `true` for chat message pushes. + */ + private fun isChatMessage(message: RemoteMessage): Boolean = + message.data["type"] == "chat" + /** * Saves the new Firebase Cloud Messaging registration token. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt index fa2996a1..f4977a82 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/ImageProcessor.kt @@ -14,6 +14,12 @@ import com.example.lambda_bbb_events.model.repository.ImageRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +/* + * Resizes and compresses images for storage, and decodes them for display. + * + * Outstanding issues: None known. + */ + /** * Prepares images for storage and loads them back for display. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt index 14ada1d8..6b5fc72f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/IncomingMessageListener.kt @@ -2,8 +2,8 @@ package com.example.lambda_bbb_events.model.services import android.content.Context import android.util.Log -import com.example.lambda_bbb_events.controller.MessageController -import com.example.lambda_bbb_events.controller.MessageNotificationController +import com.example.lambda_bbb_events.controller.messaging.MessageController +import com.example.lambda_bbb_events.controller.notification.MessageNotificationController import com.example.lambda_bbb_events.model.message.Conversation import com.example.lambda_bbb_events.model.message.Message import com.google.firebase.Firebase @@ -23,6 +23,8 @@ import kotlinx.coroutines.launch /* * Listens for incoming chat messages and triggers Android notifications. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt index a148bd6f..0a50899e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/LotteryService.kt @@ -4,6 +4,8 @@ import com.example.lambda_bbb_events.model.lottery.Lottery /* * The function for drawing lottery winners and losers. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/MapProvider.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/MapProvider.kt index 50c4236f..d6773f47 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/MapProvider.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/MapProvider.kt @@ -7,6 +7,8 @@ import com.example.lambda_bbb_events.BuildConfig /* * Chooses the service used for maps and for searching for places. + * + * Outstanding issues: None known. */ /** A service that provides maps and place search. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt index dbb6051e..3294121c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotoDecoding.kt @@ -12,6 +12,8 @@ import kotlinx.coroutines.withContext /* * Decodes photos selected by the user into bitmaps. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt index 1a9da9b3..5746660e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PhotonPlaceSearch.kt @@ -16,6 +16,8 @@ import java.net.URLEncoder * * Reference: * https://photon.komoot.io/ + * + * Outstanding issues: None known. */ private const val PHOTON_URL = "https://photon.komoot.io/api/" diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt index 453393bf..e126bb7e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/PlaceSearch.kt @@ -14,6 +14,8 @@ import java.net.URLEncoder * * Reference: * https://developers.google.com/maps/documentation/places/web-service/place-autocomplete + * + * Outstanding issues: None known. */ private const val PLACES_URL = "https://places.googleapis.com/v1/places" diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/QRCodeService.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/QRCodeService.kt index c4b0a518..2ab29d37 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/QRCodeService.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/QRCodeService.kt @@ -16,6 +16,8 @@ import com.google.zxing.qrcode.QRCodeWriter /* * Defines generating and scanning QR codes to navigate to campsite details. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt deleted file mode 100644 index 7be47292..00000000 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/services/SystemNotificationListener.kt +++ /dev/null @@ -1,276 +0,0 @@ -package com.example.lambda_bbb_events.model.services - -import android.util.Log -import com.example.lambda_bbb_events.controller.NotificationController -import com.example.lambda_bbb_events.model.lottery.WaitlistStatus -import com.example.lambda_bbb_events.model.reservation.ReservationStatus -import com.example.lambda_bbb_events.model.notifications.Notification -import com.example.lambda_bbb_events.model.notifications.NotificationCategory -import com.google.firebase.Firebase -import com.google.firebase.firestore.FirebaseFirestore -import com.google.firebase.firestore.MetadataChanges -import com.google.firebase.firestore.QuerySnapshot -import com.google.firebase.firestore.firestore -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.channels.awaitClose -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.flow.callbackFlow -import kotlinx.coroutines.launch - -/** - * Listens for changes to waitlist entries and reservations - * associated with the current user. - * - * Displays Android notifications according to the user's - * notification category preferences. - * - * @property notificationController Controller responsible for - * displaying system notifications. - * @property db Firestore database instance. - */ -class SystemNotificationListener( - private val notificationController: NotificationController, - private val db: FirebaseFirestore = Firebase.firestore -) { - - /** - * Starts listening for system notification events. - * - * Listeners are removed when the coroutine is canceled. - * - * @param userId Device ID of the current user. - */ - suspend fun listen(userId: String) = coroutineScope { - - launch { - listenToWaitlistEntries(userId) - } - - launch { - listenToReservations(userId) - } - } - - /** - * Listens for lottery results and waitlist invitations. - * - * @param userId Device ID of the entrant. - */ - private suspend fun listenToWaitlistEntries( - userId: String - ) { - observeStatusChanges( - collection = "waitlistEntries", - userId = userId - ) { status -> - - when (status) { - - WaitlistStatus.WON.name -> { - notificationController.showNotification( - notification = Notification( - title = "Lottery Winner", - message = "Congratulations! You have been selected." - ), - category = NotificationCategory.LOTTERY - ) - } - - WaitlistStatus.LOST.name -> { - notificationController.showNotification( - notification = Notification( - title = "Lottery Result", - message = "Unfortunately, you were not selected." - ), - category = NotificationCategory.REJECTION - ) - } - - else -> Unit - } - } - } - - /** - * Listens for changes to reservation statuses. - * - * @param userId Device ID of the entrant. - */ - private suspend fun listenToReservations( - userId: String - ) { - observeStatusChanges( - collection = "reservations", - userId = userId - ) { status -> - - when (status) { - - ReservationStatus.CONFIRMED.name -> { - notificationController.showNotification( - notification = Notification( - title = "Reservation Confirmed", - message = "Your campsite reservation has been confirmed." - ), - category = NotificationCategory.GENERAL - ) - } - - ReservationStatus.REJECTED.name -> { - notificationController.showNotification( - notification = Notification( - title = "Reservation Rejected", - message = "Your reservation has been rejected." - ), - category = NotificationCategory.REJECTION - ) - } - - ReservationStatus.CANCELLED.name -> { - notificationController.showNotification( - notification = Notification( - title = "Reservation Cancelled", - message = "Your campsite reservation has been cancelled." - ), - category = NotificationCategory.CANCELLATION - ) - } - - else -> Unit - } - } - } - - /** - * Observes status changes within a Firestore collection. - * - * The initial server snapshot is used as a baseline - * to prevent notifications for existing records. - * - * @param collection Firestore collection name. - * @param userId Device ID of the entrant. - * @param onStatusChanged Called when a status changes. - */ - private suspend fun observeStatusChanges( - collection: String, - userId: String, - onStatusChanged: (String) -> Unit - ) { - - val previousStatuses = mutableMapOf() - - var initialized = false - - try { - - observeCollection( - collection, - userId - ).collect { snapshot -> - - // Ignore cached data and uncommitted writes. - if (snapshot.metadata.isFromCache) { - return@collect - } - - if (snapshot.metadata.hasPendingWrites()) { - return@collect - } - - val currentStatuses = - mutableMapOf() - - snapshot.documents.forEach { document -> - - val status = document.getString("status") - ?: return@forEach - - currentStatuses[document.id] = status - } - - // Store existing statuses without notifying. - if (!initialized) { - - previousStatuses.putAll(currentStatuses) - - initialized = true - - Log.d( - "SystemNotificationListener", - "Listening to $collection: ${currentStatuses.size} records" - ) - - return@collect - } - - // Detect changed or newly created statuses. - currentStatuses.forEach { (id, status) -> - - val previousStatus = previousStatuses[id] - - if (previousStatus != status) { - - Log.d( - "SystemNotificationListener", - "$collection/$id: $previousStatus -> $status" - ) - - onStatusChanged(status) - } - } - - previousStatuses.clear() - previousStatuses.putAll(currentStatuses) - } - - } catch (e: CancellationException) { - - throw e - - } catch (e: Exception) { - - Log.e( - "SystemNotificationListener", - "Failed to observe $collection", - e - ) - } - } - - /** - * Observes Firestore documents belonging to the entrant. - * - * @param collection Firestore collection name. - * @param userId Device ID of the entrant. - * @return Flow of Firestore query snapshots. - */ - private fun observeCollection( - collection: String, - userId: String - ) = callbackFlow { - - val registration = db - .collection(collection) - .whereEqualTo("entrantId", userId) - .addSnapshotListener( - MetadataChanges.INCLUDE - ) { snapshot, error -> - - if (error != null) { - - close(error) - - return@addSnapshotListener - } - - if (snapshot != null) { - - trySend(snapshot) - } - } - - awaitClose { - registration.remove() - } - } -} \ No newline at end of file diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt index 4cb34bb5..eac829f2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Admin.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.user /* * Defines admin within the user model. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt index 6aa179b9..d57c8daa 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/CampsiteOwner.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.user /* * Defines owner within the user model. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt index 7c9b03f2..1dfff5b2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/Entrant.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.user /* * Defines entrant within the user model. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt index cfeee644..4382f9c5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/model/user/User.kt @@ -2,6 +2,8 @@ package com.example.lambda_bbb_events.model.user /* * Defines user model roles + * + * Outstanding issues: None known. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt index 064d9daa..2c05c791 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminCampsitesScreen.kt @@ -38,6 +38,8 @@ import com.example.lambda_bbb_events.view.ui.components.filter.HomeCampsiteFilte /* * Displays and filters campsite listings in the admin screen. + * + * Outstanding issues: None known. */ /** @@ -56,13 +58,10 @@ fun AdminCampsitesScreen( var query by remember { mutableStateOf(controllers.campsites.searchQuery) } var openFilter by remember { mutableStateOf(false) } - val results = controllers.campsites.getSearchResults() - Scaffold( modifier = Modifier.testTag("screen_admin_campsites"), containerColor = MaterialTheme.colorScheme.background, contentColor = MaterialTheme.colorScheme.onBackground - // TODO: add the admin bottom navigation bar here ) { innerPadding -> Column( modifier = Modifier @@ -128,6 +127,8 @@ fun AdminCampsitesScreen( Spacer(modifier = Modifier.height(2.dp)) + val results = controllers.campsites.getSearchResults() + LazyColumn( modifier = Modifier .weight(1f) diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt index eb0ffcc7..3f0fe7d8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminHomeScreen.kt @@ -32,6 +32,8 @@ import com.example.lambda_bbb_events.view.ui.components.admin.NoAccessMessage /* * Displays the admin home screen and provides navigation to admin tools. + * + * Outstanding issues: None known. */ /** @@ -51,7 +53,6 @@ fun AdminHomeScreen( modifier = Modifier.testTag("admin_home_screen"), containerColor = MaterialTheme.colorScheme.background, contentColor = MaterialTheme.colorScheme.onBackground - // TODO: add the admin bottom navigation bar here ) { innerPadding -> if (!isAdmin) { NoAccessMessage(navController) @@ -149,8 +150,6 @@ fun AdminHomeScreen( } } - // TODO: recent logs shown - item { Spacer(modifier = Modifier.height(16.dp)) } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt index 1aecb740..9a7749aa 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminImagesScreen.kt @@ -49,6 +49,8 @@ import com.example.lambda_bbb_events.view.ui.components.profile.ShowAlertDialog import kotlinx.coroutines.launch /* * Displays and manages campsite and user images for administrator moderation. + * + * Outstanding issues: None known. */ /** @@ -160,7 +162,6 @@ fun AdminImagesScreen( modifier = Modifier.testTag("screen_admin_images"), containerColor = MaterialTheme.colorScheme.background, contentColor = MaterialTheme.colorScheme.onBackground - // TODO: add the admin bottom navigation bar here ) { innerPadding -> Column( modifier = Modifier diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt index 4f8daee6..955451bc 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminLogsScreen.kt @@ -19,12 +19,16 @@ import com.example.lambda_bbb_events.model.user.UserRole import com.example.lambda_bbb_events.view.ui.components.admin.NoAccessMessage import com.example.lambda_bbb_events.view.ui.components.logs.AdminLogCard import com.example.lambda_bbb_events.view.ui.components.logs.AdminLogDialog +import com.example.lambda_bbb_events.view.ui.components.logs.LogPageControls +import com.example.lambda_bbb_events.view.ui.components.logs.NotificationLogSync import com.example.lambda_bbb_events.view.ui.components.logs.LogSearchBar import com.example.lambda_bbb_events.view.ui.components.logs.LogTabSelector import kotlinx.coroutines.CancellationException /* * Displays administrative notification and message logs. + * + * Outstanding issues: None known. */ /** @@ -147,14 +151,24 @@ private fun AdminLogsContent( // Retrieve logs when the selected tab changes // or the administrator requests a retry. - LaunchedEffect(selectedTab, refreshTrigger) { + val notificationPages = controllers.adminLogs.notificationPages + val notificationSearch = if (selectedTab == LogType.NOTIFICATION) searchQuery else "" + + NotificationLogSync(controllers, refreshTrigger) { errorMessage = it } + + LaunchedEffect( + selectedTab, + refreshTrigger, + notificationPages.pageIndex, + notificationSearch, + controllers.adminLogs.syncedCount + ) { - isLoading = true + isLoading = logs.isEmpty() errorMessage = null - logs = emptyList() try { - logs = controllers.adminLogs.getLogs(selectedTab) + logs = controllers.adminLogs.getLogs(selectedTab, notificationSearch) } catch (e: CancellationException) { throw e @@ -202,7 +216,7 @@ private fun AdminLogsContent( logs = resolvedLogs.filter { it.type == selectedTab }, - query = searchQuery + query = searchQuery.takeIf { selectedTab == LogType.MESSAGE }.orEmpty() ) } @@ -231,6 +245,7 @@ private fun AdminLogsContent( searchQuery = searchQuery, onSearchQueryChange = { searchQuery = it + notificationPages.reset() } ) @@ -328,6 +343,10 @@ private fun AdminLogsContent( } } } + + if (selectedTab == LogType.NOTIFICATION && errorMessage == null) { + LogPageControls(pager = notificationPages) + } } // Retrieve the selected log with its latest resolved names. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt index 167232ff..cfe8bf9b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfileDetailsScreen.kt @@ -61,6 +61,12 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackA import com.example.lambda_bbb_events.view.ui.components.profile.ShowAlertDialog import kotlinx.coroutines.launch +/* + * Admin screen for one user's profile, where an admin can message, promote or remove them. + * + * Outstanding issues: None known. + */ + /** * Displays a user's profile to an admin, who can message the user, promote them to admin, * or remove them. Promoting and removing ask for confirmation first, and every action shows @@ -125,7 +131,6 @@ fun AdminProfileDetailsScreen( modifier = Modifier.testTag("screen_admin_profile_details"), containerColor = MaterialTheme.colorScheme.background, contentColor = MaterialTheme.colorScheme.onBackground - // TODO: add the admin bottom navigation bar here ) { innerPadding -> Column( modifier = Modifier diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfilesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfilesScreen.kt index dd644512..681e349d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfilesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/admin_screens/AdminProfilesScreen.kt @@ -31,6 +31,12 @@ import com.example.lambda_bbb_events.view.ui.components.admin.NoAccessMessage import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.common.SearchBar +/* + * Admin screen listing every user profile. + * + * Outstanding issues: None known. + */ + /** * Displays all user profiles registered in the app. Can search with search bar. * @@ -72,7 +78,6 @@ fun AdminProfilesScreen( modifier = Modifier.testTag("screen_admin_profiles"), containerColor = MaterialTheme.colorScheme.background, contentColor = MaterialTheme.colorScheme.onBackground - // TODO: add the admin bottom navigation bar here ) { innerPadding -> Column( modifier = Modifier diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminProfileListCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminProfileListCard.kt index 5db0b0ca..e91bb88e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminProfileListCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminProfileListCard.kt @@ -30,6 +30,12 @@ import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.user.User import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture +/* + * A card summarizing one user in the admin profile list. + * + * Outstanding issues: None known. + */ + /** * Displays a card of the user's information. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt index 0683fc92..be68ecc4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminScreenTitleWithRoleSwitcher.kt @@ -16,6 +16,12 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import androidx.navigation.NavController +/* + * The admin screens' title bar, with the role switcher and notifications button. + * + * Outstanding issues: None known. + */ + /** * Displays the role switcher, title and the notifications button. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminToolTile.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminToolTile.kt index af28f903..5e9bef13 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminToolTile.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/AdminToolTile.kt @@ -25,6 +25,12 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp +/* + * A tile for one admin tool on the admin home screen. + * + * Outstanding issues: None known. + */ + /** * Displays an admin tool as a tile containing an icon and title. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/MakeAdminDialog.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/MakeAdminDialog.kt index b37ccf48..f705d0a8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/MakeAdminDialog.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/MakeAdminDialog.kt @@ -17,6 +17,12 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp +/* + * A dialog asking for the admin password before a user is made an admin. + * + * Outstanding issues: None known. + */ + /** * Displays a dialog that asks for the admin password before a user is made an admin. The * password is hidden while it is typed, and is forgotten when the dialog closes. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/NoAccessMessage.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/NoAccessMessage.kt index 48829efd..7e0f809b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/NoAccessMessage.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/NoAccessMessage.kt @@ -15,6 +15,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.navigation.NavController +/* + * The message shown when someone without the admin role opens an admin screen. + * + * Outstanding issues: None known. + */ + /** * Displayed to user that opens admin screens without having admin role. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RoleDropdownSwitcher.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RoleDropdownSwitcher.kt index fe41fcf6..29295ec6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RoleDropdownSwitcher.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RoleDropdownSwitcher.kt @@ -26,6 +26,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp +/* + * A dropdown for switching between the user and admin views. + * + * Outstanding issues: None known. + */ + /** * Displays a dropdown menu for the user to switch between user and admin roles. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt index ada71cf1..b065ced4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/admin/RunLotteriesButton.kt @@ -24,11 +24,13 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import com.example.lambda_bbb_events.controller.AdminLotteryController +import com.example.lambda_bbb_events.controller.admin.AdminLotteryController import kotlinx.coroutines.launch /* * Allows administrators to manually run all lotteries after confirmation. + * + * Outstanding issues: None known. */ /** Logcat tag for run-lotteries failures. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt index 261c1636..e0ceb4c5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/CampsiteAvailabilityCalendar.kt @@ -25,6 +25,8 @@ import java.util.Locale * * Uses Material 3 theme colors to display available, * unavailable, and selected dates in light and dark modes. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DatePicker.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DatePicker.kt index dbbba681..63fe121b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DatePicker.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DatePicker.kt @@ -23,6 +23,12 @@ import androidx.compose.ui.unit.sp import java.time.LocalDate import java.util.Locale +/* + * A date field that opens a calendar picker. + * + * Outstanding issues: None known. + */ + /** * Displays an editable date field with a calendar picker. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DateRangeCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DateRangeCard.kt index 879c42d8..a76c3d18 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DateRangeCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/DateRangeCard.kt @@ -20,6 +20,12 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import java.time.LocalDate +/* + * A card for choosing a start and end date. + * + * Outstanding issues: None known. + */ + /** * A card asking users to select a date range. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt index 647412bc..f4ae4810 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/calendar/PopUpShowDatePicker.kt @@ -6,6 +6,8 @@ import java.util.Calendar /* * Provides a date picker dialog for selecting calendar dates. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCampsiteCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCampsiteCard.kt index e0d95e2d..f9a1ab3b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCampsiteCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCampsiteCard.kt @@ -33,6 +33,8 @@ import com.example.lambda_bbb_events.view.ui.components.common.ImageFraming /* * Defines a compact campsite card for horizontally scrolling lists. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCardSection.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCardSection.kt index 7a3ef56b..c6a936b2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCardSection.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/HorizontalCardSection.kt @@ -19,6 +19,8 @@ import com.example.lambda_bbb_events.model.campsite.Campsite /* * Defines a horizontally scrollable section of campsite cards * with a title and a "See All" action. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/PhotoManager.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/PhotoManager.kt index e2a2b577..0177ba56 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/PhotoManager.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/PhotoManager.kt @@ -39,8 +39,8 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.controller.CampsitePhotoController -import com.example.lambda_bbb_events.controller.CampsitePhotoController.Companion.MAX_PHOTOS +import com.example.lambda_bbb_events.controller.campsite.CampsitePhotoController +import com.example.lambda_bbb_events.controller.campsite.CampsitePhotoController.Companion.MAX_PHOTOS import com.example.lambda_bbb_events.model.image.ImageMetaData import com.example.lambda_bbb_events.model.services.decodePhoto import com.example.lambda_bbb_events.view.ui.components.common.StoredImage @@ -50,6 +50,8 @@ import kotlinx.coroutines.launch /* * Lets owners change the photos of their campsites. + * + * Outstanding issues: None known. */ /** Longest side in pixels photos are shrunk to before uploading. They are stored no larger. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt index d2267bd5..f8f3ac63 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/SeeAllCampsiteCard.kt @@ -20,6 +20,8 @@ import com.example.lambda_bbb_events.view.ui.components.rating.formatRating /* * Defines a campsite card used in expanded campsite list. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagEditor.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagEditor.kt index 8417062e..fedcc9eb 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagEditor.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/TagEditor.kt @@ -31,6 +31,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.foundation.layout.Column +/* + * An editor for adding and removing campsite tags. + * + * Outstanding issues: None known. + */ + /** * Allows users to add and remove campsite tags. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCampsiteCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCampsiteCard.kt index 0a301979..db7aa844 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCampsiteCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCampsiteCard.kt @@ -35,6 +35,8 @@ import com.example.lambda_bbb_events.view.ui.components.common.THUMBNAIL_WIDTH /* * Defines a clickable campsite card. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt index 83338729..0a17707b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/campsite/VerticalCardSection.kt @@ -18,6 +18,8 @@ import com.example.lambda_bbb_events.model.campsite.Campsite /* * Defines a vertically arranged section of campsite cards with a title and a "See All" action * that allows the user to see all cards in selection. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt index df4cd980..08a058cb 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/AppLogo.kt @@ -12,6 +12,8 @@ import com.example.lambda_bbb_events.R /* * Displays the Lambda Camping app logo. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt index 31096913..a7160365 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/DisplayImage.kt @@ -51,6 +51,8 @@ import kotlinx.coroutines.launch /* * Provides reusable composables for displaying images stored in the database. + * + * Outstanding issues: None known. */ /** Width of the photo on list cards, the campsite's thumbnail. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt index 46ce4bfe..7dc1d856 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/FormTextField.kt @@ -22,6 +22,8 @@ import androidx.compose.ui.unit.dp * * Uses Material 3 colors and typography to support * the application's light and dark themes. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberField.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberField.kt index 44f88f4a..be597fbe 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberField.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberField.kt @@ -42,6 +42,8 @@ import com.example.lambda_bbb_events.model.formatting.maxLocalNumberLength /* * Defines a phone number input with a country calling code picker. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt index 9abf5745..55d903c0 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhoneNumberFormatting.kt @@ -9,6 +9,8 @@ import com.example.lambda_bbb_events.model.formatting.formatLocalNumber /* * Defines transformations for phone number fields. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt index 9780f671..a9dc9bc9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/PhotoFocus.kt @@ -42,6 +42,8 @@ import androidx.compose.ui.unit.dp /* * Lets owners choose which part of a photo stays in view when it is cropped. + * + * Outstanding issues: None known. */ /** Size of the ring that marks the chosen spot. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/QuickToast.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/QuickToast.kt index c90603f3..04611705 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/QuickToast.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/QuickToast.kt @@ -5,6 +5,8 @@ import android.content.Context /* * Quick function for toast pop-up that has the ability to update current toast on screen as well +* +* Outstanding issues: None known. */ /** Toast currently displayed on screen, defaults to null*/ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangePicker.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangePicker.kt index b1724a54..d195c485 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangePicker.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangePicker.kt @@ -1,3 +1,5 @@ +package com.example.lambda_bbb_events.view.ui.components.common + import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -16,12 +18,13 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.view.ui.components.common.closestStops import kotlin.math.roundToInt /* * Defines a reusable range slider for selecting * minimum and maximum numerical values. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStops.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStops.kt index 6f4cafb7..f92d5dae 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStops.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStops.kt @@ -4,6 +4,8 @@ import kotlin.math.abs /* * Matches ranges of values to the stops of a range slider. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt index dc6f5625..d20f2131 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/ScreenTitle.kt @@ -24,6 +24,8 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackA /* * Displays a reusable screen title with optional navigation and notification buttons. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/SearchBar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/SearchBar.kt index 97a52b4f..ebe2d1d3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/SearchBar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/common/SearchBar.kt @@ -19,6 +19,8 @@ import androidx.compose.ui.unit.dp /* * Defines a reusable search bar using the application's * Material 3 theme. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterButton.kt index f2d2b577..571ca298 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterButton.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterButton.kt @@ -16,6 +16,8 @@ import androidx.compose.ui.unit.dp * Defines a reusable filter button for opening search filters. * * Uses the application's Material 3 theme. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterIconButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterIconButton.kt index 9085c2ce..a5a87271 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterIconButton.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/FilterIconButton.kt @@ -17,6 +17,8 @@ import androidx.compose.ui.unit.dp /* * Defines a reusable icon button for opening search filters. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/HomeCampsiteFilter.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/HomeCampsiteFilter.kt index d8e6fbdf..ba177dc8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/HomeCampsiteFilter.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/filter/HomeCampsiteFilter.kt @@ -1,7 +1,6 @@ package com.example.lambda_bbb_events.view.ui.components.filter -import RangePicker import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape @@ -12,13 +11,14 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.controller.CampsiteController +import com.example.lambda_bbb_events.controller.campsite.CampsiteController import com.example.lambda_bbb_events.model.campsite.SearchArea import com.example.lambda_bbb_events.view.ui.components.map.AreaMap import java.util.Locale import com.example.lambda_bbb_events.model.formatting.parseDateOrNull import com.example.lambda_bbb_events.view.ui.components.rating.PickRatingStars import com.example.lambda_bbb_events.view.ui.components.calendar.DatePickerField +import com.example.lambda_bbb_events.view.ui.components.common.RangePicker import com.example.lambda_bbb_events.view.ui.components.common.FormTextField import com.example.lambda_bbb_events.view.ui.components.common.closestStops import kotlin.math.roundToInt @@ -26,6 +26,8 @@ import kotlin.math.roundToInt /* * Provides filtering campsites by date, location, * guest capacity, and minimum rating. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/image/DisplayImage.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/image/DisplayImage.kt index cbae9fdb..9cd2fe89 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/image/DisplayImage.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/image/DisplayImage.kt @@ -16,6 +16,8 @@ import coil3.compose.AsyncImage * from URLs using Coil. * * Uses Material 3 theme colors for fallback content. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogCard.kt index f148bde8..82f8e6f5 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogCard.kt @@ -21,6 +21,12 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +/* + * A card summarizing one notification or message log on the admin logs screen. + * + * Outstanding issues: None known. + */ + /** * Displays an individual notification or message log. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogDialog.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogDialog.kt index c072c6c4..247237f1 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogDialog.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/AdminLogDialog.kt @@ -10,6 +10,12 @@ import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.admin.AdminLog import com.example.lambda_bbb_events.model.admin.LogType +/* + * A dialog showing every detail of one admin log. + * + * Outstanding issues: None known. + */ + /** * Displays the complete details of an administrative log. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogPageControls.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogPageControls.kt new file mode 100644 index 00000000..cbafe786 --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogPageControls.kt @@ -0,0 +1,67 @@ +package com.example.lambda_bbb_events.view.ui.components.logs + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import com.example.lambda_bbb_events.controller.admin.LogPager + +/* + * Previous and Next buttons with the page number, for moving through notification log pages. + * + * Outstanding issues: None known. + */ + +/** + * Previous and Next buttons with the current page number, for moving through log pages. + * + * @param pager The pager whose pages are being shown. + * @param modifier Modifier applied to the row. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Because my worry is overwhelming the device with like 10000 logs." + * - "We still want it to update live." + */ +@Composable +fun LogPageControls( + pager: LogPager, + modifier: Modifier = Modifier +) { + Row( + modifier = modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + TextButton( + onClick = pager::previous, + enabled = pager.hasPrevious, + modifier = Modifier.testTag("button_logs_previous") + ) { + Text("Previous") + } + + Text( + text = "Page ${pager.pageIndex + 1}", + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.testTag("text_logs_page") + ) + + TextButton( + onClick = pager::next, + enabled = pager.hasNext, + modifier = Modifier.testTag("button_logs_next") + ) { + Text("Next") + } + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogSearchBar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogSearchBar.kt index fd8c198b..5370d3e2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogSearchBar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogSearchBar.kt @@ -14,6 +14,12 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +/* + * The search bar on the admin logs screen. + * + * Outstanding issues: None known. + */ + /** * Displays a search bar for filtering administrative logs. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogTabSelector.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogTabSelector.kt index 2e798fab..2b845b3c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogTabSelector.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/LogTabSelector.kt @@ -15,6 +15,12 @@ import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.admin.LogType +/* + * Tabs for switching between notification logs and message logs. + * + * Outstanding issues: None known. + */ + /** * Displays a segmented tab selector for the admin logs screen. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/NotificationLogSync.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/NotificationLogSync.kt new file mode 100644 index 00000000..3b66912a --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/logs/NotificationLogSync.kt @@ -0,0 +1,45 @@ +package com.example.lambda_bbb_events.view.ui.components.logs + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import com.example.lambda_bbb_events.controller.AppControllers +import kotlinx.coroutines.CancellationException + +/* + * Keeps the local copy of the notification logs in sync while the admin logs screen is open. + * + * Outstanding issues: None known. + */ + +/** + * Keeps the local copy of the notification logs in sync while it is on screen. Draws nothing. + * A failed sync is reported through [onError] and starts again when [retryKey] changes. + * + * @param controllers Application controllers. + * @param retryKey Restarts syncing whenever it changes, such as when Retry is pressed. + * @param onError Called with a message if syncing fails. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "I realized we have a sqlite db and instead we could just sync to local copy and update + * the sqlite3 db." + */ +@Composable +fun NotificationLogSync( + controllers: AppControllers, + retryKey: Any, + onError: (String) -> Unit +) { + LaunchedEffect(retryKey) { + try { + controllers.adminLogs.syncNotificationLogs() + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { + onError(e.message ?: "Failed to sync logs.") + } + } +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/LotteryEntryCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/LotteryEntryCard.kt index a9ebb4dc..fcaa01e4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/LotteryEntryCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/LotteryEntryCard.kt @@ -35,6 +35,12 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +/* + * A card for one of the user's lottery entries on the lottery bookings screen. + * + * Outstanding issues: None known. + */ + /** * A card for the lottery tab in the lottery bookings screen. It shows the campsite, the * state of the entry (e.g. in waitlist, won, lost, etc.), when the registration ends, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/OwnerLotteryCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/OwnerLotteryCard.kt index 651666fa..fddad2e0 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/OwnerLotteryCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/OwnerLotteryCard.kt @@ -27,12 +27,18 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.LotteryPhase +import com.example.lambda_bbb_events.controller.lottery.LotteryPhase import com.example.lambda_bbb_events.model.lottery.Lottery import java.text.SimpleDateFormat import java.util.Date import java.util.Locale +/* + * A card showing an owner's lottery: its periods, winners, waitlist and phase. + * + * Outstanding issues: None known. + */ + /** * A card that shows the details of a lottery including the registration and booking * periods, the number of winners, how full the waitlist is, and which phase diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationInformationBox.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationInformationBox.kt index 9e4a1fa1..264ff542 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationInformationBox.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationInformationBox.kt @@ -22,6 +22,8 @@ import java.util.Locale /* * Displays a campsite registration summary. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationStatusBox.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationStatusBox.kt index 8844bd64..df57280b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationStatusBox.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/lottery/RegistrationStatusBox.kt @@ -17,6 +17,8 @@ import androidx.compose.ui.unit.dp /* * Defines a status box for displaying campsite registration status. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/AreaMap.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/AreaMap.kt index 3aae449c..cbf56872 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/AreaMap.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/AreaMap.kt @@ -35,6 +35,8 @@ import kotlin.math.roundToInt * Provides a map for choosing an area to filter campsites by. Tapping the map places the * area's centre, and dragging the handle on its edge resizes it. The Google and OpenStreetMap * versions are in GoogleAreaMap.kt and OpenStreetAreaMap.kt. + * + * Outstanding issues: None known. */ /** Where the map looks before an area is chosen, the same place as the location picker. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/CampsiteMap.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/CampsiteMap.kt index 6c06f413..ee0f560a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/CampsiteMap.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/CampsiteMap.kt @@ -14,6 +14,8 @@ import com.example.lambda_bbb_events.model.services.MapProvider /* * Provides a map showing where campsites are. + * + * Outstanding issues: None known. */ /** Zoom level used when showing a single campsite. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/ClickableMap.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/ClickableMap.kt index adeea47e..cd5e65c2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/ClickableMap.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/ClickableMap.kt @@ -35,6 +35,8 @@ import kotlin.coroutines.resume /* * Provides an interactive map for selecting campsite locations + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleAreaMap.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleAreaMap.kt index 8faea581..5b7e2edf 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleAreaMap.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleAreaMap.kt @@ -35,6 +35,8 @@ import kotlin.math.roundToInt /* * The Google version of AreaMap, using the native Maps SDK for Android. + * + * Outstanding issues: None known. */ /** Metres in a kilometre, for Google's circle radius. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleMapViews.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleMapViews.kt index da400ea8..20f063c3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleMapViews.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/GoogleMapViews.kt @@ -52,6 +52,8 @@ import kotlinx.coroutines.flow.filter * * Reference: * https://developers.google.com/maps/documentation/android-sdk/maps-compose + * + * Outstanding issues: None known. */ /** Zoom used by the location picker, the same as the OpenStreetMap picker. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/LocationSearchBar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/LocationSearchBar.kt index 735b6801..90f36066 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/LocationSearchBar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/LocationSearchBar.kt @@ -59,6 +59,8 @@ import java.util.UUID /* * Provides a search bar that recommends places while the user types. + * + * Outstanding issues: None known. */ /** How long typing must pause before searching, so that not every letter is a request. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetAreaMap.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetAreaMap.kt index ab2baea8..136999ab 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetAreaMap.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetAreaMap.kt @@ -38,6 +38,8 @@ import org.maplibre.geojson.Polygon /* * The OpenStreetMap version of AreaMap, drawn natively with MapLibre. The circle is a polygon * layer under the marker layer. + * + * Outstanding issues: None known. */ /** The ID of the source that holds the area's circle. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetMapViews.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetMapViews.kt index 03563e75..8164e5a9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetMapViews.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/map/OpenStreetMapViews.kt @@ -68,6 +68,8 @@ import com.google.android.gms.maps.model.LatLng as GoogleLatLng * marking points. * * The tile policy is at https://operations.osmfoundation.org/policies/tiles/. + * + * Outstanding issues: None known. */ /** Zoom used by the location picker, the same as the Google picker. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ChatContactCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ChatContactCard.kt index c6568d28..c5056e7b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ChatContactCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ChatContactCard.kt @@ -31,6 +31,8 @@ import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture * top area and the fact you can't press enter to send a message and also because the profile * photo isn't shown." * - "Can you make sure the new messages stuff follows the previous app layouts." + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ConversationCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ConversationCard.kt index f5b30a77..f2ba8917 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ConversationCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/ConversationCard.kt @@ -22,6 +22,12 @@ import com.example.lambda_bbb_events.model.message.Conversation import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture import java.text.SimpleDateFormat +/* + * A preview of one conversation in the messages tab. + * + * Outstanding issues: None known. + */ + /** * Displays a conversation preview within the messaging tab. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageBubble.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageBubble.kt index 67997e20..ec5a1a97 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageBubble.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageBubble.kt @@ -28,6 +28,12 @@ import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.message.Message import java.text.SimpleDateFormat +/* + * One chat message in a conversation. + * + * Outstanding issues: None known. + */ + /** * Displays an individual message within a conversation. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageInputField.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageInputField.kt index de0f2fd3..61e8818d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageInputField.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/MessageInputField.kt @@ -29,6 +29,12 @@ import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.view.ui.components.common.formTextFieldColors +/* + * The text field and send button for writing a chat message. + * + * Outstanding issues: None known. + */ + /** * Displays a text input field and send button for messaging. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/SentMessagesSection.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/SentMessagesSection.kt new file mode 100644 index 00000000..5dee6109 --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/SentMessagesSection.kt @@ -0,0 +1,156 @@ +package com.example.lambda_bbb_events.view.ui.components.messaging + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedCard +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.produceState +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.unit.dp +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.view.ui.components.logs.formatLogTimestamp +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.flow.Flow + +/* + * The list of waitlist messages a campsite owner has sent, kept up to date as they send more. + * + * Outstanding issues: Messages are grouped by campsite, not by lottery, because logs do not + * store a lottery ID. + */ + +/** + * What the owner sees of their sent notifications: still loading, loaded, or failed. + */ +private sealed interface SentState { + data object Loading : SentState + data class Loaded(val logs: List) : SentState + data object Failed : SentState +} + +/** + * Shows the notifications a campsite owner sent, kept up to date as they send more. + * + * @param sentLogs The owner's sent notifications, newest first, each time one is added. + * @param modifier Modifier applied to the section. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "As a campsite owner, I want to view a list of all notifications I have sent." + * - "you can manage lottery and there you should be able to see your past notifications + * sent" + */ +@Composable +fun SentMessagesSection(sentLogs: Flow>, modifier: Modifier = Modifier) { + val state by produceState(SentState.Loading, sentLogs) { + try { + sentLogs.collect { value = SentState.Loaded(it) } + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { + value = SentState.Failed + } + } + + when (val current = state) { + SentState.Loading -> SentMessagesList(logs = null, modifier = modifier) + is SentState.Loaded -> SentMessagesList(logs = current.logs, modifier = modifier) + SentState.Failed -> SentMessagesList(logs = null, failed = true, modifier = modifier) + } +} + +/** + * A titled list of sent notifications, each with its text, who it reached and when. + * + * @param logs The notifications, newest first, or `null` while they load. + * @param failed Whether loading them failed. + * @param modifier Modifier applied to the list. + */ +@Composable +fun SentMessagesList(logs: List?, failed: Boolean = false, modifier: Modifier = Modifier) { + Column( + modifier = modifier.fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + Text( + text = if (logs == null) "Sent Messages" else "Sent Messages (${logs.size})", + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onBackground, + modifier = Modifier.testTag("text_sent_messages_title") + ) + + val notice = when { + failed -> "Couldn't load your sent messages." + logs == null -> "Loading sent messages..." + logs.isEmpty() -> "You haven't messaged a waitlist for this campsite yet." + else -> null + } + notice?.let { + Text( + text = it, + style = MaterialTheme.typography.bodyMedium, + color = if (failed) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.testTag("text_sent_messages_notice") + ) + } + + logs.orEmpty().forEach { SentMessageCard(it) } + } +} + +/** + * One sent notification: its text, who it reached and when it was sent. + * + * @param log The notification. + */ +@Composable +private fun SentMessageCard(log: AdminLog) { + OutlinedCard( + modifier = Modifier + .fillMaxWidth() + .testTag("card_sent_message_${log.id}"), + shape = RoundedCornerShape(12.dp), + colors = CardDefaults.outlinedCardColors(containerColor = MaterialTheme.colorScheme.surface) + ) { + Column( + modifier = Modifier.padding(12.dp), + verticalArrangement = Arrangement.spacedBy(4.dp) + ) { + Text(text = log.content, style = MaterialTheme.typography.bodyMedium) + Text( + text = "Sent to ${recipientsOf(log)}", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + Text( + text = formatLogTimestamp(log.timestamp), + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } + } +} + +/** + * Names the entrants a notification reached, falling back to how many there were when their + * names weren't saved. + * + * @param log The notification. + * @return Such as "Ed, Sam" or "3 entrants". + */ +fun recipientsOf(log: AdminLog): String { + val names = log.recipientIds.mapNotNull { id -> log.recipientNames[id]?.takeIf { it.isNotBlank() } } + if (names.size == log.recipientIds.size && names.isNotEmpty()) return names.joinToString(", ") + return if (log.recipientIds.size == 1) "1 entrant" else "${log.recipientIds.size} entrants" +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/WaitlistMessageButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/WaitlistMessageButton.kt new file mode 100644 index 00000000..308c4711 --- /dev/null +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/messaging/WaitlistMessageButton.kt @@ -0,0 +1,162 @@ +package com.example.lambda_bbb_events.view.ui.components.messaging + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.unit.dp +import com.example.lambda_bbb_events.controller.messaging.GroupMessageSender +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import kotlinx.coroutines.launch + +/* + * The Message Waitlist button and dialog an owner uses to message everyone on a lottery's + * waitlist. + * + * Outstanding issues: None known. + */ + +/** The longest message allowed, matching the limit for chat messages. */ +private const val MAX_MESSAGE_LENGTH = 2000 + +/** + * A button that lets a campsite owner send one message to everyone on a lottery's waitlist. + * It opens a dialog to write the message, and once sent shows how many entrants received it. + * The button is disabled when nobody on the waitlist can be messaged. + * + * @param entries The lottery's waitlist entries. + * @param sender Sends the message to each entrant. + * @param campsiteId The campsite the lottery is for, recorded in the admin log. + * @param campsiteName That campsite's name, recorded in the admin log. + * @param modifier Modifier applied to the button and its result text. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "As a campsite owner, I want to send notifications to entrants who have joined the + * waitlist for my campsite lottery." + * - "That's what I was thinking make group chats possible. technically it doesn't need to be + * a group chat but a group messaging system." + */ +@Composable +fun WaitlistMessageButton( + entries: List, + sender: GroupMessageSender, + campsiteId: String = "", + campsiteName: String = "", + modifier: Modifier = Modifier +) { + val scope = rememberCoroutineScope() + val recipientCount = GroupMessageSender.recipientsOf(entries).size + var showDialog by remember { mutableStateOf(false) } + var isSending by remember { mutableStateOf(false) } + var resultText by remember { mutableStateOf(null) } + + Column(modifier = modifier.fillMaxWidth()) { + Button( + onClick = { showDialog = true }, + enabled = recipientCount > 0 && !isSending, + modifier = Modifier + .fillMaxWidth() + .testTag("button_message_waitlist") + ) { + Text(if (isSending) "Sending..." else "Message Waitlist") + } + + resultText?.let { text -> + Text( + text = text, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .padding(top = 4.dp) + .testTag("text_waitlist_message_result") + ) + } + } + + if (showDialog) { + WaitlistMessageDialog( + recipientCount = recipientCount, + onDismiss = { showDialog = false }, + onSend = { content -> + showDialog = false + isSending = true + scope.launch { + resultText = sender.sendToWaitlist(entries, content, campsiteId, campsiteName).summary() + isSending = false + } + } + ) + } +} + +/** + * A dialog for writing the message sent to a lottery's waitlist. + * + * @param recipientCount How many entrants will receive the message. + * @param onDismiss Called when the dialog is cancelled. + * @param onSend Called with the message text when Send is pressed. + */ +@Composable +private fun WaitlistMessageDialog( + recipientCount: Int, + onDismiss: () -> Unit, + onSend: (String) -> Unit +) { + var content by remember { mutableStateOf("") } + val audience = if (recipientCount == 1) "1 entrant" else "$recipientCount entrants" + + AlertDialog( + onDismissRequest = onDismiss, + title = { Text("Message Waitlist") }, + text = { + Column { + Text( + text = "Sent to $audience in their chats with you.", + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.padding(bottom = 8.dp) + ) + OutlinedTextField( + value = content, + onValueChange = { if (it.length <= MAX_MESSAGE_LENGTH) content = it }, + placeholder = { Text("Write a message") }, + modifier = Modifier + .fillMaxWidth() + .heightIn(min = 120.dp) + .testTag("field_waitlist_message") + ) + } + }, + confirmButton = { + TextButton( + onClick = { onSend(content.trim()) }, + enabled = content.isNotBlank(), + modifier = Modifier.testTag("button_send_waitlist_message") + ) { + Text("Send") + } + }, + dismissButton = { + TextButton(onClick = onDismiss) { + Text("Cancel") + } + } + ) +} diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigation.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigation.kt index f35822f2..bddb7086 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigation.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigation.kt @@ -8,6 +8,8 @@ import androidx.navigation.NavController /* * Provides back navigation that cannot be triggered more than once per screen. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BookingsTypeBar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BookingsTypeBar.kt index 85253da4..20c8830b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BookingsTypeBar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/BookingsTypeBar.kt @@ -23,6 +23,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState * between active, past, and lottery reservations. * * Uses Material 3 theme colors for selected and unselected tabs. + * + * Outstanding issues: None known. */ /** Displays tabs with a selected index and reports the index the user selects. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/NavigationBar.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/NavigationBar.kt index 914f75eb..c537eb8a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/NavigationBar.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/NavigationBar.kt @@ -36,6 +36,8 @@ import androidx.navigation.compose.currentBackStackEntryAsState * and Profile screens. * * Uses the application's Material 3 theme. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/SeeAllNavigation.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/SeeAllNavigation.kt index 59d894c2..afc2a400 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/SeeAllNavigation.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/SeeAllNavigation.kt @@ -4,6 +4,12 @@ import androidx.navigation.NavController import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.view.ui.user_screens.explore.CampsiteSection +/* + * Opens the full list of campsites for one section, such as nearby or recently added. + * + * Outstanding issues: None known. + */ + /** * Opens the expanded campsite list for a selected section. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/StepStageIndicator.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/StepStageIndicator.kt index 37e57650..584f220b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/StepStageIndicator.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/navigation/StepStageIndicator.kt @@ -15,6 +15,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp +/* + * Shows which step of creating a campsite the owner is on. + * + * Outstanding issues: None known. + */ + /** * Displays a navigation indicator for the campsite * creation process. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationComponents.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationComponents.kt index 7be6fdf7..d486a953 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationComponents.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationComponents.kt @@ -20,6 +20,8 @@ import androidx.compose.ui.unit.dp /* * Defines reusable notification settings rows * for displaying notification options. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationMuteDialog.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationMuteDialog.kt index 160adb22..d4d8416f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationMuteDialog.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/notification/NotificationMuteDialog.kt @@ -18,6 +18,12 @@ import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.message.NotificationPreference +/* + * A dialog for muting a contact's notifications for a while or indefinitely. + * + * Outstanding issues: None known. + */ + /** * Represents the available notification mute options. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/DialogPrompt.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/DialogPrompt.kt index 33f4fe46..e2dfc074 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/DialogPrompt.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/DialogPrompt.kt @@ -9,6 +9,8 @@ import androidx.compose.ui.platform.testTag /* Prompts an easy to call alert dialog for more consequential requests + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/ProfileComponents.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/ProfileComponents.kt index d0d020af..0c31b94f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/ProfileComponents.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/ProfileComponents.kt @@ -19,6 +19,8 @@ import androidx.compose.ui.unit.dp /* * Defines reusable profile navigation rows and section headers * for organizing user profile options. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt index eb40185f..31ff4a89 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/profile/TogglableButton.kt @@ -21,6 +21,8 @@ import androidx.compose.ui.unit.dp /* Provides togglable buttons to be re-used throughout the app to switch between options + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/rating/RatingComposable.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/rating/RatingComposable.kt index aeb045c2..cb871b24 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/rating/RatingComposable.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/rating/RatingComposable.kt @@ -28,6 +28,8 @@ import kotlin.math.roundToInt * review counts, and selecting star ratings. * * Uses the application's Material 3 theme. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/BookedEntrantCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/BookedEntrantCard.kt index 5fd4d43e..182de335 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/BookedEntrantCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/BookedEntrantCard.kt @@ -32,6 +32,12 @@ import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults +/* + * A card showing the owner an entrant who booked their campsite. + * + * Outstanding issues: None known. + */ + /** * A card to display to the owner that has information of an entrant who booked a campsite. * It shows the entrant's profile picture, name, the reservation status, the reserved dates, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/OwnerReservationCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/OwnerReservationCard.kt index a32b0a23..8f3a706c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/OwnerReservationCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/reservation/OwnerReservationCard.kt @@ -35,6 +35,12 @@ import java.time.LocalDate import java.time.format.DateTimeFormatter import java.util.Locale +/* + * A card showing the owner one reservation at their campsite. + * + * Outstanding issues: None known. + */ + /** * A card for info on reservation of an entrant on the owner's campsite. It shows the name * of the entrant, the status of the reservation, the reservation dates, the number of guests, diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactableReviewCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactableReviewCard.kt index ecb24316..c727c370 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactableReviewCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactableReviewCard.kt @@ -26,14 +26,16 @@ import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.controller.ReviewReactionController -import com.example.lambda_bbb_events.controller.ReviewReplyController +import com.example.lambda_bbb_events.controller.review.ReviewReactionController +import com.example.lambda_bbb_events.controller.review.ReviewReplyController import com.example.lambda_bbb_events.model.review.Review import com.example.lambda_bbb_events.model.user.User import kotlinx.coroutines.launch /* * Shows a campsite review with the emoji reactions around it and the replies under it. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpots.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpots.kt index c5480fdb..cf53337b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpots.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpots.kt @@ -5,6 +5,8 @@ import kotlin.random.Random /* * Works out where emoji reactions sit around the edge of a review card. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewCard.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewCard.kt index 259a4664..dcb59386 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewCard.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewCard.kt @@ -33,6 +33,12 @@ import java.time.format.DateTimeFormatter import java.util.Date import java.util.Locale +/* + * A card showing one review: its author, date, stars and comment. + * + * Outstanding issues: None known. + */ + /** * Displays a review: who wrote it and when, their stars, and their comment. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewForm.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewForm.kt index 2d6c7122..366c48b6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewForm.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewForm.kt @@ -30,6 +30,12 @@ import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.model.review.Review import com.example.lambda_bbb_events.view.ui.components.rating.PickRatingStars +/* + * A form that opens in place to write or edit a review. + * + * Outstanding issues: None known. + */ + /** * Displays a dropdown that opens in place to write a review, or edit one that was already * written. Closing it by its heading keeps what was entered, so it can be opened again. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReactions.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReactions.kt index a9fbe8a4..70e16907 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReactions.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReactions.kt @@ -24,6 +24,8 @@ import kotlin.math.roundToInt /* * Shows the emoji reactions around a campsite review, and the tray to pick one. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReplies.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReplies.kt index f57ffdbe..ddda5056 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReplies.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewReplies.kt @@ -31,6 +31,8 @@ import kotlinx.coroutines.launch /* * Shows the replies under a campsite review, and the box to write one. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewSection.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewSection.kt index 07bc9064..d9f6663b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewSection.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/components/review/ReviewSection.kt @@ -24,6 +24,12 @@ import com.example.lambda_bbb_events.model.review.Review import com.example.lambda_bbb_events.view.ui.components.profile.ShowAlertDialog import kotlinx.coroutines.launch +/* + * The reviews section of a campsite's page, with reactions, replies and the review form. + * + * Outstanding issues: None known. + */ + /** How many reviews are shown before the rest are asked for. */ private const val REVIEWS_SHOWN_AT_FIRST = 3 diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateLotteryScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateLotteryScreen.kt index 85d4ac88..f129ce29 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateLotteryScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateLotteryScreen.kt @@ -35,6 +35,12 @@ import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import kotlinx.coroutines.launch import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction +/* + * Screen where a campsite owner creates a lottery for one of their campsites. + * + * Outstanding issues: None known. + */ + /** * Screen where a campsite owner can create a lottery for their campsite. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateMultipleCampsiteLotteryScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateMultipleCampsiteLotteryScreen.kt index 45c1adfe..61888fab 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateMultipleCampsiteLotteryScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/CreateMultipleCampsiteLotteryScreen.kt @@ -56,6 +56,13 @@ import kotlinx.coroutines.launch import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction import com.example.lambda_bbb_events.view.ui.components.rating.RatingSummary +/* + * Screen where a campsite owner creates a lottery covering several campsites, including other + * owners' campsites. + * + * Outstanding issues: None known. + */ + /** * Screen where a campsite owner can create a lottery for their campsite. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditCampsiteScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditCampsiteScreen.kt index 5293480e..2271a795 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditCampsiteScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditCampsiteScreen.kt @@ -39,7 +39,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.CampsitePhotoController +import com.example.lambda_bbb_events.controller.campsite.CampsitePhotoController import com.example.lambda_bbb_events.model.image.ImageMetaData import com.example.lambda_bbb_events.view.ui.components.campsite.PhotoManager import com.example.lambda_bbb_events.view.ui.components.campsite.TagEditor @@ -58,6 +58,8 @@ import kotlinx.coroutines.launch /* * Provides a screen for editing campsite details. * Allows owners to save changes or cancel editing. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditLotteryScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditLotteryScreen.kt index 83bfd1a8..7d217ad3 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditLotteryScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/EditLotteryScreen.kt @@ -44,6 +44,12 @@ import java.time.ZoneId import java.util.Date import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction +/* + * Screen where a campsite owner edits one of their lotteries. + * + * Outstanding issues: None known. + */ + /** * Screen where a campsite owner can edit a lottery for their campsite. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/LotteryRequestsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/LotteryRequestsScreen.kt index 65bb658e..75192a39 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/LotteryRequestsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/LotteryRequestsScreen.kt @@ -40,6 +40,12 @@ import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.lottery.formatDateRange import kotlinx.coroutines.launch +/* + * Screen where an owner accepts or declines lotteries other owners added their campsites to. + * + * Outstanding issues: None known. + */ + /** * Screen where an owner accepts or declines multiple campsite lotteries that other * owners added their campsites to. Declining cancels the whole lottery. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ManageLotteryScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ManageLotteryScreen.kt index 2dfab628..41a028b4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ManageLotteryScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ManageLotteryScreen.kt @@ -17,20 +17,25 @@ import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.LotteryFilter +import com.example.lambda_bbb_events.controller.lottery.LotteryFilter import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.lottery.OwnerLotteryCard import com.example.lambda_bbb_events.view.ui.components.common.CampsiteThumbnail +import com.example.lambda_bbb_events.view.ui.components.messaging.SentMessagesSection /* * Defines the campsite owner's lottery management screen. + * + * Outstanding issues: Sent messages are grouped by campsite, not by lottery, because logs do + * not store a lottery ID. */ /** @@ -225,6 +230,13 @@ fun OwnerManageLotteryScreen( LotterySection("Past Lotteries", pastLotteries, allLotteries, navController, controllers) LotterySection("Cancelled Lotteries", cancelledLotteries, allLotteries, navController, controllers) + HorizontalDivider(Modifier.padding(top = 5.dp)) + SentMessagesSection( + sentLogs = remember(campsiteId) { + controllers.adminLogs.observeSentBy(controllers.users.deviceId, campsiteId) + } + ) + Spacer(modifier = Modifier.height(50.dp)) } } diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/MyCampsitesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/MyCampsitesScreen.kt index 689aace4..d5355423 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/MyCampsitesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/MyCampsitesScreen.kt @@ -38,6 +38,8 @@ import kotlinx.coroutines.launch * navigation for creating campsites and managing lotteries. * * Owner registration before campsite creation might need some work. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerCampsiteDetailsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerCampsiteDetailsScreen.kt index 45a966b9..8ffd104c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerCampsiteDetailsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerCampsiteDetailsScreen.kt @@ -31,7 +31,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.ReservationFilter +import com.example.lambda_bbb_events.controller.reservation.ReservationFilter import com.example.lambda_bbb_events.model.reservation.Reservation import com.example.lambda_bbb_events.model.services.generateQR import com.example.lambda_bbb_events.view.ui.components.rating.RatingSummary @@ -45,6 +45,8 @@ import kotlinx.coroutines.launch /* * Displays campsite details and provides management actions * for owners in managing lotteries. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerLotteryDetailsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerLotteryDetailsScreen.kt index a06305b5..bd4b64e6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerLotteryDetailsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/OwnerLotteryDetailsScreen.kt @@ -37,17 +37,26 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.LotteryFilter -import com.example.lambda_bbb_events.controller.LotteryPhase +import com.example.lambda_bbb_events.controller.lottery.LotteryFilter +import com.example.lambda_bbb_events.controller.lottery.LotteryPhase import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.lottery.WaitlistEntry import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.lottery.EntryStatusPill import com.example.lambda_bbb_events.view.ui.components.lottery.OwnerLotteryCard import com.example.lambda_bbb_events.view.ui.components.lottery.formatSingleDate +import com.example.lambda_bbb_events.view.ui.components.messaging.WaitlistMessageButton +import com.example.lambda_bbb_events.controller.messaging.GroupMessageSender import kotlinx.coroutines.launch import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction +/* + * Screen showing an owner one lottery and the entrants on its waitlist, where they can message + * the waitlist. + * + * Outstanding issues: Refreshing reloads the lottery, every entry and every entrant's name. + */ + /** * Displays a lottery and the list of entrants who joined its waitlist. * @@ -231,6 +240,18 @@ fun OwnerLotteryDetailsScreen( ) } + if (entries.isNotEmpty()) { + item { + val campsiteId = currentLottery.campsiteIds.firstOrNull().orEmpty() + WaitlistMessageButton( + entries = entries, + sender = remember { GroupMessageSender(controllers.users) }, + campsiteId = campsiteId, + campsiteName = controllers.campsites.getCampsite(campsiteId)?.campsiteName.orEmpty() + ) + } + } + if (entries.isEmpty()) { item { Text( diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ViewBookedDatesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ViewBookedDatesScreen.kt index 44b6aecd..06684272 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ViewBookedDatesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/owner_screens/ViewBookedDatesScreen.kt @@ -22,7 +22,7 @@ import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import java.time.YearMonth import com.example.lambda_bbb_events.view.ui.components.common.CampsiteThumbnail import androidx.compose.ui.draw.clip -import com.example.lambda_bbb_events.controller.ReservationFilter +import com.example.lambda_bbb_events.controller.reservation.ReservationFilter import com.example.lambda_bbb_events.model.reservation.Reservation import com.example.lambda_bbb_events.model.reservation.ReservationStatus import com.example.lambda_bbb_events.model.user.User @@ -31,19 +31,14 @@ import kotlinx.coroutines.launch /* - * Allows users to select campsite reservation dates - * and guest counts before registration. + * Screen showing a campsite owner their campsite's booked dates and the entrants who booked + * them. * - * TODO: Integrate the campsite's availability schedule - * into calendar selection and reservation validation. + * Outstanding issues: None known. */ /** - * Displays campsite information and a form for selecting - * reservation dates and guest count. - * - * Navigates to the registration status screen when the - * entered dates and guest count pass validation. + * Displays a campsite's details, its booked dates, and the entrants who have booked it. * * @param navController Handles screen navigation. * @param controllers Retrieves campsite information. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Color.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Color.kt index 708bf72e..11ed31bb 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Color.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Color.kt @@ -7,6 +7,8 @@ import androidx.compose.ui.graphics.Color * * Includes light theme colors, dark theme colors, * and booking/lottery status colors. + * + * Outstanding issues: None known. */ // ======================================== diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Theme.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Theme.kt index 10bc8e1e..6273abd4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Theme.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Theme.kt @@ -18,6 +18,8 @@ import androidx.compose.ui.platform.LocalContext * * Supports customized Coastal Blue colors * for both light and dark modes. + * + * Outstanding issues: None known. */ // ======================================== diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Type.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Type.kt index bbc7fff5..ac829ad8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Type.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/theme/Type.kt @@ -7,6 +7,12 @@ import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp +/* + * The app's Material 3 text styles. + * + * Outstanding issues: None known. + */ + /** * Defines the application's Material 3 typography styles. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/ActiveBookingsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/ActiveBookingsScreen.kt index b2b6d7fb..53678f4e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/ActiveBookingsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/ActiveBookingsScreen.kt @@ -39,6 +39,12 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.launch import java.time.LocalDate +/* + * Screen listing the user's active reservations, where they can cancel one. + * + * Outstanding issues: None known. + */ + /** * Displays the user's active campsite reservations. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteCheckAvailabilityScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteCheckAvailabilityScreen.kt index f13a802c..4eb6c95f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteCheckAvailabilityScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteCheckAvailabilityScreen.kt @@ -33,8 +33,8 @@ import androidx.compose.ui.draw.clip * Allows users to select campsite reservation dates * and guest counts before registration. * - * TODO: Integrate the campsite's availability schedule - * into calendar selection and reservation validation. + * Outstanding issues: The calendar does not mark the campsite's unavailable dates yet, so + * every date can be picked here. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteWinnerAvailabilityScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteWinnerAvailabilityScreen.kt index 6ce06059..a4a68e18 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteWinnerAvailabilityScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/CampsiteWinnerAvailabilityScreen.kt @@ -27,10 +27,16 @@ import java.time.LocalDate import java.time.YearMonth import com.example.lambda_bbb_events.view.ui.components.common.CampsiteThumbnail import androidx.compose.ui.draw.clip -import com.example.lambda_bbb_events.controller.ReservationFilter +import com.example.lambda_bbb_events.controller.reservation.ReservationFilter import com.example.lambda_bbb_events.view.ui.components.campsite.VerticalCampsiteCard import kotlinx.coroutines.launch +/* + * Screen where a lottery winner chooses the dates to reserve. + * + * Outstanding issues: None known. + */ + /** * Displays campsite information and a form for selecting their * reservation dates. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/LotteryBookingsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/LotteryBookingsScreen.kt index 3daab331..44bc56a0 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/LotteryBookingsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/LotteryBookingsScreen.kt @@ -21,6 +21,12 @@ import com.example.lambda_bbb_events.view.ui.components.lottery.LotteryEntryCard import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigationBar import kotlinx.coroutines.CancellationException +/* + * Screen listing the user's lottery entries. + * + * Outstanding issues: None known. + */ + /** * Displays the user's lottery bookings. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/PastBookingsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/PastBookingsScreen.kt index 1ee11beb..27f7b198 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/PastBookingsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/PastBookingsScreen.kt @@ -21,6 +21,12 @@ import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.ui.theme.BookingsTypeBar import java.time.LocalDate +/* + * Screen listing the user's past reservations. + * + * Outstanding issues: None known. + */ + /** * Displays the user's past campsite reservations. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/BookingRecieptScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/BookingRecieptScreen.kt index f392f812..331d8ad8 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/BookingRecieptScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/BookingRecieptScreen.kt @@ -13,6 +13,13 @@ import androidx.navigation.NavController import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigationBar +/* + * Screen showing the receipt of a confirmed reservation. + * + * Outstanding issues: The file name is misspelled ("Reciept"); the screen inside is named + * BookingReceiptScreen. + */ + /** * Displays the receipt of a confirmed campsite reservation. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryAvailabilityScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryAvailabilityScreen.kt index db9c74d5..8d47cb5c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryAvailabilityScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryAvailabilityScreen.kt @@ -17,6 +17,12 @@ import com.example.lambda_bbb_events.view.ui.components.lottery.RegistrationStat import com.example.lambda_bbb_events.view.ui.theme.bookingStatusColors import java.time.LocalDate +/* + * Screen showing a campsite's lottery and whether the user can join it. + * + * Outstanding issues: None known. + */ + /** * Displays the lottery availability for a selected campsite. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryEntered.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryEntered.kt index 46d09acb..427f3799 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryEntered.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/LotteryEntered.kt @@ -23,6 +23,8 @@ import java.time.LocalDate /* * Displays the lottery entry confirmation screen, * including campsite and reservation information. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/RegistrationStatusScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/RegistrationStatusScreen.kt index 698a91e8..ff0c0145 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/RegistrationStatusScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/bookings/lottery/RegistrationStatusScreen.kt @@ -21,6 +21,12 @@ import kotlinx.coroutines.launch import java.time.LocalDate import java.time.ZoneId +/* + * Screen showing the status of the user's lottery entry. + * + * Outstanding issues: None known. + */ + /** * Displays the registration status of a waitlist entry. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateBasicInfoStep.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateBasicInfoStep.kt index bf7fc34d..0e71615d 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateBasicInfoStep.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateBasicInfoStep.kt @@ -59,6 +59,12 @@ import com.example.lambda_bbb_events.view.ui.components.campsite.TagEditor import com.example.lambda_bbb_events.view.ui.components.common.FormTextFieldWithTitle import com.example.lambda_bbb_events.view.ui.components.common.PhotoFocusDialog +/* + * The first step of creating a campsite: its name, description, occupancy, photos and tags. + * + * Outstanding issues: None known. + */ + /** Most digits the max occupancy can have, so the value always fits in an Int. */ internal const val MAX_OCCUPANCY_DIGITS = 4 diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateCampsiteFormState.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateCampsiteFormState.kt index 231b4b4f..03af576f 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateCampsiteFormState.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateCampsiteFormState.kt @@ -8,6 +8,12 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.geometry.Offset +/* + * The state shared by the three steps of the campsite creation form. + * + * Outstanding issues: None known. + */ + /** * Shared state for the three steps of the campsite creation form. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLocationStep.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLocationStep.kt index 93780957..3347c0dc 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLocationStep.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLocationStep.kt @@ -20,6 +20,12 @@ import com.example.lambda_bbb_events.view.ui.components.map.LocationSearchBar import com.example.lambda_bbb_events.view.ui.components.map.MapMove import com.google.android.gms.maps.model.LatLng +/* + * The second step of creating a campsite: choosing where it is. + * + * Outstanding issues: None known. + */ + /** * The second step of creating a campsite, for choosing where it is. The location can be * searched for by name or tapped on the map, and its address can then be edited. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLotteryStep.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLotteryStep.kt index 78f85143..a85c8469 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLotteryStep.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateLotteryStep.kt @@ -26,6 +26,12 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import com.example.lambda_bbb_events.view.ui.components.calendar.DatePickerField +/* + * The third step of creating a campsite: optionally setting up its first lottery. + * + * Outstanding issues: None known. + */ + /** Most digits the number of spots can have, so the value always fits in an Int. */ internal const val MAX_SPOTS_DIGITS = 4 diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateScreen.kt index 3a9be895..279cf427 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/create/CreateScreen.kt @@ -36,6 +36,12 @@ import com.example.lambda_bbb_events.model.services.decodePhoto import androidx.compose.ui.geometry.Offset +/* + * Runs the three-step campsite creation form and saves the campsite and its lottery. + * + * Outstanding issues: None known. + */ + /** * Coordinates the three-step campsite creation form and saves the campsite * and associated lottery when the owner presses Done. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteDetailsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteDetailsScreen.kt index a092a079..e435427a 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteDetailsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteDetailsScreen.kt @@ -36,6 +36,8 @@ import com.example.lambda_bbb_events.view.ui.components.map.CampsiteMap /* * Displays campsite information, including ratings, location, * tags, description, and reservation availability. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteSection.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteSection.kt index da2a029f..c748a453 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteSection.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/CampsiteSection.kt @@ -1,5 +1,11 @@ package com.example.lambda_bbb_events.view.ui.user_screens.explore +/* + * The campsite lists users can expand to see in full. + * + * Outstanding issues: None known. + */ + /** * Categories of campsite lists that users can expand. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreDefaultScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreDefaultScreen.kt index 760af6a3..fc38ea35 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreDefaultScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreDefaultScreen.kt @@ -38,6 +38,12 @@ import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.common.SearchBar import com.example.lambda_bbb_events.view.ui.components.campsite.VerticalCampsiteCard +/* + * The Explore screen's list view of campsites, with search and filters. + * + * Outstanding issues: None known. + */ + /** * Displays the campsite exploration screen. * @@ -60,8 +66,6 @@ fun ExploreDefaultScreen( mutableStateOf(false) } - val results = controllers.campsites.getSearchResults() - Scaffold( containerColor = MaterialTheme.colorScheme.background, bottomBar = { @@ -149,6 +153,8 @@ fun ExploreDefaultScreen( Spacer(modifier = Modifier.height(2.dp)) // Campsite search results. + val results = controllers.campsites.getSearchResults() + LazyColumn( modifier = Modifier .weight(1f) diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreMapScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreMapScreen.kt index 76fa5d6e..f4ccc878 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreMapScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/ExploreMapScreen.kt @@ -41,6 +41,13 @@ import com.example.lambda_bbb_events.view.ui.components.campsite.VerticalCardSec import com.example.lambda_bbb_events.view.ui.components.map.CampsiteMap import com.example.lambda_bbb_events.view.ui.components.navigation.navigateToSeeAll +/* + * The Explore screen's map view of campsites. + * + * Outstanding issues: The Nearby list shows every active campsite; it is not yet narrowed to + * campsites near the map's location. + */ + /** * Displays the campsite exploration screen with an interactive map. * @@ -68,7 +75,6 @@ fun ExploreMapScreen( mutableStateOf(false) } - // TODO: Filter campsites based on the selected map location. val nearbyCampsites = controllers.campsites .activeCampsites.values.toList() diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRCode.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRCode.kt index 6f650243..1c0f4bf9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRCode.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRCode.kt @@ -24,6 +24,12 @@ import com.example.lambda_bbb_events.model.services.saveBitmapToGallery import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction +/* + * Shows a campsite's QR code full screen, with an option to save it. + * + * Outstanding issues: None known. + */ + /** * Displays a full-screen view for a campsite's QR Code with option to download. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRScanner.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRScanner.kt index f1480c1c..9723a448 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRScanner.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/QRScanner.kt @@ -31,6 +31,12 @@ import com.example.lambda_bbb_events.model.services.scanAndGoToPage import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigationBar +/* + * Scans a campsite's QR code and opens its details page. + * + * Outstanding issues: None known. + */ + /** * Screen that launches the QR code scanner to scan a campsite QR code and navigate to its details page. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/SeeAllCampsitesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/SeeAllCampsitesScreen.kt index b4995093..f77b239b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/SeeAllCampsitesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/explore/SeeAllCampsitesScreen.kt @@ -14,6 +14,12 @@ import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.view.ui.components.campsite.SeeAllCampsiteCard import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle +/* + * Screen listing every campsite in one section. + * + * Outstanding issues: None known. + */ + /** * Displays all campsites belonging to a selected section. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/home/HomeScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/home/HomeScreen.kt index 6bf5bda7..95837411 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/home/HomeScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/home/HomeScreen.kt @@ -42,6 +42,8 @@ import com.example.lambda_bbb_events.view.ui.user_screens.explore.CampsiteSectio * Defines the home screen with campsite searching, * filtering, and featured listing sections. * + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatRoute.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatRoute.kt index 819150e0..cc5348c2 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatRoute.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatRoute.kt @@ -16,6 +16,12 @@ import com.example.lambda_bbb_events.model.repository.MessageRepository import kotlinx.coroutines.CancellationException import kotlinx.coroutines.delay +/* + * Loads a conversation and opens the chat screen for it. + * + * Outstanding issues: None known. + */ + /** * Loads conversation information and displays the chat screen. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatScreen.kt index da7d9e99..c342c164 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/ChatScreen.kt @@ -11,7 +11,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.controller.MessageController +import com.example.lambda_bbb_events.controller.messaging.MessageController import com.example.lambda_bbb_events.model.message.Message import com.example.lambda_bbb_events.view.ui.components.profile.ShowAlertDialog import androidx.navigation.NavController @@ -22,6 +22,13 @@ import com.example.lambda_bbb_events.view.ui.components.messaging.MessageInputFi import kotlinx.coroutines.CancellationException import kotlinx.coroutines.launch +/* + * Screen showing a conversation's messages, where its participants can send and delete + * messages. + * + * Outstanding issues: None known. + */ + /** * Displays messages belonging to a conversation and allows * authorized users to send new messages. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContacts.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContacts.kt index 68db097f..e326f875 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContacts.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContacts.kt @@ -20,6 +20,8 @@ import com.example.lambda_bbb_events.model.user.UserRole * is to fix the notification page so that the spacing looks right." * - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate * chats per admin". + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessagesTab.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessagesTab.kt index b3c871d6..fcaed5e6 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessagesTab.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessagesTab.kt @@ -20,7 +20,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.navigation.NavController -import com.example.lambda_bbb_events.controller.MessageController +import com.example.lambda_bbb_events.controller.messaging.MessageController import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture import com.example.lambda_bbb_events.view.ui.components.messaging.ConversationCard import com.example.lambda_bbb_events.view.ui.components.notification.NotificationRow @@ -39,6 +39,8 @@ import kotlinx.coroutines.launch * is to fix the notification page so that the spacing looks right." * - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate * chats per admin". + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt index e439e234..7a76c06c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationSettingsTab.kt @@ -13,8 +13,8 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.controller.NotificationController -import com.example.lambda_bbb_events.controller.NotificationPreferenceController +import com.example.lambda_bbb_events.controller.notification.NotificationController +import com.example.lambda_bbb_events.controller.notification.NotificationPreferenceController import com.example.lambda_bbb_events.model.message.NotificationPreference import com.example.lambda_bbb_events.model.notifications.NotificationCategory import com.example.lambda_bbb_events.model.notifications.NotificationMode @@ -26,6 +26,12 @@ import com.example.lambda_bbb_events.view.ui.components.notification.Notificatio import kotlinx.coroutines.CancellationException import kotlinx.coroutines.launch +/* + * The notification settings tab, organized by people and by notification category. + * + * Outstanding issues: None known. + */ + /** * Displays notification settings organized by people * and notification categories. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsScreen.kt index 5e8b813c..4f743d8c 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsScreen.kt @@ -8,8 +8,8 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.navigation.NavController -import com.example.lambda_bbb_events.controller.MessageController -import com.example.lambda_bbb_events.controller.NotificationPreferenceController +import com.example.lambda_bbb_events.controller.messaging.MessageController +import com.example.lambda_bbb_events.controller.notification.NotificationPreferenceController import com.example.lambda_bbb_events.model.message.Conversation import com.example.lambda_bbb_events.model.repository.MessagingAccessRepository import com.example.lambda_bbb_events.model.user.User @@ -18,7 +18,13 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigat import kotlinx.coroutines.CancellationException import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOf -import com.example.lambda_bbb_events.controller.NotificationController +import com.example.lambda_bbb_events.controller.notification.NotificationController + +/* + * Screen with the user's conversations, notification history and notification settings. + * + * Outstanding issues: None known. + */ /** * Displays the user's conversations and notification settings. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt index c97c065d..06773a24 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/NotificationsUpdatesTab.kt @@ -10,11 +10,17 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.example.lambda_bbb_events.controller.NotificationController +import com.example.lambda_bbb_events.controller.notification.NotificationController import com.example.lambda_bbb_events.model.notifications.NotificationHistory import java.text.DateFormat import java.util.Date +/* + * The tab listing the user's system notification history. + * + * Outstanding issues: None known. + */ + /** * Displays the current user's system notification history. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/OwnerCampers.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/OwnerCampers.kt index 8d85fb1d..39179400 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/OwnerCampers.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/OwnerCampers.kt @@ -1,7 +1,7 @@ package com.example.lambda_bbb_events.view.ui.user_screens.notification import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.controller.LotteryFilter +import com.example.lambda_bbb_events.controller.lottery.LotteryFilter import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.lottery.LotteryStatus import com.example.lambda_bbb_events.model.lottery.WaitlistStatus @@ -10,6 +10,8 @@ import com.example.lambda_bbb_events.model.lottery.WaitlistStatus * Finds the campers a campsite owner can start a conversation with (US 02.12.01). Everyone * who reserves a campsite entered its lottery first, so the owner's lottery entrants include * everyone reserving their campsites. + * + * Outstanding issues: None known. */ /** Entry statuses whose campers lost their messaging access to the owner. */ diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/AppPoliciesScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/AppPoliciesScreen.kt index 060e8b8c..56c787a9 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/AppPoliciesScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/AppPoliciesScreen.kt @@ -22,6 +22,8 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackA /* * Displays app policy and guidelines. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/EditProfileScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/EditProfileScreen.kt index 169f1ee4..87d501d7 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/EditProfileScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/EditProfileScreen.kt @@ -55,6 +55,8 @@ import java.util.UUID /* * Provides a screen for editing the current user's profile. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt index 1508f833..dfc197f4 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/NotificationsToggleScreen.kt @@ -34,6 +34,12 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigat import com.example.lambda_bbb_events.view.ui.components.profile.ToggleButton import kotlinx.coroutines.launch +/* + * Screen where the user opts in to or out of notifications. + * + * Outstanding issues: None known. + */ + /** * Lets the signed-in user opt in to or out of notifications (US 01.10.01). * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ProfileScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ProfileScreen.kt index 34840f6c..54cfe542 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ProfileScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ProfileScreen.kt @@ -42,7 +42,7 @@ import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture /* * Displays the current user's profile information and account settings. * - * TODO: no test tags for log out dialog yet + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt index c3f47793..3b355e6b 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/SettingsScreen.kt @@ -41,6 +41,8 @@ import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture * Test tags: each row is "settings_" (for example "settings_log_out"), and the * dialogs are "dialog_log_out" and "dialog_delete_account", with "_confirm" and "_cancel" * added for their buttons. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt index 9fb80085..c5a5686e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/profile/ThemeToggleScreen.kt @@ -14,6 +14,8 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigat import com.example.lambda_bbb_events.view.ui.components.profile.ChoiceToggle /* Provides togglable buttons to switch between light mode, dark mode, and Android's setting + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/LoginScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/LoginScreen.kt index 7811c66b..bff6a0dd 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/LoginScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/LoginScreen.kt @@ -34,6 +34,8 @@ import kotlinx.coroutines.launch /* * Lets a user log back in to the account on this device after logging out. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/RuleConfirmScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/RuleConfirmScreen.kt index 1650bca9..0895758e 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/RuleConfirmScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/RuleConfirmScreen.kt @@ -18,6 +18,13 @@ import com.example.lambda_bbb_events.view.ui.theme.bookingStatusColors import java.time.LocalDate import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction +/* + * Screen where an entrant confirms the campsite rules and lottery policies before booking. + * + * Outstanding issues: There is no dedicated message for a lottery whose registration has + * closed. + */ + /** * Displays campsite rules and lottery service policies for user confirmation. * @@ -25,9 +32,6 @@ import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackA * Confirming joins the lottery and navigates to the lottery entered screen, * while declining returns to the previous screen. * - * TODO: Display a message when lottery registration is closed. - * TODO: Finalize the lottery service policy information. - * * @param navController The [NavController] used for navigation. * @param controllers The [AppControllers] used to access campsite and lottery info. * @param campsiteId The ID of the selected campsite. diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/SignupScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/SignupScreen.kt index 74f7d8f9..e8cdeddf 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/SignupScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/SignupScreen.kt @@ -34,6 +34,12 @@ import com.example.lambda_bbb_events.view.ui.components.common.PhoneNumberFieldW import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle import kotlinx.coroutines.launch +/* + * Screen for creating an account. + * + * Outstanding issues: None known. + */ + /** * Displays the account registration screen. * diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/WelcomeScreen.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/WelcomeScreen.kt index ca6e5824..0952ed48 100644 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/WelcomeScreen.kt +++ b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/WelcomeScreen.kt @@ -22,6 +22,8 @@ import com.example.lambda_bbb_events.view.ui.components.common.AppLogo /* * The first screen shown to a device without an account, where the user picks * between logging in and signing up. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/test.kt b/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/test.kt deleted file mode 100644 index f4211b18..00000000 --- a/code/app/src/main/java/com/example/lambda_bbb_events/view/ui/user_screens/signup/test.kt +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.lambda_bbb_events.view.ui.user_screens.signup - -import androidx.compose.foundation.layout.Box -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.testTag -import androidx.navigation.NavController -import com.example.lambda_bbb_events.controller.AppControllers -import com.example.lambda_bbb_events.view.ui.components.common.ScreenTitle -import com.example.lambda_bbb_events.view.ui.components.navigation.BottomNavigationBar - -/* - * A Test screen to put in place for work in progress navigation screens - * - * TODO: Delete after app is done - */ - -/** - * @param navController The [NavController] used to navigate between screens. - * @param controllers The [AppControllers] instance used to retrieve user information. - */ - -@Composable -fun Test_screen( - navController: NavController, - controllers: AppControllers -) { - val previousPage = navController.previousBackStackEntry - ?.destination - ?.route ?: "Unknown" - Scaffold( - containerColor = MaterialTheme.colorScheme.background, - bottomBar = { - BottomNavigationBar(navController) - } - ) - { innerPadding -> - Box( - modifier = Modifier - .fillMaxSize() - .padding(innerPadding) - .testTag("test_nav"), - contentAlignment = Alignment.Center - ) { - Text( - text = "This page is currently under development!. Sorry! ;-;", - style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onBackground, - textAlign = TextAlign.Center - ) - } - } - ScreenTitle( - title = "Came from $previousPage", - navController = navController, - showNotifications = false, - showBack = true - ) -} diff --git a/code/app/src/main/res/xml/data_extraction_rules.xml b/code/app/src/main/res/xml/data_extraction_rules.xml index 9ee9997b..79c56928 100644 --- a/code/app/src/main/res/xml/data_extraction_rules.xml +++ b/code/app/src/main/res/xml/data_extraction_rules.xml @@ -5,7 +5,7 @@ --> - diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/AdminLogControllerSyncUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/AdminLogControllerSyncUnitTest.kt new file mode 100644 index 00000000..45816c33 --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/AdminLogControllerSyncUnitTest.kt @@ -0,0 +1,67 @@ +package com.example.lambda_bbb_events.controller.admin + +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.admin.LogType +import com.example.lambda_bbb_events.model.local.InMemoryNotificationLogStore +import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertEquals +import org.junit.Test + +/* + * Unit tests for how AdminLogController copies notification logs from the database into its + * local copy. + * + * Outstanding issues: None known. + */ + +class AdminLogControllerSyncUnitTest { + private val repository = mockk() + private val store = InMemoryNotificationLogStore() + + /** Makes a log with [id] sent at [timestamp]. */ + private fun log(id: String, timestamp: Long) = AdminLog(id = id, timestamp = timestamp) + + @Test + fun syncCopiesEachBatchIntoTheLocalCopy() = runTest { + val controller = AdminLogController(repository, store, StandardTestDispatcher(testScheduler)) + every { repository.observeNotificationLogsSince(0L) } returns flowOf( + listOf(log("a", 1), log("b", 2)), + listOf(log("c", 3)) + ) + + controller.syncNotificationLogs() + + assertEquals(listOf("c", "b", "a"), controller.getLogs(LogType.NOTIFICATION).map { it.id }) + assertEquals(2, controller.syncedCount) + } + + @Test + fun syncContinuesFromTheNewestSavedLog() = runTest { + store.upsert(listOf(log("old", 50))) + val controller = AdminLogController(repository, store, StandardTestDispatcher(testScheduler)) + every { repository.observeNotificationLogsSince(50L) } returns flowOf(emptyList()) + + controller.syncNotificationLogs() + + verify { repository.observeNotificationLogsSince(50L) } + } + + @Test + fun changedLogReplacesItsOldCopy() = runTest { + val controller = AdminLogController(repository, store, StandardTestDispatcher(testScheduler)) + every { repository.observeNotificationLogsSince(0L) } returns flowOf( + listOf(log("a", 1).copy(content = "first")), + listOf(log("a", 1).copy(content = "second")) + ) + + controller.syncNotificationLogs() + + assertEquals(listOf("second"), controller.getLogs(LogType.NOTIFICATION).map { it.content }) + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/AdminLotteryControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/AdminLotteryControllerUnitTest.kt similarity index 90% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/AdminLotteryControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/AdminLotteryControllerUnitTest.kt index 20156f35..c48340e6 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/AdminLotteryControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/AdminLotteryControllerUnitTest.kt @@ -1,10 +1,16 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.admin import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for AdminLotteryController running lottery draws through Cloud Functions. + * + * Outstanding issues: None known. + */ + /** * Unit tests for [AdminLotteryController]. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/LogPagerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/LogPagerUnitTest.kt new file mode 100644 index 00000000..f791938b --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/admin/LogPagerUnitTest.kt @@ -0,0 +1,102 @@ +package com.example.lambda_bbb_events.controller.admin + +import com.example.lambda_bbb_events.model.admin.AdminLog +import com.example.lambda_bbb_events.model.local.InMemoryNotificationLogStore +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test + +/* + * Unit tests for LogPager paging and searching the local notification logs. + * + * Outstanding issues: None known. + */ + +class LogPagerUnitTest { + private val store = InMemoryNotificationLogStore() + private val pager = LogPager(store, pageSize = 2) + + /** Five logs, log-5 newest; log-2 and log-4 mention "raccoon". */ + @Before + fun setup() { + store.upsert( + (1..5).map { number -> + AdminLog( + id = "log-$number", + timestamp = number.toLong(), + content = if (number % 2 == 0) "Raccoon sighting" else "Gates open" + ) + } + ) + } + + /** The IDs of the logs on the current page matching [query]. */ + private fun pageIds(query: String = "") = pager.load(query).map { it.id } + + @Test + fun firstPageHoldsTheNewestLogs() { + assertEquals(listOf("log-5", "log-4"), pageIds()) + assertTrue(pager.hasNext) + assertFalse(pager.hasPrevious) + } + + @Test + fun nextAndPreviousMoveThroughPages() { + pageIds() + pager.next() + assertEquals(listOf("log-3", "log-2"), pageIds()) + + pager.next() + assertEquals(listOf("log-1"), pageIds()) + assertFalse(pager.hasNext) + + pager.previous() + assertEquals(listOf("log-3", "log-2"), pageIds()) + } + + @Test + fun nextDoesNothingOnTheLastPage() { + repeat(5) { + pageIds() + pager.next() + } + + assertEquals(2, pager.pageIndex) + } + + @Test + fun searchLooksThroughEveryLogNotJustThePage() { + assertEquals(listOf("log-4", "log-2"), pageIds("RACCOON")) + assertFalse(pager.hasNext) + } + + @Test + fun narrowerSearchMovesBackToTheLastPageWithLogs() { + pageIds() + pager.next() + pager.next() + + assertEquals(listOf("log-4", "log-2"), pageIds("raccoon")) + assertEquals(0, pager.pageIndex) + } + + @Test + fun newLogsAppearOnTheFirstPage() { + pageIds() + store.upsert(listOf(AdminLog(id = "log-6", timestamp = 6))) + + assertEquals(listOf("log-6", "log-5"), pageIds()) + } + + @Test + fun resetGoesBackToTheFirstPage() { + pageIds() + pager.next() + + pager.reset() + + assertEquals(0, pager.pageIndex) + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerAreaUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerAreaUnitTest.kt similarity index 94% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerAreaUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerAreaUnitTest.kt index e41b16d4..2abc66a5 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerAreaUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerAreaUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.campsite import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.model.campsite.CampsiteStore @@ -12,6 +12,12 @@ import org.junit.Assert.assertNull import org.junit.Before import org.junit.Test +/* + * Unit tests for CampsiteController filtering campsites by an area on the map. + * + * Outstanding issues: None known. + */ + /** * Tests [CampsiteController] filtering campsites by an area on the map. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerSearchUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerSearchUnitTest.kt similarity index 98% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerSearchUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerSearchUnitTest.kt index 10132ac1..22263240 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerSearchUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerSearchUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.campsite import androidx.compose.runtime.MutableState @@ -27,6 +27,12 @@ import java.time.ZoneId import java.util.Date +/* + * Unit tests for CampsiteController searching, filtering and editing campsites. + * + * Outstanding issues: None known. + */ + /** * Tests [CampsiteController] searching, filtering, and editing. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerUnitTest.kt similarity index 97% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerUnitTest.kt index 8504bfbf..d113e46a 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsiteControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsiteControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.campsite import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.model.local.InMemoryRecentlyViewedStore @@ -19,6 +19,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for CampsiteController's cached listings and recently viewed campsites. + * + * Outstanding issues: None known. + */ + /** Verifies how the campsite controller exposes and updates cached listings. */ @OptIn(ExperimentalCoroutinesApi::class) class CampsiteControllerUnitTest { diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsitePhotoControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsitePhotoControllerUnitTest.kt similarity index 95% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsitePhotoControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsitePhotoControllerUnitTest.kt index 795f6901..bf849ecf 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/CampsitePhotoControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/campsite/CampsitePhotoControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.campsite import android.graphics.Bitmap import com.example.lambda_bbb_events.model.campsite.Campsite @@ -16,6 +16,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for CampsitePhotoController adding, removing and limiting campsite photos. + * + * Outstanding issues: None known. + */ + /** * Tests changing the photos of campsites. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/LotteryControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/lottery/LotteryControllerUnitTest.kt similarity index 98% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/LotteryControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/lottery/LotteryControllerUnitTest.kt index 1027f732..cc6941f5 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/LotteryControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/lottery/LotteryControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.lottery import com.example.lambda_bbb_events.model.lottery.Lottery import com.example.lambda_bbb_events.model.lottery.LotteryStatus @@ -25,6 +25,12 @@ import java.time.LocalDate import java.time.ZoneId import java.util.Date +/* + * Unit tests for LotteryController creating, filtering and drawing lotteries. + * + * Outstanding issues: None known. + */ + /** Verifies lottery controller behavior in isolation. */ class LotteryControllerUnitTest { private val repository = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/WaitlistEntryControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/lottery/WaitlistEntryControllerUnitTest.kt similarity index 93% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/WaitlistEntryControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/lottery/WaitlistEntryControllerUnitTest.kt index 5d120d64..7262d751 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/WaitlistEntryControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/lottery/WaitlistEntryControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.lottery import com.example.lambda_bbb_events.model.lottery.WaitlistEntry import com.example.lambda_bbb_events.model.repository.LotteryRepository @@ -17,6 +17,12 @@ import org.junit.Before import org.junit.Test import java.util.Date +/* + * Unit tests for WaitlistEntryController finding and ordering waitlist entries. + * + * Outstanding issues: None known. + */ + /** Verifies waitlist controller behavior in isolation. */ class WaitlistEntryControllerUnitTest { private val repository = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/messaging/GroupMessageSenderUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/messaging/GroupMessageSenderUnitTest.kt new file mode 100644 index 00000000..aaed77eb --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/messaging/GroupMessageSenderUnitTest.kt @@ -0,0 +1,151 @@ +package com.example.lambda_bbb_events.controller.messaging + +import com.example.lambda_bbb_events.model.lottery.WaitlistEntry +import com.example.lambda_bbb_events.model.lottery.WaitlistStatus +import com.example.lambda_bbb_events.model.message.ConversationType +import com.example.lambda_bbb_events.model.repository.AdminLogRepository +import com.example.lambda_bbb_events.model.repository.ConversationRepository +import com.example.lambda_bbb_events.model.repository.MessageRepository +import com.example.lambda_bbb_events.model.user.CampsiteOwner +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.runs +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Unit tests for GroupMessageSender messaging a lottery's waitlist and logging the send. + * + * Outstanding issues: None known. + */ + +class GroupMessageSenderUnitTest { + private val users = mockk() + private val conversations = mockk() + private val messages = mockk() + private val logs = mockk() + private val sender = GroupMessageSender(users, conversations, logs) { messages } + + /** Makes a waitlist entry for [entrantId] with [status]. */ + private fun entry(entrantId: String, status: WaitlistStatus = WaitlistStatus.IN_WAITLIST) = + WaitlistEntry(entryId = "entry-$entrantId", entrantId = entrantId, lotteryId = "lottery-1", status = status) + + @Before + fun setup() { + every { users.user } returns CampsiteOwner(deviceId = "owner-1", name = "Olive") + coEvery { users.getUserName(any()) } answers { "Name of ${firstArg()}" } + coEvery { logs.logNotification(any(), any(), any(), any(), any(), any(), any(), any()) } just runs + coEvery { conversations.createConversation("owner-1", ConversationType.OWNER, any()) } answers { + "conversation-${thirdArg()}" + } + coEvery { messages.sendMessage(any(), any()) } just runs + } + + @Test + fun onlyWaitlistedAndWinningEntrantsAreRecipients() { + val entries = WaitlistStatus.entries.map { entry("user-${it.name}", it) } + + assertEquals( + listOf("user-IN_WAITLIST", "user-WON"), + GroupMessageSender.recipientsOf(entries) + ) + } + + @Test + fun entrantWithSeveralEntriesIsMessagedOnce() = runTest { + val result = sender.sendToWaitlist(listOf(entry("user-1"), entry("user-1", WaitlistStatus.WON)), "Hi") + + assertEquals(GroupMessageResult(1, emptyList()), result) + coVerify(exactly = 1) { messages.sendMessage("Hi", "owner-1") } + } + + @Test + fun messageGoesIntoEachEntrantsChatWithTheOwner() = runTest { + sender.sendToWaitlist(listOf(entry("user-1"), entry("user-2")), "Gates open at 9") + + coVerify { conversations.createConversation("owner-1", ConversationType.OWNER, "user-1") } + coVerify { conversations.createConversation("owner-1", ConversationType.OWNER, "user-2") } + coVerify(exactly = 2) { messages.sendMessage("Gates open at 9", "owner-1") } + } + + @Test + fun oneFailureDoesNotStopTheRest() = runTest { + coEvery { + conversations.createConversation("owner-1", ConversationType.OWNER, "user-2") + } throws IllegalStateException("Owner messaging is unavailable") + + val result = sender.sendToWaitlist( + listOf(entry("user-1"), entry("user-2"), entry("user-3")), + "Hi" + ) + + assertEquals(GroupMessageResult(2, listOf("user-2")), result) + } + + @Test(expected = IllegalArgumentException::class) + fun blankMessageIsRefused() = runTest { + sender.sendToWaitlist(listOf(entry("user-1")), " ") + } + + @Test + fun eachSendIsLoggedOnceWithOnlyTheEntrantsItReached() = runTest { + coEvery { + conversations.createConversation("owner-1", ConversationType.OWNER, "user-2") + } throws IllegalStateException("Owner messaging is unavailable") + + sender.sendToWaitlist( + listOf(entry("user-1"), entry("user-2"), entry("user-3")), + " Gates open at 9 ", + campsiteId = "site-1", + campsiteName = "Pine Lake" + ) + + coVerify(exactly = 1) { + logs.logNotification( + title = GroupMessageSender.LOG_TITLE, + senderId = "owner-1", + senderName = "Olive", + recipientIds = listOf("user-1", "user-3"), + content = "Gates open at 9", + recipientNames = mapOf("user-1" to "Name of user-1", "user-3" to "Name of user-3"), + campsiteId = "site-1", + campsiteName = "Pine Lake" + ) + } + } + + @Test + fun nothingIsLoggedWhenNobodyWasReached() = runTest { + coEvery { conversations.createConversation(any(), any(), any()) } throws IllegalStateException("No access") + + sender.sendToWaitlist(listOf(entry("user-1")), "Hi") + + coVerify(exactly = 0) { logs.logNotification(any(), any(), any(), any(), any(), any(), any(), any()) } + } + + @Test + fun failedLogDoesNotHideThatTheMessagesWereSent() = runTest { + coEvery { logs.logNotification(any(), any(), any(), any(), any(), any(), any(), any()) } throws + IllegalStateException("PERMISSION_DENIED") + + val result = sender.sendToWaitlist(listOf(entry("user-1"), entry("user-2")), "Hi") + + assertEquals(GroupMessageResult(2, emptyList()), result) + } + + @Test + fun summaryCountsEntrants() { + assertEquals("Sent to 1 entrant.", GroupMessageResult(1, emptyList()).summary()) + assertEquals("Sent to 3 entrants.", GroupMessageResult(3, emptyList()).summary()) + assertEquals( + "Sent to 4 of 5 entrants. 1 could not be reached.", + GroupMessageResult(4, listOf("user-5")).summary() + ) + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/messaging/MessageControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/messaging/MessageControllerUnitTest.kt new file mode 100644 index 00000000..9446749e --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/messaging/MessageControllerUnitTest.kt @@ -0,0 +1,150 @@ +package com.example.lambda_bbb_events.controller.messaging + +import com.example.lambda_bbb_events.model.message.ConversationType +import com.example.lambda_bbb_events.model.message.Message +import com.example.lambda_bbb_events.model.repository.ConversationRepository +import com.example.lambda_bbb_events.model.user.Admin +import com.example.lambda_bbb_events.model.user.Entrant +import com.example.lambda_bbb_events.model.user.User +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import com.example.lambda_bbb_events.controller.user.UserController + +/* + * Unit tests for MessageController starting conversations, checking admin access and deciding + * who can delete a message. + * + * Outstanding issues: None known. + */ + +/** + * Tests [MessageController] with its conversations and signed-in user mocked. Opening a + * conversation and sending messages read the database, so they are tested against Firestore + * in MessageControllerFirestoreTest. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +class MessageControllerUnitTest { + private val conversations = mockk(relaxed = true) + private val users = mockk() + private val controller = MessageController(users, conversations) + + private val ed = Entrant(deviceId = "user-1", name = "Ed") + private val ada = Admin(deviceId = "admin-1", name = "Ada") + + /** Signs in [user], or nobody when it is `null`. */ + private fun signIn(user: User?) { + every { users.currentUser } returns user + if (user != null) every { users.user } returns user + } + + /** A message from [sender], already deleted if [deleted]. */ + private fun message(sender: String, deleted: Boolean = false) = + Message(messageId = "m-1", content = "Hi", senderId = sender, recipientId = "other", deleted = deleted) + + @Test + fun camperStartsAConversationAsThemselves() = runTest { + signIn(ed) + coEvery { conversations.createConversation("owner-1", ConversationType.OWNER, "user-1") } returns "c-1" + + assertEquals("c-1", controller.createConversation("owner-1", ConversationType.OWNER)) + } + + @Test + fun ownerStartsAConversationOnTheCampersBehalf() = runTest { + signIn(Entrant(deviceId = "owner-1")) + + controller.startConversationAsOwner("user-1") + + coVerify { conversations.createConversation(contactId = "owner-1", type = ConversationType.OWNER, userId = "user-1") } + } + + @Test + fun onlyAdminsCanStartAConversationWithAnyUser() = runTest { + signIn(ed) + assertTrue(runCatching { controller.startConversationWithUser("user-2") }.exceptionOrNull() is IllegalStateException) + + signIn(ada) + controller.startConversationWithUser("user-2") + coVerify { conversations.startAdminConversation(userId = "user-2", adminId = "admin-1") } + } + + @Test + fun nonAdminsHaveNoAdminConversations() = runTest { + signIn(ed) + + assertEquals(emptyList(), controller.getAdminConversations()) + coVerify(exactly = 0) { conversations.getAdminConversations(any()) } + } + + @Test + fun onlyAdminsCanWatchAdminConversations() { + signIn(ed) + assertTrue(runCatching { controller.observeAdminConversations() }.exceptionOrNull() is IllegalStateException) + + signIn(ada) + every { conversations.observeAdminConversations("admin-1") } returns emptyFlow() + controller.observeAdminConversations() + verify { conversations.observeAdminConversations("admin-1") } + } + + @Test + fun conversationListsAreForTheSignedInUser() = runTest { + signIn(ed) + + controller.getUserConversations() + controller.getOwnerConversations() + controller.getConversation("c-1") + + coVerify { conversations.getUserConversations(userId = "user-1") } + coVerify { conversations.getOwnerConversations(ownerId = "user-1") } + coVerify { conversations.getConversation(conversationId = "c-1", userId = "user-1") } + } + + @Test + fun nothingCanBeSentOrDeletedWithoutAnOpenConversation() = runTest { + signIn(ed) + + assertTrue(runCatching { controller.sendMessage("Hi") }.exceptionOrNull() is IllegalStateException) + assertTrue(runCatching { controller.deleteMessage("m-1") }.exceptionOrNull() is IllegalStateException) + assertEquals(emptyList(), controller.messages) + } + + @Test + fun peopleCanDeleteOnlyTheirOwnMessages() { + signIn(ed) + + assertTrue(controller.canDelete(message(sender = "user-1"))) + assertFalse(controller.canDelete(message(sender = "user-2"))) + } + + @Test + fun adminsCanDeleteAnyMessage() { + signIn(ada) + + assertTrue(controller.canDelete(message(sender = "user-2"))) + } + + @Test + fun deletedMessagesAndSignedOutUsersCannotDelete() { + signIn(ed) + assertFalse(controller.canDelete(message(sender = "user-1", deleted = true))) + + signIn(null) + assertFalse(controller.canDelete(message(sender = "user-1"))) + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceControllerUnitTest.kt new file mode 100644 index 00000000..d8d54200 --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/notification/NotificationPreferenceControllerUnitTest.kt @@ -0,0 +1,48 @@ +package com.example.lambda_bbb_events.controller.notification + +import io.mockk.mockk +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +/* + * Unit tests for NotificationPreferenceController before it has connected to the database. + * + * Outstanding issues: None known. + */ + +/** + * Tests [NotificationPreferenceController] before [NotificationPreferenceController.startListening] + * is called: nobody is muted, and muting fails clearly instead of being lost. Muting once + * connected is tested against Firestore in NotificationPreferenceFirestoreTest. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +class NotificationPreferenceControllerUnitTest { + private val controller = NotificationPreferenceController(mockk()) + + @Test + fun nobodyIsMutedBeforeConnecting() { + assertFalse(controller.isMuted("owner-1")) + assertEquals("owner-1", controller.getPreference("owner-1").contactId) + assertEquals(emptyList(), controller.preferences) + } + + @Test + fun mutingBeforeConnectingFailsInsteadOfBeingLost() = runTest { + listOf Unit>( + { controller.mute("owner-1") }, + { controller.muteForHours("owner-1", 8) }, + { controller.unmute("owner-1") } + ).forEach { change -> + assertTrue(runCatching { change() }.exceptionOrNull() is IllegalStateException) + } + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReservationControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/reservation/ReservationControllerUnitTest.kt similarity index 95% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/ReservationControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/reservation/ReservationControllerUnitTest.kt index 4eb320b1..396c29d0 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReservationControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/reservation/ReservationControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.reservation import com.example.lambda_bbb_events.model.reservation.Reservation import com.example.lambda_bbb_events.model.reservation.ReservationStatus @@ -11,6 +11,12 @@ import org.junit.Before import org.junit.Test import java.time.LocalDate +/* + * Unit tests for ReservationController grouping and changing reservations. + * + * Outstanding issues: None known. + */ + /** Verifies reservation controller behavior in isolation. */ class ReservationControllerUnitTest { private val repository = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewControllerUnitTest.kt similarity index 96% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewControllerUnitTest.kt index 72c5a6e5..5356410a 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.review import com.example.lambda_bbb_events.model.campsite.Campsite import com.example.lambda_bbb_events.model.repository.ReviewRepository @@ -24,6 +24,12 @@ import org.junit.Before import org.junit.Test import java.util.Date +/* + * Unit tests for ReviewController reading, writing and deleting reviews. + * + * Outstanding issues: None known. + */ + /** Verifies review controller behavior in isolation. */ class ReviewControllerUnitTest { private val repository = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewReactionControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewReactionControllerUnitTest.kt similarity index 94% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewReactionControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewReactionControllerUnitTest.kt index 819305bb..b094ed25 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewReactionControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewReactionControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.review import com.example.lambda_bbb_events.model.repository.ReviewReactionRepository import com.example.lambda_bbb_events.model.review.Review @@ -18,6 +18,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for ReviewReactionController adding, counting and removing emoji reactions. + * + * Outstanding issues: None known. + */ + class ReviewReactionControllerUnitTest { private val reactions = mockk() private val controller = ReviewReactionController(reactions) diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewReplyControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewReplyControllerUnitTest.kt similarity index 93% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewReplyControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewReplyControllerUnitTest.kt index ccee542a..35fc0e5a 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/ReviewReplyControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/review/ReviewReplyControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.review import com.example.lambda_bbb_events.model.repository.ReviewReplyRepository import com.example.lambda_bbb_events.model.review.Review @@ -21,6 +21,12 @@ import org.junit.Before import org.junit.Test import java.util.Date +/* + * Unit tests for ReviewReplyController ordering, saving and validating replies. + * + * Outstanding issues: None known. + */ + class ReviewReplyControllerUnitTest { private val replies = mockk() private val controller = ReviewReplyController(replies) diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/controller/UserControllerUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/controller/user/UserControllerUnitTest.kt similarity index 98% rename from code/app/src/test/java/com/example/lambda_bbb_events/controller/UserControllerUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/controller/user/UserControllerUnitTest.kt index bef7e2a8..1481f206 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/controller/UserControllerUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/controller/user/UserControllerUnitTest.kt @@ -1,4 +1,4 @@ -package com.example.lambda_bbb_events.controller +package com.example.lambda_bbb_events.controller.user import com.example.lambda_bbb_events.model.local.InMemorySessionStore import com.example.lambda_bbb_events.model.repository.UserRepository @@ -25,6 +25,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for UserController account logic that does not depend on Android. + * + * Outstanding issues: None known. + */ + /** * Tests [UserController] logic that does not depend on Android's input validation. * Name, email, and phone validation is covered by the instrumented `UserControllerTest`. diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/AvailabilityScheduleUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/AvailabilityScheduleUnitTest.kt index 58f7028a..8fcb80b5 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/AvailabilityScheduleUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/AvailabilityScheduleUnitTest.kt @@ -7,6 +7,12 @@ import org.junit.Assert.assertTrue import org.junit.Test import java.time.LocalDate +/* + * Unit tests for the AvailabilitySchedule model's date and booking rules. + * + * Outstanding issues: None known. + */ + /** Verifies the availability schedule's date and booking rules. */ class AvailabilityScheduleUnitTest { private fun day(n: Int): LocalDate = LocalDate.of(2026, 1, n) diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/store/CampsiteStoreUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteStoreUnitTest.kt similarity index 95% rename from code/app/src/test/java/com/example/lambda_bbb_events/store/CampsiteStoreUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteStoreUnitTest.kt index 9ebac1cb..6eebd364 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/store/CampsiteStoreUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteStoreUnitTest.kt @@ -1,8 +1,6 @@ -package com.example.lambda_bbb_events.store +package com.example.lambda_bbb_events.model.campsite import androidx.compose.runtime.mutableStateOf -import com.example.lambda_bbb_events.model.campsite.Campsite -import com.example.lambda_bbb_events.model.campsite.CampsiteStore 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 @@ -22,6 +20,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for CampsiteStore's cached listings. + * + * Outstanding issues: None known. + */ + /** Verifies how campsite store operations affect its cached listings. */ @OptIn(ExperimentalCoroutinesApi::class) class CampsiteStoreUnitTest { diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteUnitTest.kt index cc2abb49..7f358f0d 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/CampsiteUnitTest.kt @@ -7,6 +7,12 @@ import org.junit.Assert.assertNotEquals import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the Campsite model. + * + * Outstanding issues: None known. + */ + /** * Tests the [Campsite] model. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/SearchAreaUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/SearchAreaUnitTest.kt index f6dac283..735de642 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/SearchAreaUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/campsite/SearchAreaUnitTest.kt @@ -5,6 +5,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for GeoPoint distances and SearchArea checks, resizing and outlines. + * + * Outstanding issues: None known. + */ + /** * Tests [GeoPoint] distances and [SearchArea] checks, resizing, and outlines. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/DateParsingUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/DateParsingUnitTest.kt new file mode 100644 index 00000000..63797dda --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/DateParsingUnitTest.kt @@ -0,0 +1,48 @@ +package com.example.lambda_bbb_events.model.formatting + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test +import java.time.LocalDate + +/* + * Unit tests for reading dates typed into the app's date fields. + * + * Outstanding issues: None known. + */ + +/** + * Tests [parseDateOrNull]: ISO dates are read, and anything else gives `null` instead of + * crashing. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +class DateParsingUnitTest { + + @Test + fun isoDateIsRead() { + assertEquals(LocalDate.of(2026, 7, 14), parseDateOrNull("2026-07-14")) + } + + @Test + fun leapDayIsRead() { + assertEquals(LocalDate.of(2028, 2, 29), parseDateOrNull("2028-02-29")) + } + + @Test + fun impossibleDateIsNull() { + assertNull(parseDateOrNull("2026-02-30")) + } + + @Test + fun otherFormatsAreNull() { + listOf("14/07/2026", "July 14, 2026", "2026-7-14", "", " ").forEach { + assertNull("\"$it\"", parseDateOrNull(it)) + } + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/PhoneNumberUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/PhoneNumberUnitTest.kt index 5ca34c3b..62213aa9 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/PhoneNumberUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/formatting/PhoneNumberUnitTest.kt @@ -4,6 +4,12 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for parsing and formatting phone numbers. + * + * Outstanding issues: None known. + */ + /** Verifies phone-number parsing and formatting. */ class PhoneNumberUnitTest { private fun country(iso: String) = COUNTRY_CODES.first { it.isoCode == iso } diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/local/InMemoryRecentlyViewedStoreUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/local/InMemoryRecentlyViewedStoreUnitTest.kt index 8d85efaa..5ce9246f 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/local/InMemoryRecentlyViewedStoreUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/local/InMemoryRecentlyViewedStoreUnitTest.kt @@ -4,6 +4,12 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the in-memory store of recently viewed campsites. + * + * Outstanding issues: None known. + */ + /** Verifies the in-memory implementation of recently viewed campsite storage. */ class InMemoryRecentlyViewedStoreUnitTest { private val store = InMemoryRecentlyViewedStore() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/LotteryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/LotteryUnitTest.kt index e471a10d..d8590605 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/LotteryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/LotteryUnitTest.kt @@ -9,6 +9,12 @@ import java.time.LocalDate import java.time.ZoneId import java.util.Date +/* + * Unit tests for the Lottery model. + * + * Outstanding issues: None known. + */ + /** Verifies the lottery model's values and behavior. */ class LotteryUnitTest { @Test diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntryUnitTest.kt index 1fe5bf89..87217815 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/lottery/WaitlistEntryUnitTest.kt @@ -5,6 +5,12 @@ import org.junit.Assert.assertThrows import org.junit.Test import java.util.Date +/* + * Unit tests for the WaitlistEntry model. + * + * Outstanding issues: None known. + */ + /** Verifies the waitlist entry model's values and behavior. */ class WaitlistEntryUnitTest { @Test diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/message/MessageUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/message/MessageUnitTest.kt index 02b56335..1d574801 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/message/MessageUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/message/MessageUnitTest.kt @@ -14,6 +14,8 @@ import org.junit.Test * - "Also please clean up a database and offer a way for users to delete messages with a message * deleted plus. Show also that messages are active." * - "So to clarify I want to allow users and admins to remove messages." + * + * Outstanding issues: None known. */ /** Verifies the message model's values and behavior. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/message/NotificationPreferenceUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/message/NotificationPreferenceUnitTest.kt new file mode 100644 index 00000000..54ff4011 --- /dev/null +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/message/NotificationPreferenceUnitTest.kt @@ -0,0 +1,57 @@ +package com.example.lambda_bbb_events.model.message + +import com.google.firebase.Timestamp +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +/* + * Unit tests for the NotificationPreference model's muting rules. + * + * Outstanding issues: None known. + */ + +/** + * Tests when a [NotificationPreference] counts as muted: muted indefinitely, muted until a time + * still to come, or not muted once that time has passed. + * + * Reference: + * Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model]. + * https://claude.com/claude-code + * Written with the help of this AI tool. + * Prompts: + * - "Okay implement the missing tests." + */ +class NotificationPreferenceUnitTest { + + /** A time [hours] from now; negative for the past. */ + private fun hoursFromNow(hours: Long): Timestamp { + val now = Timestamp.now() + return Timestamp(now.seconds + hours * 3600, now.nanoseconds) + } + + @Test + fun newPreferenceIsNotMuted() { + assertFalse(NotificationPreference(contactId = "owner-1").isMuted()) + } + + @Test + fun mutedWithoutAnEndStaysMuted() { + assertTrue(NotificationPreference("owner-1", muted = true, mutedUntil = null).isMuted()) + } + + @Test + fun mutedUntilLaterIsMuted() { + assertTrue(NotificationPreference("owner-1", muted = true, mutedUntil = hoursFromNow(8)).isMuted()) + } + + @Test + fun muteEndsOnceItsTimeHasPassed() { + assertFalse(NotificationPreference("owner-1", muted = true, mutedUntil = hoursFromNow(-1)).isMuted()) + } + + @Test + fun anEndTimeAloneDoesNotMute() { + assertFalse(NotificationPreference("owner-1", muted = false, mutedUntil = hoursFromNow(8)).isMuted()) + } +} diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryUnitTest.kt index ef5750d6..51e09637 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/CampsiteRepositoryUnitTest.kt @@ -14,6 +14,12 @@ import org.junit.Before import org.junit.Test import java.time.LocalDate +/* + * Unit tests for CampsiteRepository with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies campsite repository behavior with mocked persistence. */ class CampsiteRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/FirestoreMocks.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/FirestoreMocks.kt index 6cfb6ffd..1b6e78da 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/FirestoreMocks.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/FirestoreMocks.kt @@ -15,6 +15,8 @@ import io.mockk.slot /* * Shared helpers for unit testing repositories against a mocked Firestore. + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ImageRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ImageRepositoryUnitTest.kt index 99142e3c..6b8bdf28 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ImageRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ImageRepositoryUnitTest.kt @@ -18,6 +18,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for ImageRepository storing and reading images in chunks, with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies image repository behavior with mocked persistence. */ class ImageRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryUnitTest.kt index c31ea7c5..0a9b4384 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/LotteryRepositoryUnitTest.kt @@ -26,6 +26,12 @@ import org.junit.Before import org.junit.Test import java.time.LocalDate +/* + * Unit tests for LotteryRepository with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies lottery repository behavior with mocked persistence. */ class LotteryRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryUnitTest.kt index 809978c8..24b478f3 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/MessageRepositoryUnitTest.kt @@ -27,6 +27,8 @@ import org.junit.Test * Prompts: * - "Fix the github action now" * - "I mean it passes because you removed the tests cases." + * + * Outstanding issues: None known. */ /** diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/RepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/RepositoryUnitTest.kt index 42e0ff06..290961f6 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/RepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/RepositoryUnitTest.kt @@ -14,6 +14,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for the shared Repository base class, through a minimal subclass. + * + * Outstanding issues: None known. + */ + /** * Tests the shared behaviour of [Repository] through a minimal subclass. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryUnitTest.kt index cf0ec028..3238e9ed 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReservationRepositoryUnitTest.kt @@ -16,6 +16,12 @@ import org.junit.After import org.junit.Before import org.junit.Test +/* + * Unit tests for ReservationRepository with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies reservation repository behavior with mocked persistence. */ class ReservationRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryUnitTest.kt index f50e4dda..565463b7 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/ReviewRepositoryUnitTest.kt @@ -16,6 +16,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for ReviewRepository keeping campsite ratings up to date, with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies review repository behavior with mocked persistence. */ class ReviewRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/UserRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/UserRepositoryUnitTest.kt index cf7a7626..bf5da98c 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/UserRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/UserRepositoryUnitTest.kt @@ -21,6 +21,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for UserRepository with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies user repository behavior with mocked persistence. */ class UserRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryUnitTest.kt index d78ff9c6..560bbb59 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/repository/WaitlistEntryRepositoryUnitTest.kt @@ -14,6 +14,12 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +/* + * Unit tests for WaitlistEntryRepository with a mocked database. + * + * Outstanding issues: None known. + */ + /** Verifies waitlist entry repository behavior with mocked persistence. */ class WaitlistEntryRepositoryUnitTest { private val db = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/reservation/ReservationUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/reservation/ReservationUnitTest.kt index 3b6a23cd..3abecc0d 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/reservation/ReservationUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/reservation/ReservationUnitTest.kt @@ -5,6 +5,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the Reservation model. + * + * Outstanding issues: None known. + */ + /** Verifies the reservation model's values and behavior. */ class ReservationUnitTest { @Test diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReactionUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReactionUnitTest.kt index a13409ae..f2f4cbfe 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReactionUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReactionUnitTest.kt @@ -5,6 +5,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the ReviewReaction model's IDs and allowed emojis. + * + * Outstanding issues: None known. + */ + class ReviewReactionUnitTest { private val reaction = ReviewReaction("site-1_user-1_user-2", "site-1_user-1", "user-2", "👍") diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReplyUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReplyUnitTest.kt index 4433c9d6..99194f26 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReplyUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewReplyUnitTest.kt @@ -4,6 +4,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the ReviewReply model's validation. + * + * Outstanding issues: None known. + */ + class ReviewReplyUnitTest { private val reply = ReviewReply("reply-1", "site-1_user-1", "user-2", "Agreed!") diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewUnitTest.kt index 60009efb..7ca49041 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/review/ReviewUnitTest.kt @@ -5,6 +5,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the Review model. + * + * Outstanding issues: None known. + */ + /** Verifies the review model's values and behavior. */ class ReviewUnitTest { private val review = Review( diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearchUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearchUnitTest.kt index 761fb552..bf1113e7 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearchUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/services/FallbackPlaceSearchUnitTest.kt @@ -10,6 +10,13 @@ import org.junit.Assert.assertTrue import org.junit.Test import java.io.IOException +/* + * Unit tests for switching place search from Google to OpenStreetMap when Google's key does not + * work. + * + * Outstanding issues: None known. + */ + /** * Tests switching from Google to OpenStreetMap when Google's key does not work. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ImageProcessorUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ImageProcessorUnitTest.kt index f5a6907d..ac2dc748 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ImageProcessorUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ImageProcessorUnitTest.kt @@ -4,6 +4,12 @@ import com.example.lambda_bbb_events.model.services.ImageProcessor.Companion.sam import org.junit.Assert.assertEquals import org.junit.Test +/* + * Unit tests for ImageProcessor's resizing helpers. + * + * Outstanding issues: None known. + */ + /** Verifies image processing helpers. */ class ImageProcessorUnitTest { diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ServicesUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ServicesUnitTest.kt index 37b70f6b..2c0a8a9f 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ServicesUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/services/ServicesUnitTest.kt @@ -11,6 +11,12 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the lottery draw and other service helpers. + * + * Outstanding issues: None known. + */ + /** Verifies application service helpers. */ class ServicesUnitTest { diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/model/user/UserUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/model/user/UserUnitTest.kt index 5e6ce344..6c68961b 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/model/user/UserUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/model/user/UserUnitTest.kt @@ -6,6 +6,12 @@ import org.junit.Assert.assertThrows import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for the User model and its roles. + * + * Outstanding issues: None known. + */ + /** * Tests the [User] model and its roles. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStopsUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStopsUnitTest.kt index 41a7b014..fbd1faf8 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStopsUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/common/RangeStopsUnitTest.kt @@ -3,6 +3,12 @@ package com.example.lambda_bbb_events.view.ui.components.common import org.junit.Assert.assertEquals import org.junit.Test +/* + * Unit tests for matching ranges to the stops of range sliders. + * + * Outstanding issues: None known. + */ + /** * Tests matching ranges to the stops of range sliders. */ diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/view/navigation/BackNavigationUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigationUnitTest.kt similarity index 89% rename from code/app/src/test/java/com/example/lambda_bbb_events/view/navigation/BackNavigationUnitTest.kt rename to code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigationUnitTest.kt index 0d5b2e70..53d7c0a9 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/view/navigation/BackNavigationUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/navigation/BackNavigationUnitTest.kt @@ -1,8 +1,7 @@ -package com.example.lambda_bbb_events.view.navigation +package com.example.lambda_bbb_events.view.ui.components.navigation import androidx.lifecycle.Lifecycle import androidx.navigation.NavController -import com.example.lambda_bbb_events.view.ui.components.navigation.goBackIfShown import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -10,6 +9,12 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for how back navigation decides what to do. + * + * Outstanding issues: None known. + */ + /** Verifies how back navigation selects an action. */ class BackNavigationUnitTest { private val navController = mockk() diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpotsUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpotsUnitTest.kt index 1ef2ac87..f6c361f6 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpotsUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/components/review/ReactionSpotsUnitTest.kt @@ -5,6 +5,12 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +/* + * Unit tests for where emoji reactions are placed on a review. + * + * Outstanding issues: None known. + */ + class ReactionSpotsUnitTest { @Test fun spotIsOnTheEdgeOfTheReview() { diff --git a/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContactsUnitTest.kt b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContactsUnitTest.kt index cb3af120..bd3aa60c 100644 --- a/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContactsUnitTest.kt +++ b/code/app/src/test/java/com/example/lambda_bbb_events/view/ui/user_screens/notification/MessageContactsUnitTest.kt @@ -24,6 +24,8 @@ import org.junit.Test * is to fix the notification page so that the spacing looks right." * - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate * chats per admin". + * + * Outstanding issues: None known. */ /** Verifies how messaging contacts are derived from the available data. */ diff --git a/code/firestore.rules b/code/firestore.rules index d521e9ad..2f98e6ba 100644 --- a/code/firestore.rules +++ b/code/firestore.rules @@ -178,7 +178,9 @@ service cloud.firestore { // and updating the latest message information. allow read, create, update: if true; - allow delete: if false; + // Only test conversations (camper IDs starting with "test-") can be + // removed, so instrumented tests can clean up. + allow delete: if resource.data.userId.matches('test-.*'); // Individual messages within a conversation. match /messages/{messageId} { @@ -204,7 +206,9 @@ service cloud.firestore { && request.resource.data.content == ''; // Messages are never removed, so the conversation keeps its order. - allow delete: if false; + // Only test messages (sender IDs starting with "test-") can be removed, + // so instrumented tests can clean up. + allow delete: if resource.data.senderId.matches('test-.*'); } } @@ -217,7 +221,9 @@ service cloud.firestore { allow read, create, update: if true; // Preserve historical messaging access records. - allow delete: if false; + // Only test users (IDs starting with "test-") can be removed, + // so instrumented tests can clean up. + allow delete: if userId.matches('test-.*'); } // Notification preferences for individual contacts. @@ -227,18 +233,48 @@ service cloud.firestore { // including temporary and indefinite muting. allow read, create, update: if true; - allow delete: if false; + // Only test users (IDs starting with "test-") can be removed, + // so instrumented tests can clean up. + allow delete: if userId.matches('test-.*'); } // Firebase Cloud Messaging registration tokens. // The app writes its own token; only Cloud Functions (Admin SDK) read it. + // Only test devices (IDs starting with "test-") can be removed, + // so instrumented tests can clean up. match /fcmTokens/{deviceId} { - allow read, delete: if false; + allow read: if false; + allow delete: if deviceId.matches('test-.*'); allow create, update: if request.resource.data.keys().hasOnly(['token', 'updatedAt']) && request.resource.data.token is string && request.resource.data.token.size() > 0 && request.resource.data.updatedAt == request.time; } + + // Notifications users sent to others, for admins to review. + // A log can be written once, by the app, and never changed or removed, + // so a sender cannot hide what they sent. + // Only logs from test senders (IDs starting with "test-") can be removed, + // so instrumented tests can clean up; real senders use device IDs. + match /notificationLogs/{logId} { + allow read: if true; + allow update: if false; + allow delete: if resource.data.senderId.matches('test-.*'); + allow create: + if request.resource.data.keys().hasOnly([ + 'id', 'type', 'title', 'senderId', 'senderName', 'recipientIds', + 'recipientNames', 'content', 'campsiteId', 'campsiteName', 'timestamp' + ]) + && request.resource.data.id == logId + && request.resource.data.type == 'NOTIFICATION' + && request.resource.data.senderId is string + && request.resource.data.senderId.size() > 0 + && request.resource.data.recipientIds is list + && request.resource.data.recipientIds.size() > 0 + && request.resource.data.content is string + && request.resource.data.content.size() <= 2000 + && request.resource.data.timestamp is int; + } } } diff --git a/doc/images/Storyboard.png b/doc/images/Storyboard.png new file mode 100644 index 00000000..22af398e Binary files /dev/null and b/doc/images/Storyboard.png differ