EntryEditScreenTest.kt

2.9 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    // ── Card field formatting (CardFieldUtils, used live by setCardNumber etc.) ─4243    @Test fun new_card_number_auto_formats() {44        assertEquals("4242 4242 4242 4242", CardFieldUtils.formatPan("4242424242424242"))45        // Amex groups 4-6-5.46        assertEquals("3782 822463 10005", CardFieldUtils.formatPan("378282246310005"))47    }4849    @Test fun new_card_expiry_auto_formats_mm_yy() {50        assertEquals("12", CardFieldUtils.formatExpiry("12"))51        assertEquals("12/28", CardFieldUtils.formatExpiry("1228"))52        assertEquals("12/28", CardFieldUtils.formatExpiry("122899")) // caps at 4 digits53    }5455    @Test fun new_card_expiry_rejects_invalid_month() {56        // currentYear2 = 26, currentMonth = 6 (2026-06).57        assertFalse(CardFieldUtils.isExpiryValid("13/28", currentYear2 = 26, currentMonth = 6))58        assertFalse(CardFieldUtils.isExpiryValid("00/28", currentYear2 = 26, currentMonth = 6))59        assertTrue(CardFieldUtils.isExpiryValid("12/28", currentYear2 = 26, currentMonth = 6))60        // Past year rejected.61        assertFalse(CardFieldUtils.isExpiryValid("12/24", currentYear2 = 26, currentMonth = 6))62    }63}