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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.example.lambda_bbb_events.ui.account

import androidx.compose.ui.test.assertIsDisplayed
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.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.model.user.User
import com.example.lambda_bbb_events.model.user.UserRole
import com.example.lambda_bbb_events.view.ui.user_screens.profile.Settings
import io.mockk.clearAllMocks
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
* Verifies the log out and delete account dialogs on the settings 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:
* - "Can you finish the to do in settings screen"
*/
@RunWith(AndroidJUnit4::class)
class SettingsScreenUITest {

@get:Rule
val composeTestRule = createComposeRule()

private val controllers = mockk<AppControllers>(relaxed = true)
private val userController = controllers.users

@Before
fun setup() {
val user = mockk<User>(relaxed = true)
every { user.name } returns "Test User"
every { user.role } returns UserRole.ENTRANT
every { userController.user } returns user
every { userController.deviceId } returns "device-1"
coEvery { userController.deleteAccount() } returns true

composeTestRule.setContent {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "settings") {
composable("settings") { Settings(navController, controllers) }
}
}
}

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

/**
* Taps a settings row by its route.
*
* @param route The row's route, such as "log_out".
*/
private fun tapRow(route: String) {
composeTestRule.onNodeWithTag("settings_$route").performScrollTo().performClick()
}

@Test
fun logOutRowOpensDialog() {
tapRow("log_out")

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

@Test
fun cancellingLogOutClosesDialogWithoutLoggingOut() {
tapRow("log_out")
composeTestRule.onNodeWithTag("dialog_log_out_cancel").performClick()

composeTestRule.onNodeWithTag("dialog_log_out").assertDoesNotExist()
verify(exactly = 0) { userController.logOut() }
}

@Test
fun confirmingLogOutLogsOut() {
tapRow("log_out")
composeTestRule.onNodeWithTag("dialog_log_out_confirm").performClick()

verify { userController.logOut() }
composeTestRule.onNodeWithTag("dialog_log_out").assertDoesNotExist()
}

@Test
fun deleteAccountRowOpensDialog() {
tapRow("delete_account")

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

@Test
fun cancellingDeleteClosesDialogWithoutDeleting() {
tapRow("delete_account")
composeTestRule.onNodeWithTag("dialog_delete_account_cancel").performClick()

composeTestRule.onNodeWithTag("dialog_delete_account").assertDoesNotExist()
coVerify(exactly = 0) { userController.deleteAccount() }
}

@Test
fun confirmingDeleteDeletesAccount() {
tapRow("delete_account")
composeTestRule.onNodeWithTag("dialog_delete_account_confirm").performClick()
composeTestRule.waitForIdle()

coVerify { userController.deleteAccount() }
composeTestRule.onNodeWithTag("dialog_delete_account").assertDoesNotExist()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.util.Date

/*
* Manages lottery and waitlist data in Firestore.
* TODO: Remove waitlist entry records when entries are deleted.
*/


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ fun AdminProfileListCard(
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
// TODO: replace with user's profile picture when user pfp's is implemented
if (user.profilePictureImageId.isBlank()) {
Surface(
shape = CircleShape,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.example.lambda_bbb_events.view.ui.components.profile
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag

/*
Prompts an easy to call alert dialog for more consequential requests
Expand All @@ -20,6 +21,15 @@ Prompts an easy to call alert dialog for more consequential requests
* @param dismissState Action when dismissed ( Should be enclosed in {} ).
* @param cancelText Cancellation button label.
* @param modifier Modifier applied to function.
* @param testTag Test tag for the dialog, or `null` for none. When set, the confirm and
* cancel buttons are tagged "<testTag>_confirm" and "<testTag>_cancel".
*
* Reference:
* Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model].
* https://claude.com/claude-code
* Changed with the help of this AI tool (added test tags).
* Prompts:
* - "Can you finish the to do in settings screen"
*/

@Composable
Expand All @@ -30,22 +40,38 @@ fun ShowAlertDialog(
confirmText: String,
dismissState: () -> Unit,
cancelText: String,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
testTag: String? = null
) {
AlertDialog(
modifier = modifier,
modifier = modifier.taggedWith(testTag),
containerColor = MaterialTheme.colorScheme.surface,
// close dialog when the user taps outside the box in specific state.
onDismissRequest = dismissState,
title = { Text(dialogLabel) },
text = { Text(dialogCaption) },
confirmButton = {
TextButton( onClick = confirmButton ) { Text(confirmText, color = MaterialTheme.colorScheme.error) }
TextButton(
onClick = confirmButton,
modifier = Modifier.taggedWith(testTag?.let { "${it}_confirm" })
) { Text(confirmText, color = MaterialTheme.colorScheme.error) }
},
dismissButton = {
TextButton( onClick = dismissState ) {
TextButton(
onClick = dismissState,
modifier = Modifier.taggedWith(testTag?.let { "${it}_cancel" })
) {
Text(cancelText)
}
}
)
}

/**
* Adds a test tag to this modifier, or leaves it unchanged when [tag] is `null`.
*
* @param tag The test tag to add, or `null` for none.
* @return The modifier with the tag added.
*/
private fun Modifier.taggedWith(tag: String?): Modifier =
if (tag == null) this else this.testTag(tag)
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import com.example.lambda_bbb_events.view.ui.components.common.CampsiteThumbnail

/*
* Defines the campsite owner's lottery management screen.
*
* TODO: Implement the View Booked Dates and Create Lottery buttons.
* TODO: Display the campsite's actual image.
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ import kotlinx.coroutines.launch
/*
* Displays campsite details and provides management actions
* for owners in managing lotteries.
*
* TODO: Make the QR code scannable and navigate to campsite details.
* TODO: Implement campsite deletion with confirmation.
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ import com.example.lambda_bbb_events.view.ui.components.lottery.formatSingleDate
import kotlinx.coroutines.launch
import com.example.lambda_bbb_events.view.ui.components.navigation.rememberBackAction

/*
* Defines the campsite owner's screen for one lottery, showing the lottery
* and the entrants on its waitlist.
*
* TODO: Implement Edit Lottery (US 02.04.06, final checkpoint).
* TODO: Show the winners once winners can be drawn (US 02.05.01).
*/

/**
* Displays a lottery and the list of entrants who joined its waitlist.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ import com.example.lambda_bbb_events.view.ui.components.map.CampsiteMap
/*
* Displays campsite information, including ratings, location,
* tags, description, and reservation availability.
*
* TODO: Make the QR code scannable and navigate to campsite details.
* TODO: Display the campsite location using Google Maps.
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 and log out does not allow re log-in
* TODO: no test tags for log out dialog yet
*/

/**
Expand Down Expand Up @@ -162,7 +162,7 @@ fun ProfileScreen(
}
)

// prompts alert dialog when log-out is clicked
// prompts alert dialogue when log-out is clicked
if (showDialog) {
ShowAlertDialog(
dialogLabel = "Log Out?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import com.example.lambda_bbb_events.view.ui.components.common.ProfilePicture
/*
* Displays more detailed account and app settings.
*
* TODO: no test tags for log out or delete dialogs yet
* Test tags: each row is "settings_<route>" (for example "settings_log_out"), and the
* dialogs are "dialog_log_out" and "dialog_delete_account", with "_confirm" and "_cancel"
* added for their buttons.
*/

/**
Expand All @@ -60,6 +62,13 @@ private val DESTRUCTIVE_ROUTES = setOf("log_out", "delete_account")
*
* @param navController Handles navigation.
* @param controllers Provides the current user.
*
* Reference:
* Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model].
* https://claude.com/claude-code
* Changed with the help of this AI tool (test tags for rows and dialogs).
* Prompts:
* - "Can you finish the to do in settings screen"
*/
@Composable
fun Settings(
Expand Down Expand Up @@ -178,6 +187,7 @@ fun Settings(
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 60.dp)
.testTag("settings_$route")
.clickable {
when (route) {
"delete_account" -> {
Expand Down Expand Up @@ -281,7 +291,8 @@ fun Settings(
confirmText = "Delete",
dismissState = { showDeleteDialog = false },
cancelText = "Cancel",
modifier = Modifier
modifier = Modifier,
testTag = "dialog_delete_account"
)
}

Expand All @@ -297,7 +308,8 @@ fun Settings(
confirmText = "Log Out",
dismissState = { showLogOutDialog = false },
cancelText = "Cancel",
modifier = Modifier
modifier = Modifier,
testTag = "dialog_log_out"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ 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

/*
* Provides the signup screen for creating a new entrant account.
*
* TODO: Replace the logo placeholder when a final logo is added.
* TODO: Add loading and error handling during account creation.
*/

/**
* Displays the account registration screen.
*
Expand Down
Loading