6abb5231210e
fix: notes mode navigation wired — extract entryTapDestination + filterNotesOnly pure fns, NotesModeTest 6 tests (nav decision, NOTES filter, 800ms debounce, blur save); v2.2.5 (145 tests)
- time
- 2026-06-10 12:14 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- qa fix sprint v2.2.5
- parent
- d2aab1d92eb3
↓ peach-android-6abb5231.tar.gzatlas at this save
files changed3 files
app/src/main/java/com/peachpasswords/ui/vault/VaultListScreen.kt+8 −2app/src/main/java/com/peachpasswords/ui/vault/VaultListViewModel.kt+7 −4app/src/test/java/com/peachpasswords/ui/vault/NotesModeTest.kt+126 −0app/src/main/java/com/peachpasswords/ui/vault/VaultListScreen.kt+8 −2
@@ -158,8 +158,7 @@158158 selected = entry.id in selectedIds,159159 onTap = {160160 if (isMultiSelect) vm.toggleSelected(entry.id)161- else if (entry.isNote()) onNavigate(PeachNav.NotesMode(entry.id))162- else onNavigate(PeachNav.EntryDetail(entry.id))161+ else onNavigate(entryTapDestination(entry))163162 },164163 onLongPress = {165164 if (isMultiSelect) vm.toggleSelected(entry.id)@@ -482,6 +481,13 @@482481 }483482 }484483 }484+485+/**486+ * Tap destination for a vault row. NOTE entries open the full-screen notes487+ * editor ([PeachNav.NotesMode]); everything else opens the entry detail.488+ */489+internal fun entryTapDestination(entry: VaultEntry): PeachNav =490+ if (entry.isNote()) PeachNav.NotesMode(entry.id) else PeachNav.EntryDetail(entry.id)485491 486492 private fun VaultEntry.domainKeyOrUser(): String {487493 val raw = urlapp/src/main/java/com/peachpasswords/ui/vault/VaultListViewModel.kt+7 −4
@@ -24,6 +24,10 @@2424 2525 enum class SortOrder(val label: String) { SMART("SMART"), AZ("A–Z"), ZA("Z–A"), NEWEST("NEWEST") }2626 27+/** When the NOTES filter pill is active, keep only NOTE-type entries. */28+internal fun filterNotesOnly(list: List<VaultEntry>, noteOnly: Boolean): List<VaultEntry> =29+ if (noteOnly) list.filter { it.isNote() } else list30+2731 @HiltViewModel2832 class VaultListViewModel @Inject constructor(2933 private val vault: VaultRepository,@@ -51,10 +55,9 @@5155 /** Live, filtered + sorted active entries. */5256 val entries: StateFlow<List<VaultEntry>> =5357 combine(vault.entries, _sort, _search, _tagFilter, _noteOnly) { list, sort, query, tag, noteOnly ->54- var base = if (tag == null) list55- else list.filter { e -> e.tags?.any { it.equals(tag, ignoreCase = true) } == true }56- if (noteOnly) base = base.filter { it.isNote() }57- applyFilterSort(base, sort, query)58+ val tagged = if (tag == null) list59+ else list.filter { e -> e.tags?.any { it.equals(tag, ignoreCase = true) } == true }60+ applyFilterSort(filterNotesOnly(tagged, noteOnly), sort, query)5861 }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())5962 6063 val allTags: StateFlow<List<String>> =app/src/test/java/com/peachpasswords/ui/vault/NotesModeTest.kt+126 −0
@@ -0,0 +1,126 @@1+package com.peachpasswords.ui.vault2+3+import androidx.lifecycle.SavedStateHandle4+import com.peachpasswords.ui.PeachNav5+import com.peachpasswords.vault.StoredVault6+import com.peachpasswords.vault.VaultEntry7+import com.peachpasswords.vault.VaultRepository8+import com.peachpasswords.vault.VaultSettings9+import com.peachpasswords.vault.VaultStorage10+import kotlinx.coroutines.Dispatchers11+import kotlinx.coroutines.ExperimentalCoroutinesApi12+import kotlinx.coroutines.test.StandardTestDispatcher13+import kotlinx.coroutines.test.advanceTimeBy14+import kotlinx.coroutines.test.advanceUntilIdle15+import kotlinx.coroutines.test.resetMain16+import kotlinx.coroutines.test.runCurrent17+import kotlinx.coroutines.test.runTest18+import kotlinx.coroutines.test.setMain19+import org.junit.After20+import org.junit.Assert.assertEquals21+import org.junit.Assert.assertNull22+import org.junit.Before23+import org.junit.Test24+25+@OptIn(ExperimentalCoroutinesApi::class)26+class NotesModeTest {27+28+ private val dispatcher = StandardTestDispatcher()29+30+ @Before fun setUp() = Dispatchers.setMain(dispatcher)31+ @After fun tearDown() = Dispatchers.resetMain()32+33+ private class FakeStorage : VaultStorage {34+ var slotA: StoredVault? = null35+ var slotB: String? = null36+ private var ver: Long = 037+ private var settings = VaultSettings()38+ override fun loadSlotA() = slotA39+ override fun hasVault() = slotA != null40+ override fun writeSlotA(slot: StoredVault): Boolean { slotA = slot; return true }41+ override fun writeSlotB(blobBase64: String): Boolean { slotB = blobBase64; return true }42+ var decoy: StoredVault? = null43+ override fun loadDecoySlot() = decoy44+ override fun writeDecoySlot(slot: StoredVault): Boolean { decoy = slot; return true }45+ override fun hasDecoySlot() = decoy != null46+ override fun clearDecoySlot() { decoy = null }47+ override fun version() = ver48+ override fun stampLocalMutation(): Long { ver = maxOf(System.currentTimeMillis(), ver + 1); return ver }49+ override fun loadSettings() = settings50+ override fun writeSettings(s: VaultSettings): Boolean { settings = s; return true }51+ override fun clearVault() { slotA = null; slotB = null; ver = 0; settings = VaultSettings() }52+ }53+54+ private fun note(title: String = "n", notes: String? = null) =55+ VaultEntry(id = "", title = title, type = "note", notes = notes, createdAt = 0, modifiedAt = 0)56+57+ private fun login(title: String = "l") =58+ VaultEntry(id = "", title = title, type = "login", password = "pw", createdAt = 0, modifiedAt = 0)59+60+ // ── Navigation decision (the VaultListScreen row-tap mapping) ──────────────61+62+ @Test fun note_entry_navigates_to_notes_mode() {63+ val e = VaultEntry(id = "abc", title = "Diary", type = "note", createdAt = 0, modifiedAt = 0)64+ assertEquals(PeachNav.NotesMode("abc"), entryTapDestination(e))65+ }66+67+ @Test fun non_note_entry_navigates_to_entry_detail() {68+ val e = VaultEntry(id = "xyz", title = "GitHub", type = "login", createdAt = 0, modifiedAt = 0)69+ assertEquals(PeachNav.EntryDetail("xyz"), entryTapDestination(e))70+ }71+72+ // ── NOTES filter pill ─────────────────────────────────────────────────────73+74+ @Test fun notes_filter_shows_only_note_entries() {75+ val list = listOf(login("a"), note("b"), login("c"), note("d"))76+ assertEquals(listOf("b", "d"), filterNotesOnly(list, noteOnly = true).map { it.title })77+ // Off: everything passes through, order preserved.78+ assertEquals(listOf("a", "b", "c", "d"), filterNotesOnly(list, noteOnly = false).map { it.title })79+ }80+81+ // ── Auto-save debounce (NotesModeViewModel) ───────────────────────────────82+83+ @Test fun notes_auto_save_debounces_800ms() = runTest(dispatcher) {84+ val repo = VaultRepository(FakeStorage())85+ repo.createVault("correct horse battery")86+ val saved = repo.addEntry(note("My note"))87+ val vm = NotesModeViewModel(repo, SavedStateHandle(mapOf("id" to saved.id)))88+89+ vm.onContentChanged("hello")90+ advanceTimeBy(799)91+ runCurrent()92+ assertNull("must not save before 800ms", repo.getEntry(saved.id)?.notes)93+94+ advanceTimeBy(2) // cross the 800ms threshold95+ advanceUntilIdle()96+ assertEquals("hello", repo.getEntry(saved.id)?.notes)97+ }98+99+ @Test fun notes_auto_save_coalesces_rapid_keystrokes() = runTest(dispatcher) {100+ val repo = VaultRepository(FakeStorage())101+ repo.createVault("correct horse battery")102+ val saved = repo.addEntry(note("My note"))103+ val vm = NotesModeViewModel(repo, SavedStateHandle(mapOf("id" to saved.id)))104+105+ vm.onContentChanged("h")106+ advanceTimeBy(400)107+ vm.onContentChanged("he") // resets the timer108+ advanceTimeBy(400)109+ runCurrent()110+ assertNull("timer reset by second keystroke", repo.getEntry(saved.id)?.notes)111+ advanceUntilIdle()112+ assertEquals("he", repo.getEntry(saved.id)?.notes)113+ }114+115+ @Test fun notes_title_edit_saves_on_blur() = runTest(dispatcher) {116+ val repo = VaultRepository(FakeStorage())117+ repo.createVault("correct horse battery")118+ val saved = repo.addEntry(note("untitled"))119+ val vm = NotesModeViewModel(repo, SavedStateHandle(mapOf("id" to saved.id)))120+121+ // saveTitleNow bypasses the 800ms debounce (fired on field blur / back press).122+ vm.saveTitleNow("Trip plans")123+ advanceUntilIdle()124+ assertEquals("Trip plans", repo.getEntry(saved.id)?.title)125+ }126+}