EntryEditScreenTest.kt

4.1 KB · raw

1package com.peachpasswords.ui.vault23import org.junit.Assert.assertEquals4import org.junit.Assert.assertFalse5import org.junit.Assert.assertTrue6import org.junit.Test78class EntryEditScreenTest {910    // ── Top-bar label (cancel | <title> | save) ───────────────────────────────1112    @Test fun title_bar_label_is_type_specific_for_new_entries() {13        assertEquals("new entry", editTitleBarLabel(isNew = true, type = "login"))14        assertEquals("new note", editTitleBarLabel(isNew = true, type = "note"))15        assertEquals("new card", editTitleBarLabel(isNew = true, type = "card"))16    }1718    @Test fun title_bar_label_is_edit_for_existing_entries() {19        assertEquals("edit", editTitleBarLabel(isNew = false, type = "login"))20        assertEquals("edit", editTitleBarLabel(isNew = false, type = "note"))21    }2223    // ── New note routes to NotesMode, not the form ────────────────────────────2425    @Test fun new_note_routes_to_notes_mode() {26        assertTrue(shouldOpenNotesMode(isNew = true, type = "note"))27        // Existing note stays in the form; new login/card stay in the form.28        assertFalse(shouldOpenNotesMode(isNew = false, type = "note"))29        assertFalse(shouldOpenNotesMode(isNew = true, type = "login"))30        assertFalse(shouldOpenNotesMode(isNew = true, type = "card"))31    }3233    // ── Ghost watermark fades in as the title is typed ────────────────────────3435    @Test fun new_entry_ghost_watermark_appears_on_title_type() {36        assertEquals(0f, editGhostWatermarkTarget(""), 0f)37        assertEquals(0f, editGhostWatermarkTarget("   "), 0f)38        assertEquals(0.03f, editGhostWatermarkTarget("GitHub"), 0f)39    }4041    // ── Browser AddView optional login fields ────────────────────────────────4243    @Test fun new_login_hides_optional_totp_and_notes_until_requested() {44        assertFalse(shouldShowLoginTotp("login", revealed = false, totp = ""))45        assertFalse(shouldShowLoginNotes("login", revealed = false, notes = ""))46        assertTrue(shouldShowAddTotpLink("login", revealed = false, totp = ""))47        assertTrue(shouldShowAddNotesLink("login", revealed = false, notes = ""))48    }4950    @Test fun optional_login_fields_show_when_revealed_or_populated() {51        assertTrue(shouldShowLoginTotp("login", revealed = true, totp = ""))52        assertTrue(shouldShowLoginTotp("login", revealed = false, totp = "JBSWY3DPEHPK3PXP"))53        assertTrue(shouldShowLoginNotes("login", revealed = true, notes = ""))54        assertTrue(shouldShowLoginNotes("login", revealed = false, notes = "remember this"))55        assertFalse(shouldShowAddTotpLink("login", revealed = true, totp = ""))56        assertFalse(shouldShowAddNotesLink("login", revealed = false, notes = "remember this"))57    }5859    // ── Card field formatting (CardFieldUtils, used live by setCardNumber etc.) ─6061    @Test fun new_card_number_auto_formats() {62        assertEquals("4242 4242 4242 4242", CardFieldUtils.formatPan("4242424242424242"))63        // Amex groups 4-6-5.64        assertEquals("3782 822463 10005", CardFieldUtils.formatPan("378282246310005"))65    }6667    @Test fun new_card_expiry_auto_formats_mm_yy() {68        assertEquals("12", CardFieldUtils.formatExpiry("12"))69        assertEquals("12/28", CardFieldUtils.formatExpiry("1228"))70        assertEquals("12/28", CardFieldUtils.formatExpiry("122899")) // caps at 4 digits71    }7273    @Test fun new_card_expiry_rejects_invalid_month() {74        // currentYear2 = 26, currentMonth = 6 (2026-06).75        assertFalse(CardFieldUtils.isExpiryValid("13/28", currentYear2 = 26, currentMonth = 6))76        assertFalse(CardFieldUtils.isExpiryValid("00/28", currentYear2 = 26, currentMonth = 6))77        assertTrue(CardFieldUtils.isExpiryValid("12/28", currentYear2 = 26, currentMonth = 6))78        // Past year rejected.79        assertFalse(CardFieldUtils.isExpiryValid("12/24", currentYear2 = 26, currentMonth = 6))80    }81}