Obsłuż wielodniowe kursy kierowcy

This commit is contained in:
admin
2026-07-10 14:50:38 +02:00
parent 3267fee439
commit e49e7c358e
9 changed files with 224 additions and 36 deletions
+2 -2
View File
@@ -34,8 +34,8 @@ android {
applicationId = "pl.firmatpp.kierowca" applicationId = "pl.firmatpp.kierowca"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 102 versionCode = 103
versionName = "1.0.49" versionName = "1.0.50"
setProperty("archivesBaseName", "pl.firmatpp.kierowca") setProperty("archivesBaseName", "pl.firmatpp.kierowca")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -244,6 +244,7 @@ data class RealtimeStatusBody(
data class DriverRouteDto( data class DriverRouteDto(
val id: String, val id: String,
val routeDate: String? = null, val routeDate: String? = null,
val unloadingDate: String? = null,
val startsAt: String, val startsAt: String,
val originName: String, val originName: String,
val destinationName: String, val destinationName: String,
@@ -3,6 +3,7 @@ package pl.firmatpp.kierowca.data.sync
import android.content.Context import android.content.Context
import com.google.gson.Gson import com.google.gson.Gson
import java.io.IOException import java.io.IOException
import java.time.LocalDate
import pl.firmatpp.kierowca.data.DriverRepository import pl.firmatpp.kierowca.data.DriverRepository
import pl.firmatpp.kierowca.data.model.BootstrapResponse import pl.firmatpp.kierowca.data.model.BootstrapResponse
import pl.firmatpp.kierowca.data.model.DriverRouteDto import pl.firmatpp.kierowca.data.model.DriverRouteDto
@@ -72,18 +73,19 @@ class DriverSyncRepository(
), ),
) )
val selectedDate = date ?: return (routeVisibleDates(route) + listOfNotNull(date)).distinct().forEach { selectedDate ->
val cachedBootstrap = dao.bootstrap(selectedDate) ?: return val cachedBootstrap = dao.bootstrap(selectedDate) ?: return@forEach
val response = gson.fromJson(cachedBootstrap.payloadJson, BootstrapResponse::class.java) val response = gson.fromJson(cachedBootstrap.payloadJson, BootstrapResponse::class.java)
val updatedRoutes = response.routes.today.map { item -> if (item.id == route.id) route else item } val updatedRoutes = response.routes.today.map { item -> if (item.id == route.id) route else item }
dao.upsertBootstrap( dao.upsertBootstrap(
cachedBootstrap.copy( cachedBootstrap.copy(
payloadJson = gson.toJson(response.copy(routes = response.routes.copy(today = updatedRoutes))), payloadJson = gson.toJson(response.copy(routes = response.routes.copy(today = updatedRoutes))),
checksum = null, checksum = null,
version = null, version = null,
syncedAtEpochMillis = syncedAt, syncedAtEpochMillis = syncedAt,
), ),
) )
}
} }
suspend fun fetchSyncState(date: String?, routeId: String?): SyncStateResponse = suspend fun fetchSyncState(date: String?, routeId: String?): SyncStateResponse =
@@ -146,6 +148,18 @@ class DriverSyncRepository(
private fun currentDateFallback(): String = java.time.LocalDate.now().toString() private fun currentDateFallback(): String = java.time.LocalDate.now().toString()
private fun routeVisibleDates(route: DriverRouteDto): List<String> {
val start = route.routeDate?.let { runCatching { LocalDate.parse(it) }.getOrNull() } ?: return emptyList()
val end = route.unloadingDate
?.let { runCatching { LocalDate.parse(it) }.getOrNull() }
?.takeUnless { it.isBefore(start) }
?: start
return generateSequence(start) { date -> date.plusDays(1).takeIf { !it.isAfter(end) } }
.map(LocalDate::toString)
.toList()
}
companion object { companion object {
const val SCOPE_ROUTES = "routes" const val SCOPE_ROUTES = "routes"
const val SCOPE_ROUTE_DETAIL = "route_detail" const val SCOPE_ROUTE_DETAIL = "route_detail"
@@ -281,7 +281,7 @@ fun DriverApp(
title = "Waga załadunku", title = "Waga załadunku",
stage = "loading", stage = "loading",
weightLabel = "Waga z wagi", weightLabel = "Waga z wagi",
submitLabel = "Rozpocznij kurs", submitLabel = "Załaduj",
showWeightInput = true, showWeightInput = true,
showPhotoActions = false, showPhotoActions = false,
showPhotoGrid = false, showPhotoGrid = false,
@@ -295,10 +295,10 @@ fun DriverApp(
) )
DriverScreen.FinishRoute -> RouteStageScreen( DriverScreen.FinishRoute -> RouteStageScreen(
state = state, state = state,
title = "Zakończ kurs", title = "Rozładunek",
stage = "unloading", stage = "unloading",
weightLabel = "Waga na rozładunku", weightLabel = "Waga na rozładunku",
submitLabel = "Zakończ kurs", submitLabel = "Rozładuj",
onBack = viewModel::back, onBack = viewModel::back,
onWeightChange = viewModel::updateRouteStageWeight, onWeightChange = viewModel::updateRouteStageWeight,
onUpload = { uri, source, metadata -> viewModel.uploadPhoto(uri, source, metadata, "unloading") }, onUpload = { uri, source, metadata -> viewModel.uploadPhoto(uri, source, metadata, "unloading") },
@@ -2030,6 +2030,8 @@ private fun StitchRouteCard(route: DriverRouteDto, onRoute: (String) -> Unit) {
) )
} }
} }
Spacer(Modifier.height(12.dp))
RouteScheduleLabel(route)
Spacer(Modifier.height(if (compactWidth) 18.dp else 26.dp)) Spacer(Modifier.height(if (compactWidth) 18.dp else 26.dp))
RouteTimeline(display.origin, display.destination) RouteTimeline(display.origin, display.destination)
} }
@@ -2061,6 +2063,21 @@ private fun StatusChip(status: String, color: Color) {
) )
} }
@Composable
private fun RouteScheduleLabel(route: DriverRouteDto) {
Text(
routeScheduleSummary(route),
modifier = Modifier
.fillMaxWidth()
.background(TppTheme.colors.panel, RoundedCornerShape(4.dp))
.padding(horizontal = 10.dp, vertical = 8.dp),
color = TppTheme.colors.muted,
fontFamily = FontFamily.Monospace,
fontWeight = FontWeight.SemiBold,
style = MaterialTheme.typography.labelMedium,
)
}
@Composable @Composable
private fun RouteTimeline(origin: String, destination: String) { private fun RouteTimeline(origin: String, destination: String) {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(14.dp)) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(14.dp)) {
@@ -2774,9 +2791,19 @@ private fun RouteLifecycleSection(
val steps = routeFlowSteps(route, routeActions) val steps = routeFlowSteps(route, routeActions)
val callout = routeSyncCallout(routeActions) val callout = routeSyncCallout(routeActions)
val action = routeLifecyclePrimaryAction(route, selectedDate) val action = routeLifecyclePrimaryAction(route, selectedDate)
val instruction = routeTodayInstruction(route, selectedDate)
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) { Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) {
RouteFlowStepper(steps) RouteFlowStepper(steps)
if (instruction != null) {
RouteStateMessage(
text = instruction,
icon = Icons.Outlined.Info,
container = TppTheme.colors.panel,
outline = TppTheme.colors.outline,
color = TppTheme.colors.ink,
)
}
if (!feedback.isNullOrBlank()) { if (!feedback.isNullOrBlank()) {
RouteStateMessage( RouteStateMessage(
text = feedback, text = feedback,
@@ -2885,6 +2912,15 @@ private fun RouteFlowStepItem(step: RouteFlowStepUi, modifier: Modifier = Modifi
maxLines = 2, maxLines = 2,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
if (step.dateLabel != null) {
Text(
step.dateLabel,
color = TppTheme.colors.muted,
fontFamily = FontFamily.Monospace,
fontWeight = FontWeight.SemiBold,
style = MaterialTheme.typography.labelSmall,
)
}
Text( Text(
step.stateLabel, step.stateLabel,
color = color, color = color,
@@ -2996,6 +3032,7 @@ private fun ManifestSection(route: DriverRouteDto, selectedDate: String, onNavig
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
color = TppTheme.colors.ink, color = TppTheme.colors.ink,
) )
RouteScheduleLabel(route)
} }
} }
HorizontalDivider(color = TppTheme.colors.outline.copy(alpha = 0.65f)) HorizontalDivider(color = TppTheme.colors.outline.copy(alpha = 0.65f))
@@ -34,6 +34,7 @@ data class RouteFlowStepUi(
val title: String, val title: String,
val state: RouteFlowStepState, val state: RouteFlowStepState,
val stateLabel: String, val stateLabel: String,
val dateLabel: String? = null,
) )
data class RouteLifecycleActionUi( data class RouteLifecycleActionUi(
@@ -49,12 +50,65 @@ data class RouteSyncCalloutUi(
fun canManageRoutePhotos(selectedDate: String, today: LocalDate = LocalDate.now()): Boolean = fun canManageRoutePhotos(selectedDate: String, today: LocalDate = LocalDate.now()): Boolean =
runCatching { LocalDate.parse(selectedDate).isEqual(today) }.getOrDefault(false) runCatching { LocalDate.parse(selectedDate).isEqual(today) }.getOrDefault(false)
fun routeIsActiveToday(
route: DriverRouteDto,
selectedDate: String,
today: LocalDate = LocalDate.now(),
): Boolean {
val viewedDate = runCatching { LocalDate.parse(selectedDate) }.getOrNull() ?: return false
val loadingDate = route.routeDate?.let { runCatching { LocalDate.parse(it) }.getOrNull() } ?: return false
val unloadingDate = route.unloadingDate
?.let { runCatching { LocalDate.parse(it) }.getOrNull() }
?: loadingDate
return viewedDate == today && !today.isBefore(loadingDate) && !today.isAfter(unloadingDate)
}
fun routeUnloadingDate(route: DriverRouteDto): String? = route.unloadingDate ?: route.routeDate
fun routeScheduleDateLabel(date: String?): String =
date
?.let { runCatching { LocalDate.parse(it).format(shortDateFormatter) }.getOrNull() }
?: ""
fun routeScheduleSummary(route: DriverRouteDto): String {
val loading = routeScheduleDateLabel(route.routeDate)
val unloading = routeScheduleDateLabel(routeUnloadingDate(route))
return if (route.unloadingDate == null) {
"Załadunek: $loading · Rozładunek: ten sam dzień"
} else {
"Załadunek: $loading · Rozładunek: $unloading"
}
}
fun routeTodayInstruction(
route: DriverRouteDto,
selectedDate: String,
today: LocalDate = LocalDate.now(),
): String? {
if (!routeIsActiveToday(route, selectedDate, today)) return null
val loadingDate = route.routeDate?.let { runCatching { LocalDate.parse(it) }.getOrNull() } ?: return null
val unloadingDate = routeUnloadingDate(route)?.let { runCatching { LocalDate.parse(it) }.getOrNull() } ?: loadingDate
return when {
route.status == "ZAKOŃCZONA" -> "Kurs zakończony."
loadingDate == unloadingDate -> "Dziś: załadunek i rozładunek."
today == loadingDate -> "Dziś: załadunek."
today == unloadingDate && route.status == "ZAPLANOWANA" -> "Dziś: rozładunek. Załadunek możesz potwierdzić dzisiaj."
today == unloadingDate -> "Dziś: rozładunek."
else -> "Kurs jest w trasie. Rozładunek: ${routeScheduleDateLabel(routeUnloadingDate(route))}."
}
}
fun canCompleteRouteFromDriverApp( fun canCompleteRouteFromDriverApp(
route: DriverRouteDto, route: DriverRouteDto,
selectedDate: String, selectedDate: String,
today: LocalDate = LocalDate.now(), today: LocalDate = LocalDate.now(),
): Boolean = ): Boolean =
canManageRoutePhotos(selectedDate, today) runCatching { LocalDate.parse(selectedDate) }.getOrNull() == today
&& routeUnloadingDate(route)?.let { runCatching { LocalDate.parse(it) }.getOrNull() } == today
&& route.status in setOf("ZAPLANOWANA", "W TRAKCIE") && route.status in setOf("ZAPLANOWANA", "W TRAKCIE")
fun canStartRouteFromDriverApp( fun canStartRouteFromDriverApp(
@@ -62,7 +116,7 @@ fun canStartRouteFromDriverApp(
selectedDate: String, selectedDate: String,
today: LocalDate = LocalDate.now(), today: LocalDate = LocalDate.now(),
): Boolean = ): Boolean =
canManageRoutePhotos(selectedDate, today) routeIsActiveToday(route, selectedDate, today)
&& route.status == "ZAPLANOWANA" && route.status == "ZAPLANOWANA"
fun canFinishRouteFromDriverApp( fun canFinishRouteFromDriverApp(
@@ -70,8 +124,9 @@ fun canFinishRouteFromDriverApp(
selectedDate: String, selectedDate: String,
today: LocalDate = LocalDate.now(), today: LocalDate = LocalDate.now(),
): Boolean = ): Boolean =
canManageRoutePhotos(selectedDate, today) route.status == "W TRAKCIE"
&& route.status == "W TRAKCIE" && runCatching { LocalDate.parse(selectedDate) }.getOrNull() == today
&& routeUnloadingDate(route)?.let { runCatching { LocalDate.parse(it) }.getOrNull() } == today
fun canSubmitRouteStageForm(weightText: String, serverPhotoCount: Int, localUploadCount: Int): Boolean { fun canSubmitRouteStageForm(weightText: String, serverPhotoCount: Int, localUploadCount: Int): Boolean {
return routeStageSubmitBlocker(weightText, serverPhotoCount, localUploadCount) == null return routeStageSubmitBlocker(weightText, serverPhotoCount, localUploadCount) == null
@@ -116,8 +171,8 @@ fun routeLifecyclePrimaryAction(
today: LocalDate = LocalDate.now(), today: LocalDate = LocalDate.now(),
): RouteLifecycleActionUi? = ): RouteLifecycleActionUi? =
when { when {
canStartRouteFromDriverApp(route, selectedDate, today) -> RouteLifecycleActionUi("Rozpocznij kurs", RouteLifecycleAction.Start) canStartRouteFromDriverApp(route, selectedDate, today) -> RouteLifecycleActionUi("Załaduj", RouteLifecycleAction.Start)
canFinishRouteFromDriverApp(route, selectedDate, today) -> RouteLifecycleActionUi("Zakończ kurs", RouteLifecycleAction.Finish) canFinishRouteFromDriverApp(route, selectedDate, today) -> RouteLifecycleActionUi("Rozładuj", RouteLifecycleAction.Finish)
else -> null else -> null
} }
@@ -175,10 +230,10 @@ fun routeFlowSteps(route: DriverRouteDto, actions: List<RouteActionEntity>): Lis
} }
return listOf( return listOf(
RouteFlowStepUi("loading_photos", "Zdjęcia załadunku", loadingPhotosState, routeFlowStateLabel(loadingPhotosState)), RouteFlowStepUi("loading_photos", "Zdjęcia załadunku", loadingPhotosState, routeFlowStateLabel(loadingPhotosState), routeScheduleDateLabel(route.routeDate)),
RouteFlowStepUi("loading_weight", "Waga załadunku", loadingWeightState, routeFlowStateLabel(loadingWeightState)), RouteFlowStepUi("loading_weight", "Waga załadunku", loadingWeightState, routeFlowStateLabel(loadingWeightState), routeScheduleDateLabel(route.routeDate)),
RouteFlowStepUi("transit", "W trasie", transitState, routeFlowStateLabel(transitState)), RouteFlowStepUi("transit", "W trasie", transitState, routeFlowStateLabel(transitState)),
RouteFlowStepUi("unloading", "Rozładunek", unloadingState, routeFlowStateLabel(unloadingState)), RouteFlowStepUi("unloading", "Rozładunek", unloadingState, routeFlowStateLabel(unloadingState), routeScheduleDateLabel(routeUnloadingDate(route))),
) )
} }
@@ -96,6 +96,7 @@ data class DriverUiState(
val displayRoutes: List<DriverRouteDto> val displayRoutes: List<DriverRouteDto>
get() = projectDriverRoutes(routes, projectionActions) get() = projectDriverRoutes(routes, projectionActions)
.sortedBy { route -> if (route.status == "ZAKOŃCZONA") 1 else 0 }
val selectedRouteProjection: ProjectedDriverRoute? val selectedRouteProjection: ProjectedDriverRoute?
get() = selectedRoute?.let { projectDriverRoute(it, projectionActions) } get() = selectedRoute?.let { projectDriverRoute(it, projectionActions) }
@@ -634,7 +635,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
} }
fun uploadPhoto(uri: Uri, source: String, metadata: PhotoUploadMetadata = PhotoUploadMetadata(), stage: String = "other") { fun uploadPhoto(uri: Uri, source: String, metadata: PhotoUploadMetadata = PhotoUploadMetadata(), stage: String = "other") {
val route = _state.value.selectedRoute ?: return val snapshot = _state.value
val route = snapshot.selectedRoute ?: return
if (!routeIsActiveToday(route, snapshot.selectedDate)) {
_state.update { it.copy(error = "Zdjęcia możesz dodać tylko w zaplanowanym zakresie kursu.") }
return
}
viewModelScope.launch { viewModelScope.launch {
_state.update { it.copy(error = null) } _state.update { it.copy(error = null) }
runCatching { photoUploadOutbox.enqueue(route.id, uri, source, metadata, stage) } runCatching { photoUploadOutbox.enqueue(route.id, uri, source, metadata, stage) }
@@ -645,7 +651,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
} }
fun openStartRoute() { fun openStartRoute() {
val route = _state.value.selectedRoute ?: return val snapshot = _state.value
val route = snapshot.selectedRoute ?: return
if (!canStartRouteFromDriverApp(route, snapshot.selectedDate)) {
_state.update { it.copy(error = "Załadunek nie jest dostępny poza zaplanowanym zakresem kursu.") }
return
}
_state.update { _state.update {
it.copy( it.copy(
screen = DriverScreen.StartRoute, screen = DriverScreen.StartRoute,
@@ -681,7 +692,12 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
} }
fun openFinishRoute() { fun openFinishRoute() {
val route = _state.value.selectedRoute ?: return val snapshot = _state.value
val route = snapshot.selectedRoute ?: return
if (!canFinishRouteFromDriverApp(route, snapshot.selectedDate)) {
_state.update { it.copy(error = "Rozładunek jest dostępny w dniu zaplanowanego rozładunku.") }
return
}
_state.update { _state.update {
it.copy( it.copy(
screen = DriverScreen.FinishRoute, screen = DriverScreen.FinishRoute,
@@ -708,6 +724,21 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
private fun submitRouteStage(stage: String) { private fun submitRouteStage(stage: String) {
val snapshot = _state.value val snapshot = _state.value
val route = snapshot.selectedRoute ?: return val route = snapshot.selectedRoute ?: return
val canSubmitStage = if (stage == "loading") {
canStartRouteFromDriverApp(route, snapshot.selectedDate)
} else {
canFinishRouteFromDriverApp(route, snapshot.selectedDate)
}
if (!canSubmitStage) {
_state.update {
it.copy(error = if (stage == "loading") {
"Załadunek nie jest dostępny poza zaplanowanym zakresem kursu."
} else {
"Rozładunek jest dostępny w dniu zaplanowanego rozładunku."
})
}
return
}
val driver = snapshot.driver val driver = snapshot.driver
val weight = snapshot.routeStageWeightText.trim().replace(',', '.').toDoubleOrNull() val weight = snapshot.routeStageWeightText.trim().replace(',', '.').toDoubleOrNull()
val stagePhotos = routePhotosForStage(route.photos, stage) val stagePhotos = routePhotosForStage(route.photos, stage)
@@ -880,8 +911,13 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
} }
fun completeSelectedRoute() { fun completeSelectedRoute() {
val route = _state.value.selectedRoute ?: return val snapshot = _state.value
if (_state.value.completingRoute || !_state.value.isOnline) return val route = snapshot.selectedRoute ?: return
if (snapshot.completingRoute || !snapshot.isOnline) return
if (!canCompleteRouteFromDriverApp(route, snapshot.selectedDate)) {
_state.update { it.copy(error = "Zakończenie kursu jest dostępne w dniu zaplanowanego rozładunku.") }
return
}
viewModelScope.launch { viewModelScope.launch {
_state.update { it.copy(completingRoute = true, feedback = null, error = null) } _state.update { it.copy(completingRoute = true, feedback = null, error = null) }
@@ -154,6 +154,7 @@ class DriverRouteProjectionTest {
): DriverRouteDto = ): DriverRouteDto =
DriverRouteDto( DriverRouteDto(
id = "1", id = "1",
routeDate = "2026-06-30",
startsAt = "", startsAt = "",
originName = "Baza", originName = "Baza",
destinationName = "Instalacja", destinationName = "Instalacja",
@@ -39,6 +39,32 @@ class DriverUiRulesTest {
assertFalse(canCompleteRouteFromDriverApp(route(status = "ZAPLANOWANA"), "2026-06-29", today)) assertFalse(canCompleteRouteFromDriverApp(route(status = "ZAPLANOWANA"), "2026-06-29", today))
} }
@Test
fun multiDayRouteCanLoadTodayButCanUnloadOnlyOnItsUnloadingDate() {
val route = route(
status = "ZAPLANOWANA",
routeDate = "2026-06-29",
unloadingDate = "2026-06-30",
)
assertTrue(canStartRouteFromDriverApp(route, "2026-06-30", today))
assertEquals("Załaduj", routeLifecyclePrimaryAction(route, "2026-06-30", today)?.label)
assertEquals("Dziś: rozładunek. Załadunek możesz potwierdzić dzisiaj.", routeTodayInstruction(route, "2026-06-30", today))
val activeRoute = route.copy(status = "W TRAKCIE")
assertTrue(canFinishRouteFromDriverApp(activeRoute, "2026-06-30", today))
assertEquals("Rozładuj", routeLifecyclePrimaryAction(activeRoute, "2026-06-30", today)?.label)
assertFalse(canFinishRouteFromDriverApp(activeRoute, "2026-06-29", LocalDate.parse("2026-06-29")))
}
@Test
fun routeScheduleShowsBothDispatcherDates() {
val route = route(routeDate = "2026-06-30", unloadingDate = "2026-07-02")
assertEquals("Załadunek: 30.06 · Rozładunek: 02.07", routeScheduleSummary(route))
assertEquals("Załadunek: 30.06 · Rozładunek: ten sam dzień", routeScheduleSummary(route.copy(unloadingDate = null)))
}
@Test @Test
fun showsLiveRouteDayUpdateOnlyForViewedDate() { fun showsLiveRouteDayUpdateOnlyForViewedDate() {
assertTrue(shouldShowRouteDayLiveUpdate(viewedDate = "2026-03-12", hintDate = "2026-03-12")) assertTrue(shouldShowRouteDayLiveUpdate(viewedDate = "2026-03-12", hintDate = "2026-03-12"))
@@ -300,7 +326,7 @@ class DriverUiRulesTest {
assertEquals(RouteFlowStepState.Todo, steps[1].state) assertEquals(RouteFlowStepState.Todo, steps[1].state)
assertEquals(RouteFlowStepState.Todo, steps[2].state) assertEquals(RouteFlowStepState.Todo, steps[2].state)
assertEquals(RouteFlowStepState.Todo, steps[3].state) assertEquals(RouteFlowStepState.Todo, steps[3].state)
assertEquals("Rozpocznij kurs", action?.label) assertEquals("Załaduj", action?.label)
assertEquals(RouteLifecycleAction.Start, action?.action) assertEquals(RouteLifecycleAction.Start, action?.action)
} }
@@ -327,7 +353,7 @@ class DriverUiRulesTest {
assertEquals(RouteFlowStepState.Confirmed, steps[1].state) assertEquals(RouteFlowStepState.Confirmed, steps[1].state)
assertEquals(RouteFlowStepState.LocalComplete, steps[2].state) assertEquals(RouteFlowStepState.LocalComplete, steps[2].state)
assertEquals(RouteFlowStepState.Todo, steps[3].state) assertEquals(RouteFlowStepState.Todo, steps[3].state)
assertEquals("Zakończ kurs", action?.label) assertEquals("Rozładuj", action?.label)
assertEquals(RouteLifecycleAction.Finish, action?.action) assertEquals(RouteLifecycleAction.Finish, action?.action)
} }
@@ -400,13 +426,17 @@ class DriverUiRulesTest {
} }
private fun route( private fun route(
status: String, status: String = "ZAPLANOWANA",
loadingWeight: Double? = null, loadingWeight: Double? = null,
unloadingWeight: Double? = null, unloadingWeight: Double? = null,
photos: List<RoutePhotoDto> = emptyList(), photos: List<RoutePhotoDto> = emptyList(),
routeDate: String? = "2026-06-30",
unloadingDate: String? = null,
): DriverRouteDto = ): DriverRouteDto =
DriverRouteDto( DriverRouteDto(
id = "1", id = "1",
routeDate = routeDate,
unloadingDate = unloadingDate,
startsAt = "", startsAt = "",
originName = "Baza", originName = "Baza",
destinationName = "Instalacja", destinationName = "Instalacja",
@@ -70,6 +70,19 @@ class DriverUiStateTest {
assertEquals(12.5, state.displaySelectedRoute?.loadingWeight) assertEquals(12.5, state.displaySelectedRoute?.loadingWeight)
} }
@Test
fun displayRoutesMovesCompletedRoutesBelowActiveDispatcherOrder() {
val state = DriverUiState(
routes = listOf(
route(id = "completed", status = "ZAKOŃCZONA"),
route(id = "planned", status = "ZAPLANOWANA"),
route(id = "active", status = "W TRAKCIE"),
),
)
assertEquals(listOf("planned", "active", "completed"), state.displayRoutes.map { it.id })
}
private fun leaveRequest(id: String, status: String): DriverLeaveRequestDto = private fun leaveRequest(id: String, status: String): DriverLeaveRequestDto =
DriverLeaveRequestDto( DriverLeaveRequestDto(
id = id, id = id,
@@ -79,9 +92,10 @@ class DriverUiStateTest {
status = status, status = status,
) )
private fun route(status: String): DriverRouteDto = private fun route(id: String = "1", status: String): DriverRouteDto =
DriverRouteDto( DriverRouteDto(
id = "1", id = id,
routeDate = "2026-06-30",
startsAt = "", startsAt = "",
originName = "Baza", originName = "Baza",
destinationName = "Instalacja", destinationName = "Instalacja",