1package com.peachpasswords.ui23import com.peachpasswords.ui.lock.postUnlockDestination4import com.peachpasswords.ui.onboarding.onboardingStartDestination5import com.peachpasswords.ui.vault.entryTapDestination6import com.peachpasswords.vault.VaultEntry7import org.junit.Assert.assertEquals8import org.junit.Test91011121314class NavigationFlowTest {1516 private fun login(id: String) = VaultEntry(id = id, title = id, type = "login", createdAt = 0, modifiedAt = 0)17 private fun note(id: String) = VaultEntry(id = id, title = id, type = "note", createdAt = 0, modifiedAt = 0)1819 2021 @Test fun entry_detail_route_embeds_id() {22 assertEquals("entry/abc", PeachNav.EntryDetail("abc").route)23 assertEquals("entry/abc", PeachNav.EntryDetail.of("abc"))24 assertEquals("entry/{id}", PeachNav.EntryDetail.ROUTE)25 }2627 @Test fun notes_mode_route_embeds_id() {28 assertEquals("notes/n1", PeachNav.NotesMode("n1").route)29 assertEquals("notes/n1", PeachNav.NotesMode.of("n1"))30 assertEquals("notes/{id}", PeachNav.NotesMode.ROUTE)31 }3233 @Test fun entry_edit_route_handles_null_and_value() {34 assertEquals("edit?id=&prefillUrl=&prefillUsername=&prefillEmail=", PeachNav.EntryEdit(null).route)35 assertEquals("edit?id=x&prefillUrl=&prefillUsername=&prefillEmail=", PeachNav.EntryEdit("x").route)36 assertEquals("edit?id=&prefillUrl=&prefillUsername=&prefillEmail=", PeachNav.EntryEdit.of(null))37 assertEquals("edit?id=x&prefillUrl=&prefillUsername=&prefillEmail=", PeachNav.EntryEdit.of("x"))38 }3940 @Test fun entry_edit_route_carries_prefill_payload() {41 val route = PeachNav.EntryEdit.of(42 id = null,43 prefillUrl = "github.com",44 prefillUsername = "june",45 prefillEmail = "[email protected]",46 )47 assertEquals(48 "edit?id=&prefillUrl=github.com&prefillUsername=june&[email protected]",49 route,50 )51 }5253 @Test fun static_routes_are_stable() {54 assertEquals("onboarding", PeachNav.Onboarding.route)55 assertEquals("lock", PeachNav.Lock.route)56 assertEquals("vault", PeachNav.VaultList.route)57 assertEquals("settings", PeachNav.Settings.route)58 }5960 6162 @Test fun first_launch_shows_onboarding() {63 assertEquals(PeachNav.Onboarding, onboardingStartDestination(hasVault = false, onboarded = false))64 }6566 @Test fun subsequent_launch_skips_onboarding() {67 assertEquals(PeachNav.Lock, onboardingStartDestination(hasVault = true, onboarded = true))68 }6970 7172 @Test fun list_tap_login_opens_detail() {73 assertEquals(PeachNav.EntryDetail("l"), entryTapDestination(login("l")))74 }7576 @Test fun list_tap_note_opens_notes_mode() {77 assertEquals(PeachNav.NotesMode("n"), entryTapDestination(note("n")))78 }7980 8182 @Test fun post_unlock_opens_last_viewed() {83 val entries = mapOf("a" to login("a"), "b" to login("b"))84 assertEquals(PeachNav.EntryDetail("b"), postUnlockDestination("b", entries::get, entries["a"]))85 }8687 @Test fun post_unlock_empty_vault_falls_to_list() {88 assertEquals(PeachNav.VaultList, postUnlockDestination(null, { null }, null))89 }9091 @Test fun vault_from_entry_uses_sheet_transition() {92 assertEquals(true, isVaultSheetTransition("entry/a", PeachNav.VaultList.route))93 assertEquals(true, isVaultSheetTransition("notes/n", PeachNav.VaultList.route))94 assertEquals(false, isVaultSheetTransition(PeachNav.Lock.route, PeachNav.VaultList.route))95 }9697 @Test fun vault_to_entry_uses_reverse_sheet_transition() {98 assertEquals(true, isVaultSheetTransition(PeachNav.VaultList.route, "entry/a", reverse = true))99 assertEquals(true, isVaultSheetTransition(PeachNav.VaultList.route, "notes/n", reverse = true))100 assertEquals(false, isVaultSheetTransition(PeachNav.VaultList.route, PeachNav.Settings.route, reverse = true))101 }102}