EntryEditScreenTest.kt

5.0 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    @Test fun primary_action_label_matches_browser_add_view() {24        assertEquals("create", entryEditPrimaryActionLabel(isNew = true, saving = false))25        assertEquals("save", entryEditPrimaryActionLabel(isNew = false, saving = false))26        assertEquals("saving...", entryEditPrimaryActionLabel(isNew = true, saving = true))27    }2829    @Test fun save_is_disabled_until_browser_minimum_fields_are_present() {30        assertFalse(canSaveEditForm(EditForm(type = "login", title = "")))31        assertTrue(canSaveEditForm(EditForm(type = "login", title = "GitHub")))32        assertFalse(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "", cardNumber = "4242")))33        assertFalse(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "June", cardNumber = "")))34        assertTrue(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "June", cardNumber = "4242")))35    }3637    // ── New note routes to NotesMode, not the form ────────────────────────────3839    @Test fun new_note_routes_to_notes_mode() {40        assertTrue(shouldOpenNotesMode(isNew = true, type = "note"))41        // Existing note stays in the form; new login/card stay in the form.42        assertFalse(shouldOpenNotesMode(isNew = false, type = "note"))43        assertFalse(shouldOpenNotesMode(isNew = true, type = "login"))44        assertFalse(shouldOpenNotesMode(isNew = true, type = "card"))45    }4647    // ── Ghost watermark fades in as the title is typed ────────────────────────4849    @Test fun new_entry_ghost_watermark_appears_on_title_type() {50        assertEquals(0f, editGhostWatermarkTarget(""), 0f)51        assertEquals(0f, editGhostWatermarkTarget("   "), 0f)52        assertEquals(0.03f, editGhostWatermarkTarget("GitHub"), 0f)53    }5455    // ── Browser AddView optional login fields ────────────────────────────────5657    @Test fun new_login_hides_optional_totp_and_notes_until_requested() {58        assertFalse(shouldShowLoginTotp("login", revealed = false, totp = ""))59        assertFalse(shouldShowLoginNotes("login", revealed = false, notes = ""))60        assertTrue(shouldShowAddTotpLink("login", revealed = false, totp = ""))61        assertTrue(shouldShowAddNotesLink("login", revealed = false, notes = ""))62    }6364    @Test fun optional_login_fields_show_when_revealed_or_populated() {65        assertTrue(shouldShowLoginTotp("login", revealed = true, totp = ""))66        assertTrue(shouldShowLoginTotp("login", revealed = false, totp = "JBSWY3DPEHPK3PXP"))67        assertTrue(shouldShowLoginNotes("login", revealed = true, notes = ""))68        assertTrue(shouldShowLoginNotes("login", revealed = false, notes = "remember this"))69        assertFalse(shouldShowAddTotpLink("login", revealed = true, totp = ""))70        assertFalse(shouldShowAddNotesLink("login", revealed = false, notes = "remember this"))71    }7273    // ── Card field formatting (CardFieldUtils, used live by setCardNumber etc.) ─7475    @Test fun new_card_number_auto_formats() {76        assertEquals("4242 4242 4242 4242", CardFieldUtils.formatPan("4242424242424242"))77        // Amex groups 4-6-5.78        assertEquals("3782 822463 10005", CardFieldUtils.formatPan("378282246310005"))79    }8081    @Test fun new_card_expiry_auto_formats_mm_yy() {82        assertEquals("12", CardFieldUtils.formatExpiry("12"))83        assertEquals("12/28", CardFieldUtils.formatExpiry("1228"))84        assertEquals("12/28", CardFieldUtils.formatExpiry("122899")) // caps at 4 digits85    }8687    @Test fun new_card_expiry_rejects_invalid_month() {88        // currentYear2 = 26, currentMonth = 6 (2026-06).89        assertFalse(CardFieldUtils.isExpiryValid("13/28", currentYear2 = 26, currentMonth = 6))90        assertFalse(CardFieldUtils.isExpiryValid("00/28", currentYear2 = 26, currentMonth = 6))91        assertTrue(CardFieldUtils.isExpiryValid("12/28", currentYear2 = 26, currentMonth = 6))92        // Past year rejected.93        assertFalse(CardFieldUtils.isExpiryValid("12/24", currentYear2 = 26, currentMonth = 6))94    }95}