diff --git a/app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt b/app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt index 954bf82f7..69605c4cf 100644 --- a/app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt +++ b/app/src/androidTest/java/com/android/periodpals/ui/alert/AlertScreenTest.kt @@ -44,9 +44,9 @@ class AlertScreenTest { composeTestRule.onNodeWithTag("alertLocation").assertIsDisplayed() composeTestRule.onNodeWithTag("alertMessage").assertIsDisplayed() composeTestRule - .onNodeWithTag("alertSubmit") - .assertIsDisplayed() - .assertTextEquals("Ask for Help") + .onNodeWithTag("alertSubmit") + .assertIsDisplayed() + .assertTextEquals("Ask for Help") } @Test diff --git a/app/src/main/java/com/android/periodpals/ui/alert/AlertScreen.kt b/app/src/main/java/com/android/periodpals/ui/alert/AlertScreen.kt index 1ff2c7fe3..da0b2f80e 100644 --- a/app/src/main/java/com/android/periodpals/ui/alert/AlertScreen.kt +++ b/app/src/main/java/com/android/periodpals/ui/alert/AlertScreen.kt @@ -44,122 +44,124 @@ fun AlertScreen(navigationActions: NavigationActions) { val (urgencyIsSelected, setUrgencyIsSelected) = remember { mutableStateOf(false) } Scaffold( - modifier = Modifier.testTag("alertScreen"), - bottomBar = { - BottomNavigationMenu( - onTabSelect = { route -> navigationActions.navigateTo(route) }, - tabList = LIST_TOP_LEVEL_DESTINATION, - selectedItem = navigationActions.currentRoute(), - ) - }, - topBar = { TopAppBar(title = "Create Alert") }, - content = { paddingValues -> - Column( - modifier = Modifier.fillMaxSize().padding(30.dp).padding(paddingValues), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.SpaceEvenly, - ) { - // Text Instruction - Text( - "Push a notification to users near you! If they are available and have the products you need, they'll be able to help you!", - modifier = Modifier.testTag("alertInstruction"), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.titleSmall, + modifier = Modifier.testTag("alertScreen"), + bottomBar = { + BottomNavigationMenu( + onTabSelect = { route -> navigationActions.navigateTo(route) }, + tabList = LIST_TOP_LEVEL_DESTINATION, + selectedItem = navigationActions.currentRoute(), ) + }, + topBar = { TopAppBar(title = "Create Alert") }, + content = { paddingValues -> + Column( + modifier = Modifier.fillMaxSize().padding(30.dp).padding(paddingValues), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.SpaceEvenly, + ) { + // Text Instruction + Text( + "Push a notification to users near you! If they are available and have the products you need, they'll be able to help you!", + modifier = Modifier.testTag("alertInstruction"), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.titleSmall, + ) - // Product - ExposedDropdownMenuSample( - listOf("Tampons", "Pads", "No Preference"), - "Product Needed", - "alertProduct", - setProductIsSelected, - ) + // Product + ExposedDropdownMenuSample( + listOf("Tampons", "Pads", "No Preference"), + "Product Needed", + "alertProduct", + setProductIsSelected, + ) - // Urgency - ExposedDropdownMenuSample( - listOf("!!! High", "!! Medium", "! Low"), - "Urgency level", - "alertUrgency", - setUrgencyIsSelected, - ) + // Urgency + ExposedDropdownMenuSample( + listOf("!!! High", "!! Medium", "! Low"), + "Urgency level", + "alertUrgency", + setUrgencyIsSelected, + ) - // Location - OutlinedTextField( - value = location, - onValueChange = { location = it }, - label = { Text("Location") }, - placeholder = { Text("Enter your location") }, - modifier = Modifier.fillMaxWidth().testTag("alertLocation"), - ) + // Location + OutlinedTextField( + value = location, + onValueChange = { location = it }, + label = { Text("Location") }, + placeholder = { Text("Enter your location") }, + modifier = Modifier.fillMaxWidth().testTag("alertLocation"), + ) - // Message - OutlinedTextField( - value = message, - onValueChange = { message = it }, - label = { Text("Message") }, - placeholder = { Text("Write a message for the other users") }, - modifier = Modifier.fillMaxWidth().height(150.dp).testTag("alertMessage"), - ) + // Message + OutlinedTextField( + value = message, + onValueChange = { message = it }, + label = { Text("Message") }, + placeholder = { Text("Write a message for the other users") }, + modifier = Modifier.fillMaxWidth().height(150.dp).testTag("alertMessage"), + ) - // Submit Button - Button( - onClick = { - if (location.isEmpty()) { - Toast.makeText(context, "Please enter a location", Toast.LENGTH_SHORT).show() - } else if (!productIsSelected) { - Toast.makeText(context, "Please select a product", Toast.LENGTH_SHORT).show() - } else if (!urgencyIsSelected) { - Toast.makeText(context, "Please select an urgency level", Toast.LENGTH_SHORT).show() - } else { - navigationActions.navigateTo(Screen.ALERT_LIST) - } - }, - modifier = Modifier.width(300.dp).height(100.dp).testTag("alertSubmit").padding(16.dp), - ) { - Text("Ask for Help", style = MaterialTheme.typography.headlineMedium) + // Submit Button + Button( + onClick = { + if (location.isEmpty()) { + Toast.makeText(context, "Please enter a location", Toast.LENGTH_SHORT).show() + } else if (!productIsSelected) { + Toast.makeText(context, "Please select a product", Toast.LENGTH_SHORT).show() + } else if (!urgencyIsSelected) { + Toast.makeText(context, "Please select an urgency level", Toast.LENGTH_SHORT) + .show() + } else { + navigationActions.navigateTo(Screen.ALERT_LIST) + } + }, + modifier = + Modifier.width(300.dp).height(100.dp).testTag("alertSubmit").padding(16.dp), + ) { + Text("Ask for Help", style = MaterialTheme.typography.headlineMedium) + } } - } - }, + }, ) } @OptIn(ExperimentalMaterial3Api::class) @Composable fun ExposedDropdownMenuSample( - list: List, - label: String, - testTag: String, - setIsSelected: (Boolean) -> Unit, + list: List, + label: String, + testTag: String, + setIsSelected: (Boolean) -> Unit, ) { var options = list var expanded by remember { mutableStateOf(false) } var text by remember { mutableStateOf("Please choose one option") } ExposedDropdownMenuBox( - modifier = Modifier.testTag(testTag), - expanded = expanded, - onExpandedChange = { expanded = it }, + modifier = Modifier.testTag(testTag), + expanded = expanded, + onExpandedChange = { expanded = it }, ) { TextField( - modifier = Modifier.menuAnchor(), - value = text, - onValueChange = {}, - singleLine = true, - label = { Text(label) }, - trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) }, - colors = ExposedDropdownMenuDefaults.textFieldColors(), + modifier = Modifier.menuAnchor(), + value = text, + onValueChange = {}, + singleLine = true, + label = { Text(label) }, + trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) }, + colors = ExposedDropdownMenuDefaults.textFieldColors(), ) ExposedDropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) { options.forEach { option -> DropdownMenuItem( - modifier = Modifier, - text = { Text(option) }, - onClick = { - text = option - expanded = false - setIsSelected(true) - }, - contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding, + modifier = Modifier, + text = { Text(option) }, + onClick = { + text = option + expanded = false + setIsSelected(true) + }, + contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding, ) } }