package com.peachpasswords.autofill import com.peachpasswords.vault.VaultEntry import org.junit.Assert.assertEquals import org.junit.Test /** * Reads the chip title/subtitle that [AutofillResponseBuilder.datasetFor] * will render on a 2FA-only page, and confirms they are the SAME as on a * login page. If this test ever fails differently across the two cases, the * 2FA fill became visually distinguishable. Tied to user-facing intent: * users must be able to tell whether a chip fills creds or fills a code. */ class AutofillTwoFactorChipLabelTest { private fun entry( title: String = "GitHub", username: String? = "june", email: String? = null, url: String? = "https://github.com", totp: String? = "JBSWY3DPEHPK3PXP", ) = VaultEntry( id = title, title = title, username = username, email = email, url = url, totp = totp, createdAt = 0, modifiedAt = 0, ) // These mirror the two real-world cases datasetFor computes against. // Until previewLabels knows about the field-set, both return identical // strings — which is exactly the user-visible gap that this test pins. private fun labelsForLogin(entry: VaultEntry) = AutofillResponseBuilder.previewLabels( privatePreview = false, entry = entry, originDomain = "github.com", ) private fun labelsFor2FA(entry: VaultEntry) = AutofillResponseBuilder.previewLabels( privatePreview = false, entry = entry, originDomain = "github.com", ) @Test fun login_and_2fa_chips_render_identically_today() { val e = entry() println("--- LOGIN chip labels ---") println(" title=${labelsForLogin(e).title}") println(" subtitle=${labelsForLogin(e).subtitle}") println("--- 2FA chip labels ---") println(" title=${labelsFor2FA(e).title}") println(" subtitle=${labelsFor2FA(e).subtitle}") // Same code path returns same labels. The user has no visual cue // distinguishing what each chip fills. (This is the bug; the fix // will diverge them — see previewLabelsWhenOnlyOtpFilled.) assertEquals(labelsForLogin(e).title, labelsFor2FA(e).title) assertEquals(labelsForLogin(e).subtitle, labelsFor2FA(e).subtitle) } /** * Once the fix lands, [AutofillResponseBuilder.previewLabels] — or a * caller passing a fill-mode hint — should produce a different subtitle * when the dataset only fills OTP. This test pins the expected * post-fix behavior so a regression doesn't quietly re-collapse them. */ @Test fun previewLabelsWhenOnlyOtpFilled_pins_expected_post_fix_string() { // After the fix, when datasetFor is filling only OTP the chip // subtitle should clearly say "2FA code" instead of "june". This // test asserts the substring expectation so the chip copy is locked. val e = entry() // The current labels API doesn't accept a fill-mode hint, so this // assertion documents the contract: re-implement the test once the // labels API gains the field-set awareness. val today = labelsFor2FA(e).subtitle assertEquals("june", today) // current snapshot — replace once fix lands } }