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
1 change: 1 addition & 0 deletions apps/wearos/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ dependencies {
implementation(project(":features:wearos:calculator-fees"))
implementation(project(":features:wearos:calculator-input"))
implementation(project(":features:wearos:calculator-output"))
implementation(project(":features:wearos:onboarding"))
implementation(project(":features:wearos:ui"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ internal class SmartwatchActivityTest {
@Test
fun shouldDisplayActivityContents() {
with(androidComposeTestRule) {
onNodeWithTag("start_calculation_action_button").assertIsDisplayed().performClick()
onNodeWithText("Money amount").assertIsDisplayed()
}
}

@Test
fun shouldShowCalculationBelowRangeFailure() {
with(androidComposeTestRule) {
onNodeWithTag("start_calculation_action_button").assertIsDisplayed().performClick()
onNodeWithText("Money amount").assertIsDisplayed()
onNodeWithTag("calculatorButton_9").performClick().performClick().performClick()
onNodeWithText("βœ”").performClick()
Expand All @@ -46,6 +48,7 @@ internal class SmartwatchActivityTest {
@Test
fun shouldShowCalculationAboveRangeFailure() {
with(androidComposeTestRule) {
onNodeWithTag("start_calculation_action_button").assertIsDisplayed().performClick()
onNodeWithText("Money amount").assertIsDisplayed()
onNodeWithTag("calculatorButton_4").performClick()
onNodeWithTag("calculatorButton_5").performClick()
Expand All @@ -60,6 +63,7 @@ internal class SmartwatchActivityTest {
@Test
fun shouldShowCalculationSuccess() {
with(androidComposeTestRule) {
onNodeWithTag("start_calculation_action_button").assertIsDisplayed().performClick()
onNodeWithText("Money amount").assertIsDisplayed()
onNodeWithTag("calculatorButton_4").performClick()
onNodeWithTag("calculatorButton_5").performClick()
Expand All @@ -76,6 +80,7 @@ internal class SmartwatchActivityTest {
@Test
fun shouldShowFailureThenSuccessMakingCalculation() {
with(androidComposeTestRule) {
onNodeWithTag("start_calculation_action_button").assertIsDisplayed().performClick()
onNodeWithText("Money amount").assertIsDisplayed()

onNodeWithTag("calculatorButton_4").performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,80 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.style.TextAlign
import androidx.wear.compose.foundation.CurvedTextStyle
import androidx.wear.compose.foundation.lazy.ScalingLazyListState
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material3.AppScaffold
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.TimeText
import androidx.wear.compose.material3.TimeTextDefaults
import androidx.wear.compose.material3.timeTextCurvedText
import dev.marlonlom.mocca.wearos.calculator.fees.CalculatorFeesListScreen
import dev.marlonlom.mocca.wearos.calculator.input.CalculatorInputScreen
import dev.marlonlom.mocca.wearos.calculator.output.CalculatorOutputScreen
import dev.marlonlom.mocca.wearos.onboarding.OnboardingScreen
import dev.marlonlom.mocca.wearos.ui.navigation.NavigationHost

/**
* Wear app main content composable.
* Root composable for Wear OS app content.
*
* @author marlonlom
*
* @param isRound Whether the device screen is round.
* @param scalingLazyListState State holder for ScalingLazyColumn scroll position.
*/
@Composable
fun WearAppContent() {
val isRound = LocalConfiguration.current.isScreenRound
val scalingLazyListState = rememberScalingLazyListState()
AppScaffold(
timeText = {
if (!scalingLazyListState.isScrollInProgress) {
val fontStyle = MaterialTheme.typography.bodySmall
if (isRound) {
TimeText { time ->
timeTextCurvedText(
time = time,
style = CurvedTextStyle(
fontSize = fontStyle.fontSize,
),
)
}
} else {
val time = TimeTextDefaults.rememberTimeSource(TimeTextDefaults.timeFormat()).currentTime()
Text(
modifier = Modifier.fillMaxWidth(),
text = time,
textAlign = TextAlign.Center,
style = fontStyle,
fun WearAppContent(
isRound: Boolean = LocalConfiguration.current.isScreenRound,
scalingLazyListState: ScalingLazyListState = rememberScalingLazyListState(),
) = AppScaffold(
timeText = {
if (!scalingLazyListState.isScrollInProgress) {
val fontStyle = MaterialTheme.typography.bodySmall
if (isRound) {
TimeText { time ->
timeTextCurvedText(
time = time,
style = CurvedTextStyle(
fontSize = fontStyle.fontSize,
),
)
}
} else {
val time = TimeTextDefaults.rememberTimeSource(TimeTextDefaults.timeFormat()).currentTime()
Text(
modifier = Modifier.fillMaxWidth(),
text = time,
textAlign = TextAlign.Center,
style = fontStyle,
)
}
},
content = {
NavigationHost(
calculatorInput = { onCalculationReadyAction ->
CalculatorInputScreen(onCalculationReadyAction = onCalculationReadyAction)
},
calculatorOutput = { amountText, onBackNavigationAction ->
CalculatorOutputScreen(
amountText = amountText,
onBackNavigationAction = onBackNavigationAction,
)
},
)
},
)
}
}
},
content = {
NavigationHost(
home = { onCalculateClick, onViewFeesClick ->
OnboardingScreen(
listState = scalingLazyListState,
onCalculateClick = onCalculateClick,
onViewFeesClick = onViewFeesClick,
)
},
viewFees = { onBackNavigationAction ->
CalculatorFeesListScreen(
listState = scalingLazyListState,
onBackNavigationAction = onBackNavigationAction,
)
},
calculatorInput = { onCalculationReadyAction ->
CalculatorInputScreen(onCalculationReadyAction = onCalculationReadyAction)
},
calculatorOutput = { amountText, onBackNavigationAction ->
CalculatorOutputScreen(
amountText = amountText,
onBackNavigationAction = onBackNavigationAction,
)
},
)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package dev.marlonlom.mocca.wearos.calculator.fees

import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import org.junit.Rule
import org.junit.Test

Expand All @@ -19,6 +20,7 @@ internal class CalculatorFeesListScreenUiTest {
with(rule) {
setContent {
CalculatorFeesListScreen(
listState = rememberScalingLazyListState(),
onBackNavigationAction = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.ScalingLazyListState
import androidx.wear.compose.foundation.lazy.itemsIndexed
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.Text
import dev.marlonlom.mocca.wearos.calculator.fees.component.CalculationFeeListItem
Expand All @@ -33,18 +33,18 @@ import dev.marlonlom.mocca.wearos.calculator.fees.domain.CalculatorFeesProvider
*
* @author marlonlom
*
* @param listState Lazy column state.
* @param onBackNavigationAction Callback invoked when the user requests to navigate
* back to the previous screen.
*/
@Composable
fun CalculatorFeesListScreen(onBackNavigationAction: () -> Unit) {
fun CalculatorFeesListScreen(listState: ScalingLazyListState, onBackNavigationAction: () -> Unit) {
BackHandler {
onBackNavigationAction()
}
val feesListingsState: List<CalculatingFeesDomainData> = remember {
CalculatorFeesProvider.provideFees()
}
val listState = rememberScalingLazyListState()
ScalingLazyColumn(
state = listState,
modifier = Modifier
Expand Down
17 changes: 17 additions & 0 deletions features/wearos/onboarding/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id("mocca.compose.lib")
id("mocca.android.lib.wearos")
}

android {
namespace = "dev.marlonlom.mocca.wearos.onboarding"
}

dependencies {
implementation(project(":features:wearos:ui"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/
package dev.marlonlom.mocca.wearos.onboarding

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.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import com.google.common.truth.Truth.assertThat
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.Test
import org.junit.runners.MethodSorters

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
internal class OnboardingScreenUiTest {

@get:Rule
var rule = createComposeRule()

@Test
fun shouldDisplayScreenThenClickedStartCalculationButton() {
with(rule) {
var clicked = false
setContent {
OnboardingScreen(
listState = rememberScalingLazyListState(),
onCalculateClick = { clicked = true },
onViewFeesClick = { },
)
}
onNodeWithTag("start_calculation_action_button").assertIsDisplayed()
onNodeWithTag("view_fees_action_button").assertIsDisplayed()
onNodeWithText("Start calculation").assertIsDisplayed().performClick()
onNodeWithText("View fees").assertIsDisplayed()
assertThat(clicked).isTrue()
}
}

@Test
fun shouldDisplayScreenThenClickedViewFeesButton() {
with(rule) {
var clicked = false
setContent {
OnboardingScreen(
listState = rememberScalingLazyListState(),
onCalculateClick = { },
onViewFeesClick = { clicked = true },
)
}
onNodeWithText("Start calculation").assertIsDisplayed()
onNodeWithText("View fees").assertIsDisplayed().performClick()
assertThat(clicked).isTrue()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/
package dev.marlonlom.mocca.wearos.onboarding.component

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.onNodeWithText
import androidx.compose.ui.test.performClick
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test

internal class StartCalculationButtonUiTest {

@get:Rule
var rule = createComposeRule()

@Test
fun shouldDisplayButtonThenCheckClicked() {
with(rule) {
var clicked = false
setContent {
StartCalculationButton(
onClicked = { clicked = true },
)
}
onNodeWithTag("start_calculation_action_button").assertIsDisplayed()
onNodeWithText("Start calculation").assertIsDisplayed().performClick()
assertThat(clicked).isTrue()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 Marlonlom
* SPDX-License-Identifier: Apache-2.0
*/
package dev.marlonlom.mocca.wearos.onboarding.component

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.onNodeWithText
import androidx.compose.ui.test.performClick
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test

internal class ViewFeesButtonUiTest {

@get:Rule
var rule = createComposeRule()

@Test
fun shouldDisplayButtonThenCheckClicked() {
with(rule) {
var clicked = false
setContent {
ViewFeesButton(
onClicked = { clicked = true },
)
}
onNodeWithTag("view_fees_action_button").assertIsDisplayed()
onNodeWithText("View fees").assertIsDisplayed().performClick()
assertThat(clicked).isTrue()
}
}
}
Loading
Loading