create-cmp-cli 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -9
- package/llms.txt +5 -1
- package/package.json +1 -1
- package/src/lib/adr-seed.mjs +178 -0
- package/src/lib/tabs.mjs +97 -4
- package/src/scaffold.mjs +52 -1
- package/template/.claude/skills/add-feature/SKILL.md +35 -10
- package/template/.claude/skills/add-repository/SKILL.md +1 -1
- package/template/.claude/skills/add-screen/SKILL.md +13 -7
- package/template/.githooks/pre-push +24 -0
- package/template/CLAUDE.md +213 -47
- package/template/README.md +32 -27
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/CrashRecorder.kt +99 -0
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/DbInspector.kt +144 -0
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/InspectorCatalog.kt +19 -0
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/InspectorHttpServer.kt +177 -21
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/InspectorInit.kt +8 -4
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/LiveSemanticsJson.kt +10 -0
- package/template/composeApp/src/androidDebug/kotlin/com/example/app/inspector/NavInspector.kt +62 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/data/AppResultCatching.kt +32 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/data/remote/ItemRepositoryImpl.kt +9 -2
- package/template/composeApp/src/commonMain/kotlin/com/example/app/domain/model/DomainError.kt +21 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/domain/repository/ItemRepository.kt +4 -1
- package/template/composeApp/src/commonMain/kotlin/com/example/app/domain/result/AppResult.kt +23 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/domain/usecase/GetItemsUseCase.kt +4 -1
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/brand/BrandMark.kt +75 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/AppBottomBar.kt +138 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/AppButton.kt +56 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/AppHeader.kt +63 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/AppIconButton.kt +48 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/BaseScreen.kt +16 -8
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/ContentStateContainer.kt +105 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/ContentUiState.kt +18 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/EmptyState.kt +58 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/ErrorState.kt +52 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/ListItemCard.kt +77 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/ScreenColumn.kt +47 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/Shimmer.kt +90 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/components/TestTagAutomation.kt +9 -9
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/home/DetailScreen.kt +5 -27
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/home/HomeScreen.kt +14 -70
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/home/HomeViewModel.kt +33 -13
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/navigation/AppNavHost.kt +22 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/navigation/AppShell.kt +7 -109
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/navigation/NavInspectionHook.kt +31 -0
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/profile/ProfileScreen.kt +4 -27
- package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/theme/Typography.kt +70 -6
- package/template/composeApp/src/commonTest/kotlin/com/example/app/data/AppResultCatchingTest.kt +52 -0
- package/template/composeApp/src/commonTest/kotlin/com/example/app/data/remote/ItemRepositoryImplTest.kt +29 -4
- package/template/composeApp/src/commonTest/kotlin/com/example/app/domain/usecase/GetItemsUseCaseTest.kt +8 -6
- package/template/composeApp/src/commonTest/kotlin/com/example/app/presentation/home/HomeViewModelTest.kt +39 -27
- package/template/composeApp/src/commonTest/kotlin/com/example/app/testing/fakes/FakeItemRepository.kt +10 -6
- package/template/composeApp/src/desktopMain/kotlin/com/example/app/inspector/ComponentStories.kt +300 -0
- package/template/composeApp/src/desktopMain/kotlin/com/example/app/inspector/PreviewDaemon.kt +5 -0
- package/template/composeApp/src/desktopMain/kotlin/com/example/app/inspector/PreviewHarness.kt +91 -1
- package/template/composeApp/src/desktopMain/kotlin/com/example/app/inspector/PreviewRegistry.kt +37 -1
- package/template/composeApp/src/desktopMain/kotlin/com/example/app/inspector/PreviewSemanticsJson.kt +14 -1
- package/template/composeApp/src/desktopTest/kotlin/com/example/app/conformance/ArchitectureConformanceTest.kt +250 -16
- package/template/composeApp/src/desktopTest/kotlin/com/example/app/conformance/ComponentConformanceTest.kt +84 -0
- package/template/composeApp/src/desktopTest/kotlin/com/example/app/presentation/home/HomeScreenTest.kt +36 -4
- package/template/docs/ARCHITECTURE.md +372 -34
- package/template/docs/TESTING.md +13 -5
- package/template/docs/adr/0002-maestro-over-appium-for-e2e.md +39 -0
- package/template/docs/adr/0003-jvm-desktop-target-is-harness-infrastructure.md +39 -0
- package/template/docs/adr/0004-fakes-not-mocks-for-unit-tests.md +48 -0
- package/template/qa/approvals.json +42 -0
- package/template/qa/approve.mjs +139 -0
- package/template/qa/arch-doc.mjs +69 -0
- package/template/qa/comment.mjs +76 -0
- package/template/qa/comments.json +4 -0
- package/template/qa/e2e/smoke.yaml +6 -0
- package/template/qa/golden/home.json +3 -3
- package/template/qa/lib/a11y.mjs +17 -8
- package/template/qa/lib/approvals.mjs +822 -0
- package/template/qa/lib/arch-doc.mjs +451 -0
- package/template/qa/lib/comments.mjs +252 -0
- package/template/qa/lib/component-stories.mjs +183 -0
- package/template/qa/lib/inputs-hash.mjs +5 -1
- package/template/qa/scaffold-feature.mjs +184 -67
- package/template/qa/setup-hooks.mjs +33 -0
- package/template/qa/verify.mjs +181 -15
- package/template/qa/walkthrough.mjs +499 -0
- package/template/specs/app-base.spec.md +49 -7
- package/template/specs/home.spec.md +7 -4
- package/template/specs/intent.md +50 -0
package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/home/HomeViewModel.kt
CHANGED
|
@@ -2,25 +2,35 @@ package __PACKAGE__.presentation.home
|
|
|
2
2
|
|
|
3
3
|
import androidx.lifecycle.ViewModel
|
|
4
4
|
import androidx.lifecycle.viewModelScope
|
|
5
|
+
import __PACKAGE__.domain.model.DomainError
|
|
5
6
|
import __PACKAGE__.domain.model.Item
|
|
7
|
+
import __PACKAGE__.domain.result.AppResult
|
|
6
8
|
import __PACKAGE__.domain.usecase.GetItemsUseCase
|
|
9
|
+
import __PACKAGE__.presentation.components.ContentUiState
|
|
10
|
+
import __PACKAGE__.presentation.components.toContentState
|
|
7
11
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
8
12
|
import kotlinx.coroutines.flow.StateFlow
|
|
9
13
|
import kotlinx.coroutines.flow.asStateFlow
|
|
10
14
|
import kotlinx.coroutines.launch
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* No `try`/`catch` here — ever (ARCH-07). Failures arrive as typed [AppResult.Failure]
|
|
18
|
+
* values from the use case; the ViewModel folds over the result and maps [DomainError]
|
|
19
|
+
* KINDS to user-facing copy. A `CancellationException` thrown while suspended simply
|
|
20
|
+
* cancels this coroutine (structured concurrency) — it never becomes an error state.
|
|
21
|
+
*
|
|
22
|
+
* The state machine is the shared [ContentUiState] (`presentation/components`) — the
|
|
23
|
+
* generalization of this feature's pre-generalization per-feature sealed state (which
|
|
24
|
+
* EH-1 landed): same four arms (Loading/Content/Empty/Error), same fold, made generic once
|
|
25
|
+
* so `ContentStateContainer` can own the non-content arms' rendering instead of every
|
|
26
|
+
* screen hand-folding its own copy.
|
|
27
|
+
*/
|
|
18
28
|
class HomeViewModel(
|
|
19
29
|
private val getItems: GetItemsUseCase,
|
|
20
30
|
) : ViewModel() {
|
|
21
31
|
|
|
22
|
-
private val _state = MutableStateFlow(
|
|
23
|
-
val state: StateFlow<
|
|
32
|
+
private val _state = MutableStateFlow<ContentUiState<List<Item>>>(ContentUiState.Loading)
|
|
33
|
+
val state: StateFlow<ContentUiState<List<Item>>> = _state.asStateFlow()
|
|
24
34
|
|
|
25
35
|
init {
|
|
26
36
|
load()
|
|
@@ -28,12 +38,22 @@ class HomeViewModel(
|
|
|
28
38
|
|
|
29
39
|
fun load() {
|
|
30
40
|
viewModelScope.launch {
|
|
31
|
-
_state.value =
|
|
32
|
-
_state.value =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
HomeUiState(isLoading = false, errorMessage = e.message ?: "Something went wrong")
|
|
41
|
+
_state.value = ContentUiState.Loading
|
|
42
|
+
_state.value = when (val result = getItems()) {
|
|
43
|
+
is AppResult.Success -> result.value.toContentState()
|
|
44
|
+
is AppResult.Failure -> ContentUiState.Error(result.error.toUserMessage())
|
|
36
45
|
}
|
|
37
46
|
}
|
|
38
47
|
}
|
|
39
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Presentation owns user-facing copy: error KINDS become strings here, next to the screen
|
|
52
|
+
* that shows them. A raw `Throwable.message` never reaches the UI — the domain carries no
|
|
53
|
+
* display text at all.
|
|
54
|
+
*/
|
|
55
|
+
internal fun DomainError.toUserMessage(): String = when (this) {
|
|
56
|
+
DomainError.Network -> "Can't reach the server. Check your connection and try again."
|
|
57
|
+
DomainError.NotFound -> "That content isn't available."
|
|
58
|
+
is DomainError.Unexpected -> "Something went wrong. Please try again."
|
|
59
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package __PACKAGE__.presentation.navigation
|
|
2
2
|
|
|
3
3
|
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
4
5
|
import androidx.navigation.NavType
|
|
5
6
|
import androidx.navigation.compose.NavHost
|
|
6
7
|
import androidx.navigation.compose.composable
|
|
@@ -16,6 +17,27 @@ import __PACKAGE__.presentation.profile.ProfileScreen
|
|
|
16
17
|
fun AppNavHost() {
|
|
17
18
|
val navController = rememberNavController()
|
|
18
19
|
|
|
20
|
+
// Report every back-stack change to the common inspection seam — a no-op unless the
|
|
21
|
+
// androidDebug inspector registered a listener (see NavInspectionHook.kt). Best-effort:
|
|
22
|
+
// `currentBackStack` is a live snapshot, not a durable history.
|
|
23
|
+
LaunchedEffect(navController) {
|
|
24
|
+
// The jump half of the same seam: lets the debug inspector navigate by route
|
|
25
|
+
// (its navigate endpoint) so walkthrough coverage enumerates the graph instead of
|
|
26
|
+
// synthesizing taps. Registered/cleared with the controller's composition lifetime;
|
|
27
|
+
// NavController rejects unknown routes itself (IllegalArgumentException).
|
|
28
|
+
NavInspectionHook.navigator = { route -> navController.navigate(route) }
|
|
29
|
+
try {
|
|
30
|
+
navController.currentBackStack.collect { stack ->
|
|
31
|
+
NavInspectionHook.listener?.invoke(
|
|
32
|
+
navController.currentDestination?.route,
|
|
33
|
+
stack.mapNotNull { it.destination.route },
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
} finally {
|
|
37
|
+
NavInspectionHook.navigator = null
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
NavHost(navController = navController, startDestination = Screen.Shell.route) {
|
|
20
42
|
composable(Screen.Shell.route) {
|
|
21
43
|
val tabs = appTabs(
|
|
@@ -1,44 +1,26 @@
|
|
|
1
1
|
package __PACKAGE__.presentation.navigation
|
|
2
2
|
|
|
3
|
-
import androidx.compose.foundation.background
|
|
4
|
-
import androidx.compose.foundation.clickable
|
|
5
|
-
import androidx.compose.foundation.layout.Arrangement
|
|
6
3
|
import androidx.compose.foundation.layout.Box
|
|
7
|
-
import androidx.compose.foundation.layout.Column
|
|
8
|
-
import androidx.compose.foundation.layout.Row
|
|
9
|
-
import androidx.compose.foundation.layout.defaultMinSize
|
|
10
4
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
11
|
-
import androidx.compose.foundation.layout.fillMaxWidth
|
|
12
|
-
import androidx.compose.foundation.layout.height
|
|
13
|
-
import androidx.compose.foundation.layout.navigationBarsPadding
|
|
14
|
-
import androidx.compose.foundation.layout.padding
|
|
15
|
-
import androidx.compose.foundation.layout.size
|
|
16
|
-
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
17
|
-
import androidx.compose.material3.Icon
|
|
18
|
-
import androidx.compose.material3.Text
|
|
19
5
|
import androidx.compose.runtime.Composable
|
|
20
6
|
import androidx.compose.runtime.getValue
|
|
21
7
|
import androidx.compose.runtime.mutableIntStateOf
|
|
22
8
|
import androidx.compose.runtime.saveable.rememberSaveable
|
|
23
9
|
import androidx.compose.runtime.setValue
|
|
24
|
-
import androidx.compose.ui.Alignment
|
|
25
10
|
import androidx.compose.ui.Modifier
|
|
26
|
-
import
|
|
27
|
-
import androidx.compose.ui.semantics.semantics
|
|
28
|
-
import androidx.compose.ui.semantics.testTag
|
|
29
|
-
import androidx.compose.ui.text.font.FontWeight
|
|
30
|
-
import androidx.compose.ui.unit.dp
|
|
31
|
-
import androidx.compose.ui.unit.sp
|
|
11
|
+
import __PACKAGE__.presentation.components.AppBottomBar
|
|
32
12
|
import __PACKAGE__.presentation.components.BaseScreen
|
|
33
13
|
import __PACKAGE__.presentation.components.exposeTestTagsForAutomation
|
|
34
|
-
import __PACKAGE__.presentation.theme.__THEME_PREFIX__Colors
|
|
35
|
-
import __PACKAGE__.presentation.theme.__THEME_PREFIX__Tokens
|
|
36
|
-
import __PACKAGE__.presentation.theme.designToken
|
|
37
14
|
|
|
38
15
|
/**
|
|
39
16
|
* Generic bottom-nav shell. Parameterized by a [tabs] list — NOT role-hardcoded.
|
|
40
17
|
* Hosts the selected tab's content inside a [BaseScreen] so each tab gets correct insets;
|
|
41
18
|
* the bottom bar reserves the navigation-bar inset exactly once.
|
|
19
|
+
*
|
|
20
|
+
* The bar itself is [__PACKAGE__.presentation.components.AppBottomBar] — promoted out of
|
|
21
|
+
* this file into the governed component registry (§4.3 of the component-vocabulary
|
|
22
|
+
* proposal): it was already a mature component, just invisible to the registry as a
|
|
23
|
+
* `private` composable here.
|
|
42
24
|
*/
|
|
43
25
|
@Composable
|
|
44
26
|
fun AppShell(tabs: List<AppTab>) {
|
|
@@ -52,7 +34,7 @@ fun AppShell(tabs: List<AppTab>) {
|
|
|
52
34
|
// The bottom bar owns the navigation-bar inset; the body must not also pad it.
|
|
53
35
|
applyNavBarPadding = false,
|
|
54
36
|
bottomBar = {
|
|
55
|
-
|
|
37
|
+
AppBottomBar(
|
|
56
38
|
tabs = tabs,
|
|
57
39
|
selectedIndex = selected,
|
|
58
40
|
onSelect = { selected = it },
|
|
@@ -64,87 +46,3 @@ fun AppShell(tabs: List<AppTab>) {
|
|
|
64
46
|
}
|
|
65
47
|
}
|
|
66
48
|
}
|
|
67
|
-
|
|
68
|
-
@Composable
|
|
69
|
-
private fun AppBottomNav(
|
|
70
|
-
tabs: List<AppTab>,
|
|
71
|
-
selectedIndex: Int,
|
|
72
|
-
onSelect: (Int) -> Unit,
|
|
73
|
-
) {
|
|
74
|
-
Column(Modifier.fillMaxWidth()) {
|
|
75
|
-
Box(
|
|
76
|
-
Modifier
|
|
77
|
-
.fillMaxWidth()
|
|
78
|
-
.height(1.dp)
|
|
79
|
-
.background(__THEME_PREFIX__Colors.OutlineVariant)
|
|
80
|
-
)
|
|
81
|
-
Row(
|
|
82
|
-
modifier = Modifier
|
|
83
|
-
.fillMaxWidth()
|
|
84
|
-
.background(__THEME_PREFIX__Colors.Surface)
|
|
85
|
-
// Lift tabs above the gesture pill / 3-button nav (maps to iOS safe area).
|
|
86
|
-
.navigationBarsPadding()
|
|
87
|
-
.height(__THEME_PREFIX__Tokens.BottomNavHeight)
|
|
88
|
-
// Inspector: the bottom-nav container self-reports its height token.
|
|
89
|
-
.designToken(
|
|
90
|
-
tokens = listOf("BottomNavHeight"),
|
|
91
|
-
resolved = mapOf("height" to "72dp"),
|
|
92
|
-
)
|
|
93
|
-
.semantics { testTag = "app_bottom_nav" }
|
|
94
|
-
.padding(bottom = 8.dp),
|
|
95
|
-
verticalAlignment = Alignment.CenterVertically,
|
|
96
|
-
horizontalArrangement = Arrangement.SpaceEvenly,
|
|
97
|
-
) {
|
|
98
|
-
tabs.forEachIndexed { index, tab ->
|
|
99
|
-
NavItem(
|
|
100
|
-
label = tab.label,
|
|
101
|
-
selected = selectedIndex == index,
|
|
102
|
-
onClick = { onSelect(index) },
|
|
103
|
-
) {
|
|
104
|
-
Icon(
|
|
105
|
-
imageVector = tab.icon,
|
|
106
|
-
contentDescription = tab.label,
|
|
107
|
-
tint = if (selectedIndex == index) __THEME_PREFIX__Colors.Primary
|
|
108
|
-
else __THEME_PREFIX__Colors.OnSurfaceVariant.copy(alpha = 0.55f),
|
|
109
|
-
modifier = Modifier.size(24.dp),
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Deterministic automation tag for a nav item: `nav_` + the label lowercased with every non-[a-z0-9] run collapsed to `_` and trimmed (e.g. "My Stuff!" → `nav_my_stuff`). Must mirror `navSlug` in create-cmp's engine (src/lib/tabs.mjs), which generates `qa/e2e/smoke.yaml`'s id selectors from the configured tabs — keep the two in sync. */
|
|
118
|
-
private fun navItemTag(label: String): String =
|
|
119
|
-
"nav_" + label.lowercase().replace(Regex("[^a-z0-9]+"), "_").trim('_')
|
|
120
|
-
|
|
121
|
-
@Composable
|
|
122
|
-
private fun NavItem(
|
|
123
|
-
label: String,
|
|
124
|
-
selected: Boolean,
|
|
125
|
-
onClick: () -> Unit,
|
|
126
|
-
icon: @Composable () -> Unit,
|
|
127
|
-
) {
|
|
128
|
-
Column(
|
|
129
|
-
modifier = Modifier
|
|
130
|
-
.clip(RoundedCornerShape(8.dp))
|
|
131
|
-
.clickable(onClick = onClick)
|
|
132
|
-
// a11y: guarantee the 48dp minimum touch target regardless of label width
|
|
133
|
-
// (the inspector's audit_a11y flags anything smaller).
|
|
134
|
-
.defaultMinSize(minWidth = 48.dp, minHeight = 48.dp)
|
|
135
|
-
// Durable selection handle (tests/E2E select by testTag, never display text).
|
|
136
|
-
.semantics { testTag = navItemTag(label) }
|
|
137
|
-
.padding(horizontal = 8.dp, vertical = 4.dp),
|
|
138
|
-
horizontalAlignment = Alignment.CenterHorizontally,
|
|
139
|
-
verticalArrangement = Arrangement.Center,
|
|
140
|
-
) {
|
|
141
|
-
icon()
|
|
142
|
-
Text(
|
|
143
|
-
text = label,
|
|
144
|
-
fontSize = 10.sp,
|
|
145
|
-
fontWeight = if (selected) FontWeight.Bold else FontWeight.SemiBold,
|
|
146
|
-
color = if (selected) __THEME_PREFIX__Colors.Primary else __THEME_PREFIX__Colors.OnSurfaceVariant,
|
|
147
|
-
modifier = Modifier.padding(top = 4.dp),
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package __PACKAGE__.presentation.navigation
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A tiny common seam [AppNavHost] reports every navigation change to. [listener] is `null` by
|
|
5
|
+
* default — a structural no-op — and is registered only by the optional debug-only on-device
|
|
6
|
+
* inspector, when that feature is included in the project. Release builds never register a
|
|
7
|
+
* listener, so invoking a `null` one stays free.
|
|
8
|
+
*
|
|
9
|
+
* This indirection is the whole point: `AppNavHost` lives in commonMain and must never
|
|
10
|
+
* reference a debug-only class directly (a debug-only source set may not even exist in every
|
|
11
|
+
* build of this project) — it only ever talks to this common object.
|
|
12
|
+
*/
|
|
13
|
+
object NavInspectionHook {
|
|
14
|
+
/**
|
|
15
|
+
* Invoked on every back-stack change with `currentRoute` (nullable — no destination
|
|
16
|
+
* resolved yet) and `backStack` (root-to-top, best-effort: derived from
|
|
17
|
+
* `NavController.currentBackStack`, which is itself a live/soon-to-be-live snapshot, not a
|
|
18
|
+
* durable history).
|
|
19
|
+
*/
|
|
20
|
+
var listener: ((currentRoute: String?, backStack: List<String>) -> Unit)? = null
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The JUMP half of the seam: [AppNavHost] registers a function that navigates the real
|
|
24
|
+
* `NavController` to a route. Debug-only callers (the debug inspector's navigate endpoint) use it
|
|
25
|
+
* so a walkthrough can enumerate the nav graph mechanically — coverage by route-jump —
|
|
26
|
+
* instead of synthesizing taps with guessed settle times. Taps remain the tool for
|
|
27
|
+
* BEHAVIOUR proofs (a toggle, a search); this is for COVERAGE. `null` outside debug
|
|
28
|
+
* inspection, and must only ever be invoked on the main thread (NavController requirement).
|
|
29
|
+
*/
|
|
30
|
+
var navigator: ((route: String) -> Unit)? = null
|
|
31
|
+
}
|
|
@@ -1,39 +1,16 @@
|
|
|
1
1
|
package __PACKAGE__.presentation.profile
|
|
2
2
|
|
|
3
|
-
import androidx.compose.foundation.layout.Arrangement
|
|
4
|
-
import androidx.compose.foundation.layout.Column
|
|
5
|
-
import androidx.compose.foundation.layout.fillMaxSize
|
|
6
|
-
import androidx.compose.foundation.layout.padding
|
|
7
3
|
import androidx.compose.material3.MaterialTheme
|
|
8
4
|
import androidx.compose.material3.Text
|
|
9
5
|
import androidx.compose.runtime.Composable
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import androidx.compose.ui.semantics.semantics
|
|
13
|
-
import androidx.compose.ui.semantics.testTag
|
|
14
|
-
import androidx.compose.ui.unit.dp
|
|
15
|
-
import __PACKAGE__.presentation.theme.__THEME_PREFIX__Tokens
|
|
16
|
-
import __PACKAGE__.presentation.theme.designToken
|
|
6
|
+
import __PACKAGE__.presentation.components.AppHeader
|
|
7
|
+
import __PACKAGE__.presentation.components.ScreenColumn
|
|
17
8
|
|
|
18
9
|
// Feature stub. Copy the `home` feature's data→domain→presentation→DI wiring to flesh this out.
|
|
19
10
|
@Composable
|
|
20
11
|
fun ProfileScreen() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.fillMaxSize()
|
|
24
|
-
.designToken(
|
|
25
|
-
tokens = listOf("PaddingPage"),
|
|
26
|
-
resolved = mapOf("padding" to "16dp"),
|
|
27
|
-
)
|
|
28
|
-
.padding(__THEME_PREFIX__Tokens.PaddingPage),
|
|
29
|
-
verticalArrangement = Arrangement.spacedBy(8.dp),
|
|
30
|
-
horizontalAlignment = Alignment.Start,
|
|
31
|
-
) {
|
|
32
|
-
Text(
|
|
33
|
-
text = "Profile",
|
|
34
|
-
style = MaterialTheme.typography.headlineMedium,
|
|
35
|
-
modifier = Modifier.semantics { testTag = "profile_title" },
|
|
36
|
-
)
|
|
12
|
+
ScreenColumn(screenTag = "profile") {
|
|
13
|
+
AppHeader(title = "Profile", screenTag = "profile")
|
|
37
14
|
Text(
|
|
38
15
|
text = "This is a stub screen. Wire it up like the Home feature.",
|
|
39
16
|
style = MaterialTheme.typography.bodyMedium,
|
package/template/composeApp/src/commonMain/kotlin/com/example/app/presentation/theme/Typography.kt
CHANGED
|
@@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
|
|
|
5
5
|
import androidx.compose.ui.text.TextStyle
|
|
6
6
|
import androidx.compose.ui.text.font.FontFamily
|
|
7
7
|
import androidx.compose.ui.text.font.FontWeight
|
|
8
|
+
import androidx.compose.ui.unit.TextUnit
|
|
8
9
|
import androidx.compose.ui.unit.sp
|
|
9
10
|
import org.jetbrains.compose.resources.Font
|
|
10
11
|
import __PACKAGE__.generated.resources.DMSans_Bold
|
|
@@ -22,15 +23,78 @@ val DmSansFontFamily: FontFamily
|
|
|
22
23
|
Font(Res.font.DMSans_Bold, weight = FontWeight.Bold),
|
|
23
24
|
)
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* One rung of the ramp, as plain data. The ramp has to be readable WITHOUT a
|
|
28
|
+
* composition — the preview harness publishes it into `design-system.json`, and
|
|
29
|
+
* the studio console's Design language page renders the type ramp from that
|
|
30
|
+
* catalog. Holding the numbers here (rather than only inside the [Typography]
|
|
31
|
+
* factory below, which needs `@Composable` for the font family) is what keeps
|
|
32
|
+
* the published ramp and the rendered ramp the same numbers by construction.
|
|
33
|
+
*
|
|
34
|
+
* [tracking] is nullable on purpose: `null` means "leave letter spacing
|
|
35
|
+
* unspecified", which is NOT the same as `0.sp` — Compose resolves those
|
|
36
|
+
* differently, and flattening one into the other would silently retrack the
|
|
37
|
+
* mid-ramp styles.
|
|
38
|
+
*/
|
|
39
|
+
data class __THEME_PREFIX__TypeStyle(
|
|
40
|
+
val name: String,
|
|
41
|
+
val weight: Int,
|
|
42
|
+
val sizeSp: Int,
|
|
43
|
+
val lineHeightSp: Int,
|
|
44
|
+
val tracking: Float? = null,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A full ramp, not a minimal one. `display*` are the hero numerics (counts,
|
|
49
|
+
* totals, dashboard figures) — heavy and optically tightened; `headline`/`title`
|
|
50
|
+
* structure the screens; `label*` carries small ALL-CAPS eyebrows and metric
|
|
51
|
+
* units. Tight negative tracking on the big sizes is what makes a data-forward
|
|
52
|
+
* screen read as a considered product rather than a form — a thin ramp is the
|
|
53
|
+
* single cheapest tell of a scaffold.
|
|
54
|
+
*/
|
|
55
|
+
val __THEME_PREFIX__TypeRamp: List<__THEME_PREFIX__TypeStyle> = listOf(
|
|
56
|
+
__THEME_PREFIX__TypeStyle("displayLarge", weight = 700, sizeSp = 56, lineHeightSp = 58, tracking = -1.5f),
|
|
57
|
+
__THEME_PREFIX__TypeStyle("displayMedium", weight = 700, sizeSp = 44, lineHeightSp = 46, tracking = -1.0f),
|
|
58
|
+
__THEME_PREFIX__TypeStyle("displaySmall", weight = 700, sizeSp = 32, lineHeightSp = 36, tracking = -0.5f),
|
|
59
|
+
__THEME_PREFIX__TypeStyle("headlineLarge", weight = 700, sizeSp = 28, lineHeightSp = 32, tracking = -0.5f),
|
|
60
|
+
__THEME_PREFIX__TypeStyle("headlineMedium", weight = 600, sizeSp = 22, lineHeightSp = 28, tracking = -0.3f),
|
|
61
|
+
__THEME_PREFIX__TypeStyle("titleLarge", weight = 600, sizeSp = 18, lineHeightSp = 24),
|
|
62
|
+
__THEME_PREFIX__TypeStyle("titleMedium", weight = 600, sizeSp = 16, lineHeightSp = 22),
|
|
63
|
+
__THEME_PREFIX__TypeStyle("bodyLarge", weight = 400, sizeSp = 16, lineHeightSp = 24),
|
|
64
|
+
__THEME_PREFIX__TypeStyle("bodyMedium", weight = 400, sizeSp = 14, lineHeightSp = 20),
|
|
65
|
+
__THEME_PREFIX__TypeStyle("labelLarge", weight = 600, sizeSp = 14, lineHeightSp = 18),
|
|
66
|
+
__THEME_PREFIX__TypeStyle("labelMedium", weight = 500, sizeSp = 12, lineHeightSp = 16, tracking = 0.5f),
|
|
67
|
+
__THEME_PREFIX__TypeStyle("labelSmall", weight = 600, sizeSp = 11, lineHeightSp = 14, tracking = 0.8f),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
private fun ramp(name: String): __THEME_PREFIX__TypeStyle =
|
|
71
|
+
__THEME_PREFIX__TypeRamp.first { it.name == name }
|
|
72
|
+
|
|
25
73
|
@Composable
|
|
26
74
|
fun remember__THEME_PREFIX__Typography(): Typography {
|
|
27
75
|
val dmSans = DmSansFontFamily
|
|
76
|
+
fun style(name: String): TextStyle {
|
|
77
|
+
val spec = ramp(name)
|
|
78
|
+
return TextStyle(
|
|
79
|
+
fontFamily = dmSans,
|
|
80
|
+
fontWeight = FontWeight(spec.weight),
|
|
81
|
+
fontSize = spec.sizeSp.sp,
|
|
82
|
+
lineHeight = spec.lineHeightSp.sp,
|
|
83
|
+
letterSpacing = spec.tracking?.sp ?: TextUnit.Unspecified,
|
|
84
|
+
)
|
|
85
|
+
}
|
|
28
86
|
return Typography(
|
|
29
|
-
displayLarge =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
87
|
+
displayLarge = style("displayLarge"),
|
|
88
|
+
displayMedium = style("displayMedium"),
|
|
89
|
+
displaySmall = style("displaySmall"),
|
|
90
|
+
headlineLarge = style("headlineLarge"),
|
|
91
|
+
headlineMedium = style("headlineMedium"),
|
|
92
|
+
titleLarge = style("titleLarge"),
|
|
93
|
+
titleMedium = style("titleMedium"),
|
|
94
|
+
bodyLarge = style("bodyLarge"),
|
|
95
|
+
bodyMedium = style("bodyMedium"),
|
|
96
|
+
labelLarge = style("labelLarge"),
|
|
97
|
+
labelMedium = style("labelMedium"),
|
|
98
|
+
labelSmall = style("labelSmall"),
|
|
35
99
|
)
|
|
36
100
|
}
|
package/template/composeApp/src/commonTest/kotlin/com/example/app/data/AppResultCatchingTest.kt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package __PACKAGE__.data
|
|
2
|
+
|
|
3
|
+
import __PACKAGE__.domain.model.DomainError
|
|
4
|
+
import __PACKAGE__.domain.result.AppResult
|
|
5
|
+
import kotlin.coroutines.cancellation.CancellationException
|
|
6
|
+
import kotlin.test.Test
|
|
7
|
+
import kotlin.test.assertEquals
|
|
8
|
+
import kotlin.test.assertFailsWith
|
|
9
|
+
import kotlin.test.assertIs
|
|
10
|
+
import kotlinx.coroutines.test.runTest
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The exception-translation helper's contract (`specs/app-base.spec.md` ARCH-08):
|
|
14
|
+
* success wraps, failures map to typed kinds, and cancellation ALWAYS propagates.
|
|
15
|
+
*/
|
|
16
|
+
class AppResultCatchingTest {
|
|
17
|
+
|
|
18
|
+
@Test
|
|
19
|
+
fun `wraps the block's value in Success`() = runTest {
|
|
20
|
+
val result = suspendRunCatching { 42 }
|
|
21
|
+
|
|
22
|
+
assertEquals(AppResult.Success(42), result)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Test
|
|
26
|
+
fun `maps a thrown exception through mapError to a typed Failure`() = runTest {
|
|
27
|
+
val boom = IllegalStateException("io broke")
|
|
28
|
+
|
|
29
|
+
val result = suspendRunCatching(mapError = { DomainError.Network }) { throw boom }
|
|
30
|
+
|
|
31
|
+
assertEquals(AppResult.Failure(DomainError.Network), result)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Test
|
|
35
|
+
fun `files unclassified exceptions under Unexpected with the cause preserved`() = runTest {
|
|
36
|
+
val boom = IllegalStateException("io broke")
|
|
37
|
+
|
|
38
|
+
val result = suspendRunCatching { throw boom }
|
|
39
|
+
|
|
40
|
+
val failure = assertIs<AppResult.Failure>(result)
|
|
41
|
+
val error = assertIs<DomainError.Unexpected>(failure.error)
|
|
42
|
+
assertEquals(boom, error.cause)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// SPEC: ARCH-08
|
|
46
|
+
@Test
|
|
47
|
+
fun `rethrows CancellationException instead of mapping it`() = runTest {
|
|
48
|
+
assertFailsWith<CancellationException> {
|
|
49
|
+
suspendRunCatching { throw CancellationException("scope cancelled") }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,26 +1,51 @@
|
|
|
1
1
|
package __PACKAGE__.data.remote
|
|
2
2
|
|
|
3
|
+
import __PACKAGE__.domain.result.AppResult
|
|
3
4
|
import kotlin.test.Test
|
|
4
5
|
import kotlin.test.assertEquals
|
|
6
|
+
import kotlin.test.assertNull
|
|
5
7
|
import kotlin.test.assertTrue
|
|
8
|
+
import kotlin.test.fail
|
|
9
|
+
import kotlinx.coroutines.launch
|
|
6
10
|
import kotlinx.coroutines.test.runTest
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* The exemplar data-layer test. [ItemRepositoryImpl] is the template's dependency-light
|
|
10
14
|
* example source; when you swap it for a real Firestore/Ktor + Room implementation, keep
|
|
11
|
-
* this shape: test the repository through its DOMAIN contract,
|
|
12
|
-
* time (the simulated I/O delay costs nothing
|
|
15
|
+
* this shape: test the repository through its DOMAIN contract (AppResult in, never an
|
|
16
|
+
* exception out), under `runTest` virtual time (the simulated I/O delay costs nothing
|
|
17
|
+
* here — delays are skipped, not slept).
|
|
13
18
|
*/
|
|
14
19
|
class ItemRepositoryImplTest {
|
|
15
20
|
|
|
16
21
|
private val repository = ItemRepositoryImpl()
|
|
17
22
|
|
|
18
23
|
@Test
|
|
19
|
-
fun `returns the seeded example items`() = runTest {
|
|
20
|
-
val items = repository.getItems()
|
|
24
|
+
fun `returns the seeded example items as Success`() = runTest {
|
|
25
|
+
val items = when (val result = repository.getItems()) {
|
|
26
|
+
is AppResult.Success -> result.value
|
|
27
|
+
is AppResult.Failure -> fail("example source should succeed, got $result")
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
assertTrue(items.isNotEmpty(), "example source should seed items")
|
|
23
31
|
assertEquals(items.size, items.map { it.id }.toSet().size, "item ids must be unique")
|
|
24
32
|
assertTrue(items.all { it.title.isNotBlank() }, "every item needs a title")
|
|
25
33
|
}
|
|
34
|
+
|
|
35
|
+
// SPEC: ARCH-08
|
|
36
|
+
@Test
|
|
37
|
+
fun `cancellation propagates - a cancelled load never completes as a Failure`() = runTest {
|
|
38
|
+
// A REAL cancellation: getItems() is suspended in its simulated I/O when the caller's
|
|
39
|
+
// job is cancelled. suspendRunCatching must rethrow the CancellationException — if it
|
|
40
|
+
// mapped it, `result` would hold a Failure and this test would fail.
|
|
41
|
+
var result: Any? = null
|
|
42
|
+
val job = launch { result = repository.getItems() }
|
|
43
|
+
testScheduler.runCurrent() // enter getItems() up to the suspension point
|
|
44
|
+
|
|
45
|
+
job.cancel()
|
|
46
|
+
job.join()
|
|
47
|
+
|
|
48
|
+
assertTrue(job.isCancelled, "the load job should end cancelled, not completed")
|
|
49
|
+
assertNull(result, "a cancelled load must produce NO result — especially not a Failure")
|
|
50
|
+
}
|
|
26
51
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
package __PACKAGE__.domain.usecase
|
|
2
2
|
|
|
3
|
+
import __PACKAGE__.domain.model.DomainError
|
|
3
4
|
import __PACKAGE__.domain.model.Item
|
|
5
|
+
import __PACKAGE__.domain.result.AppResult
|
|
4
6
|
import __PACKAGE__.testing.fakes.FakeItemRepository
|
|
5
7
|
import kotlin.test.Test
|
|
6
8
|
import kotlin.test.assertEquals
|
|
7
|
-
import kotlin.test.assertFailsWith
|
|
8
9
|
import kotlinx.coroutines.test.runTest
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* The exemplar use-case test. Use cases are pure business actions with no framework
|
|
12
13
|
* dependencies, so their tests are the simplest in the pyramid: fake in, behavior out.
|
|
14
|
+
* Results stay typed end-to-end — nothing here throws or catches.
|
|
13
15
|
*/
|
|
14
16
|
class GetItemsUseCaseTest {
|
|
15
17
|
|
|
@@ -17,21 +19,21 @@ class GetItemsUseCaseTest {
|
|
|
17
19
|
private val getItems = GetItemsUseCase(repository)
|
|
18
20
|
|
|
19
21
|
@Test
|
|
20
|
-
fun `returns the repository's items`() = runTest {
|
|
22
|
+
fun `returns the repository's items as Success`() = runTest {
|
|
21
23
|
val expected = listOf(
|
|
22
24
|
Item(id = "1", title = "First", subtitle = "a"),
|
|
23
25
|
Item(id = "2", title = "Second", subtitle = "b"),
|
|
24
26
|
)
|
|
25
27
|
repository.items = expected
|
|
26
28
|
|
|
27
|
-
assertEquals(expected, getItems())
|
|
29
|
+
assertEquals(AppResult.Success(expected), getItems())
|
|
28
30
|
assertEquals(1, repository.getItemsCallCount)
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
@Test
|
|
32
|
-
fun `
|
|
33
|
-
repository.
|
|
34
|
+
fun `passes a typed failure through untouched`() = runTest {
|
|
35
|
+
repository.failure = DomainError.Network
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
assertEquals(AppResult.Failure(DomainError.Network), getItems())
|
|
36
38
|
}
|
|
37
39
|
}
|