1package com.peachpasswords.ui.vault23import com.peachpasswords.vault.VaultEntry4import org.junit.Assert.assertEquals5import org.junit.Assert.assertFalse6import org.junit.Assert.assertTrue7import org.junit.Test89class EntryEditScreenTest {1011 1213 @Test fun title_bar_label_is_type_specific_for_new_entries() {14 assertEquals("new entry", editTitleBarLabel(isNew = true, type = "login"))15 assertEquals("new note", editTitleBarLabel(isNew = true, type = "note"))16 assertEquals("new card", editTitleBarLabel(isNew = true, type = "card"))17 }1819 @Test fun title_bar_label_is_edit_for_existing_entries() {20 assertEquals("edit", editTitleBarLabel(isNew = false, type = "login"))21 assertEquals("edit", editTitleBarLabel(isNew = false, type = "note"))22 }2324 @Test fun primary_action_label_matches_browser_add_view() {25 assertEquals("create", entryEditPrimaryActionLabel(isNew = true, saving = false))26 assertEquals("save", entryEditPrimaryActionLabel(isNew = false, saving = false))27 assertEquals("saving...", entryEditPrimaryActionLabel(isNew = true, saving = true))28 }2930 @Test fun save_is_disabled_until_browser_minimum_fields_are_present() {31 assertFalse(canSaveEditForm(EditForm(type = "login", title = "")))32 assertTrue(canSaveEditForm(EditForm(type = "login", title = "GitHub")))33 assertFalse(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "", cardNumber = "4242")))34 assertFalse(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "June", cardNumber = "")))35 assertTrue(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "June", cardNumber = "4242")))36 }3738 3940 @Test fun new_note_routes_to_notes_mode() {41 assertTrue(shouldOpenNotesMode(isNew = true, type = "note"))42 43 assertFalse(shouldOpenNotesMode(isNew = false, type = "note"))44 assertFalse(shouldOpenNotesMode(isNew = true, type = "login"))45 assertFalse(shouldOpenNotesMode(isNew = true, type = "card"))46 }4748 4950 @Test fun new_entry_ghost_watermark_appears_on_title_type() {51 assertEquals(0f, editGhostWatermarkTarget(""), 0f)52 assertEquals(0f, editGhostWatermarkTarget(" "), 0f)53 assertEquals(0.03f, editGhostWatermarkTarget("GitHub"), 0f)54 }5556 5758 @Test fun new_login_hides_optional_totp_and_notes_until_requested() {59 assertFalse(shouldShowLoginTotp("login", revealed = false, totp = ""))60 assertFalse(shouldShowLoginNotes("login", revealed = false, notes = ""))61 assertTrue(shouldShowAddTotpLink("login", revealed = false, totp = ""))62 assertTrue(shouldShowAddNotesLink("login", revealed = false, notes = ""))63 }6465 @Test fun optional_login_fields_show_when_revealed_or_populated() {66 assertTrue(shouldShowLoginTotp("login", revealed = true, totp = ""))67 assertTrue(shouldShowLoginTotp("login", revealed = false, totp = "JBSWY3DPEHPK3PXP"))68 assertTrue(shouldShowLoginNotes("login", revealed = true, notes = ""))69 assertTrue(shouldShowLoginNotes("login", revealed = false, notes = "remember this"))70 assertFalse(shouldShowAddTotpLink("login", revealed = true, totp = ""))71 assertFalse(shouldShowAddNotesLink("login", revealed = false, notes = "remember this"))72 }7374 @Test fun identity_suggestions_split_username_and_email_like_browser() {75 val entries = listOf(76 identityEntry("a", username = "june", email = "[email protected]"),77 identityEntry("b", username = "june", email = null),78 identityEntry("c", username = "[email protected]", email = "[email protected]"),79 identityEntry("d", username = "[email protected]", email = null),80 )8182 assertEquals(listOf("june"), identitySuggestionsFor(entries, IdentityField.Username))83 assertEquals(84 listOf("[email protected]", "[email protected]", "[email protected]"),85 identitySuggestionsFor(entries, IdentityField.Email),86 )87 }8889 9091 @Test fun new_card_number_auto_formats() {92 assertEquals("4242 4242 4242 4242", CardFieldUtils.formatPan("4242424242424242"))93 94 assertEquals("3782 822463 10005", CardFieldUtils.formatPan("378282246310005"))95 }9697 @Test fun new_card_expiry_auto_formats_mm_yy() {98 assertEquals("12", CardFieldUtils.formatExpiry("12"))99 assertEquals("12/28", CardFieldUtils.formatExpiry("1228"))100 assertEquals("12/28", CardFieldUtils.formatExpiry("122899")) 101 }102103 @Test fun new_card_expiry_rejects_invalid_month() {104 105 assertFalse(CardFieldUtils.isExpiryValid("13/28", currentYear2 = 26, currentMonth = 6))106 assertFalse(CardFieldUtils.isExpiryValid("00/28", currentYear2 = 26, currentMonth = 6))107 assertTrue(CardFieldUtils.isExpiryValid("12/28", currentYear2 = 26, currentMonth = 6))108 109 assertFalse(CardFieldUtils.isExpiryValid("12/24", currentYear2 = 26, currentMonth = 6))110 }111112 private fun identityEntry(id: String, username: String?, email: String?) = VaultEntry(113 id = id,114 title = id,115 type = "login",116 username = username,117 email = email,118 createdAt = 0,119 modifiedAt = 0,120 )121}