package com.peachpasswords.ui.lock import com.peachpasswords.ui.PeachNav import com.peachpasswords.vault.VaultEntry import org.junit.Assert.assertEquals import org.junit.Test class PostUnlockNavTest { private fun login(id: String) = VaultEntry(id = id, title = id, type = "login", createdAt = 0, modifiedAt = 0) private fun note(id: String) = VaultEntry(id = id, title = id, type = "note", createdAt = 0, modifiedAt = 0) /** A still-present last-viewed id reopens that entry's detail. */ @Test fun unlock_navigates_to_last_viewed_entry() { val entries = mapOf("a" to login("a"), "b" to login("b")) val dest = postUnlockDestination( lastViewedId = "b", resolve = entries::get, firstActive = entries["a"], ) assertEquals(PeachNav.EntryDetail("b"), dest) } /** No history → land on the first active entry. */ @Test fun unlock_navigates_to_first_entry_when_no_history() { val first = login("a") val dest = postUnlockDestination( lastViewedId = null, resolve = { null }, firstActive = first, ) assertEquals(PeachNav.EntryDetail("a"), dest) } /** Empty vault → fall back to the list. */ @Test fun unlock_navigates_to_vault_list_when_empty() { val dest = postUnlockDestination( lastViewedId = null, resolve = { null }, firstActive = null, ) assertEquals(PeachNav.VaultList, dest) } /** A stale last-viewed id (entry since deleted) falls back to the first entry. */ @Test fun unlock_falls_back_when_last_viewed_deleted() { val first = login("a") val dest = postUnlockDestination( lastViewedId = "ghost", resolve = { null }, // "ghost" no longer resolves firstActive = first, ) assertEquals(PeachNav.EntryDetail("a"), dest) } /** A last-viewed NOTE reopens the notes editor, not the entry detail. */ @Test fun unlock_last_viewed_note_routes_to_notes_mode() { val entries = mapOf("n" to note("n")) val dest = postUnlockDestination( lastViewedId = "n", resolve = entries::get, firstActive = entries["n"], ) assertEquals(PeachNav.NotesMode("n"), dest) } }