08f44d2c8d98
test: EntryDetailScreen pure logic — EntryDetailScreenTest 14 tests (full-title watermark, NOTE routing, breach predicate, TOTP six-digit/rollover/hot-state<5s/progress, masked PAN visa+amex, display expiry); v2.2.6 (325 tests)
- time
- 2026-06-10 13:02 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- test coverage entrydetail
- parent
- db8da89fdf31
↓ peach-android-08f44d2c.tar.gzatlas at this save
files changed1 file
app/src/test/java/com/peachpasswords/ui/vault/EntryDetailScreenTest.kt+95 −0app/src/test/java/com/peachpasswords/ui/vault/EntryDetailScreenTest.kt+95 −0
@@ -0,0 +1,95 @@1+package com.peachpasswords.ui.vault2+3+import com.peachpasswords.ui.PeachNav4+import com.peachpasswords.vault.TOTPGenerator5+import com.peachpasswords.vault.VaultEntry6+import com.peachpasswords.vault.isBreach7+import org.junit.Assert.assertEquals8+import org.junit.Assert.assertFalse9+import org.junit.Assert.assertTrue10+import org.junit.Test11+12+/**13+ * EntryDetail suite (brief Suite 4): the screen's pure rendering logic — full-title14+ * ghost watermark, NOTE routing, breach-banner predicate, TOTP timing/hot-state,15+ * and masked card display. The biometric-reveal and FLAG_SECURE paths need an16+ * instrumented device.17+ */18+class EntryDetailScreenTest {19+20+ // ── Ghost watermark + routing ─────────────────────────────────────────────21+22+ @Test fun ghost_watermark_uses_full_title() {23+ assertEquals("My Bank", ghostWatermarkText("My Bank"))24+ }25+26+ @Test fun note_entry_routes_to_notes_mode() {27+ val note = VaultEntry(id = "n1", title = "Diary", type = "note", createdAt = 0, modifiedAt = 0)28+ assertEquals(PeachNav.NotesMode("n1"), entryTapDestination(note))29+ }30+31+ @Test fun login_entry_routes_to_entry_detail() {32+ val login = VaultEntry(id = "l1", title = "GitHub", type = "login", createdAt = 0, modifiedAt = 0)33+ assertEquals(PeachNav.EntryDetail("l1"), entryTapDestination(login))34+ }35+36+ // ── Breach banner ─────────────────────────────────────────────────────────37+38+ @Test fun breach_banner_shown_when_breach_positive() {39+ assertTrue(VaultEntry(id = "a", title = "x", breach = 2, createdAt = 0, modifiedAt = 0).isBreach())40+ }41+42+ @Test fun breach_banner_hidden_when_zero_or_null() {43+ assertFalse(VaultEntry(id = "a", title = "x", breach = 0, createdAt = 0, modifiedAt = 0).isBreach())44+ assertFalse(VaultEntry(id = "a", title = "x", breach = null, createdAt = 0, modifiedAt = 0).isBreach())45+ }46+47+ // ── TOTP display + hot state ──────────────────────────────────────────────48+49+ private val secret = "JBSWY3DPEHPK3PXP"50+51+ /** The screen pulses the TOTP ring in its final 5 seconds. */52+ private fun isHot(nowMillis: Long) = TOTPGenerator.remainingSeconds(nowMillis) <= 553+54+ @Test fun totp_code_is_six_digits() {55+ val code = TOTPGenerator.generateCode(secret, nowMillis = 0L)!!56+ assertEquals(6, code.length)57+ assertTrue(code.all { it.isDigit() })58+ }59+60+ @Test fun totp_code_updates_across_periods() {61+ val a = TOTPGenerator.generateCode(secret, nowMillis = 0L)62+ val b = TOTPGenerator.generateCode(secret, nowMillis = 30_000L) // next 30s window63+ assertFalse("code rolls over at the period boundary", a == b)64+ }65+66+ @Test fun totp_hot_state_only_in_final_five_seconds() {67+ assertFalse(isHot(10_000L)) // 20s remaining68+ assertTrue(isHot(27_000L)) // 3s remaining69+ assertTrue(isHot(29_000L)) // 1s remaining70+ }71+72+ @Test fun totp_remaining_and_progress_are_consistent() {73+ val now = 27_000L74+ assertEquals(3, TOTPGenerator.remainingSeconds(now))75+ assertEquals(27f / 30f, TOTPGenerator.periodProgress(now), 0.0001f)76+ }77+78+ // ── Masked card display ───────────────────────────────────────────────────79+80+ @Test fun masked_pan_shows_only_last_four_visa() {81+ assertEquals("•••• •••• •••• 4242", CardFieldUtils.maskedPan("4242424242424242"))82+ }83+84+ @Test fun masked_pan_groups_amex_4_6_5() {85+ assertEquals("•••• •••••• •0005", CardFieldUtils.maskedPan("378282246310005"))86+ }87+88+ @Test fun masked_pan_empty_for_no_number() {89+ assertEquals("", CardFieldUtils.maskedPan(null))90+ }91+92+ @Test fun display_expiry_combines_month_and_year() {93+ assertEquals("04/30", CardFieldUtils.displayExpiry("04", "2030"))94+ }95+}