package com.peachpasswords.autofill import com.peachpasswords.autofill.AutofillResponseBuilder.FillMode import com.peachpasswords.vault.VaultEntry import org.junit.Assert.assertEquals import org.junit.Assert.assertNotEquals import org.junit.Test /** * Confirms the keyboard-row chip carries WHAT it will fill. Users must be * able to tell a creds-fill chip from a TOTP-fill chip at a glance — same * labels on both pages was a real user-visible gap (logged 2026-08-05). * * The fix routes the OTP-only fill path through a separate FillMode so the * chip title carries the actual TOTP code instead of the entry title. */ 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, ) private fun loginLabels() = AutofillResponseBuilder.previewLabels( privatePreview = false, entry = entry(), originDomain = "github.com", fillMode = FillMode.LOGIN, ) private fun otpLabels(code: String = "482901") = AutofillResponseBuilder.previewLabels( privatePreview = false, entry = entry(), originDomain = "github.com", fillMode = FillMode.OTP_FILL, otpCode = code, ) @Test fun login_and_2fa_chips_now_differ() { val login = loginLabels() val otp = otpLabels() println("--- LOGIN chip labels ---") println(" title=${login.title} subtitle=${login.subtitle}") println("--- 2FA chip labels ---") println(" title=${otp.title} subtitle=${otp.subtitle}") assertEquals("GitHub", login.title) assertEquals("june", login.subtitle) assertEquals("482 901", otp.title) assertEquals("2FA", otp.subtitle) assertNotEquals(login.title, otp.title) assertNotEquals(login.subtitle, otp.subtitle) } @Test fun otp_label_tracks_the_code_passed_in() { // The chip is recomputed each call — a fresh code passed in shows up // as the title. Verification gate for the datasetFor recompute path // (Phase B), which will route a chip-tap through this same labels // function with a newly-generated TOTP code. val one = otpLabels("111111") val two = otpLabels("222222") assertEquals("111 111", one.title) assertEquals("222 222", two.title) } }