PostUnlockNavTest.kt

2.3 KB · raw

1package com.peachpasswords.ui.lock23import com.peachpasswords.ui.PeachNav4import com.peachpasswords.vault.VaultEntry5import org.junit.Assert.assertEquals6import org.junit.Test78class PostUnlockNavTest {910    private fun login(id: String) =11        VaultEntry(id = id, title = id, type = "login", createdAt = 0, modifiedAt = 0)1213    private fun note(id: String) =14        VaultEntry(id = id, title = id, type = "note", createdAt = 0, modifiedAt = 0)1516    /** A still-present last-viewed id reopens that entry's detail. */17    @Test fun unlock_navigates_to_last_viewed_entry() {18        val entries = mapOf("a" to login("a"), "b" to login("b"))19        val dest = postUnlockDestination(20            lastViewedId = "b",21            resolve = entries::get,22            firstActive = entries["a"],23        )24        assertEquals(PeachNav.EntryDetail("b"), dest)25    }2627    /** No history → land on the first active entry. */28    @Test fun unlock_navigates_to_first_entry_when_no_history() {29        val first = login("a")30        val dest = postUnlockDestination(31            lastViewedId = null,32            resolve = { null },33            firstActive = first,34        )35        assertEquals(PeachNav.EntryDetail("a"), dest)36    }3738    /** Empty vault → fall back to the list. */39    @Test fun unlock_navigates_to_vault_list_when_empty() {40        val dest = postUnlockDestination(41            lastViewedId = null,42            resolve = { null },43            firstActive = null,44        )45        assertEquals(PeachNav.VaultList, dest)46    }4748    /** A stale last-viewed id (entry since deleted) falls back to the first entry. */49    @Test fun unlock_falls_back_when_last_viewed_deleted() {50        val first = login("a")51        val dest = postUnlockDestination(52            lastViewedId = "ghost",53            resolve = { null }, // "ghost" no longer resolves54            firstActive = first,55        )56        assertEquals(PeachNav.EntryDetail("a"), dest)57    }5859    /** A last-viewed NOTE reopens the notes editor, not the entry detail. */60    @Test fun unlock_last_viewed_note_routes_to_notes_mode() {61        val entries = mapOf("n" to note("n"))62        val dest = postUnlockDestination(63            lastViewedId = "n",64            resolve = entries::get,65            firstActive = entries["n"],66        )67        assertEquals(PeachNav.NotesMode("n"), dest)68    }69}