AutofillPickerSpecSelectionTest.kt

2.0 KB · raw

1package com.peachpasswords.autofill23import org.junit.Assert.assertEquals4import org.junit.Assert.assertNull5import org.junit.Test67/**8 * Which inline spec hosts the "Search Peach…" chip.9 *10 * v2.14.6 collision fix (holds): with a single inline spec and an OTP chip11 * eligible, both chips would target specs[0] and the picker dataset -- added12 * last -- would clobber the 2FA chip. The picker drops to the system menu so13 * the OTP chip keeps the lone slot.14 *15 * v2.14.8 refinement: without an OTP chip the stale two-slot reservation16 * left the last spec empty (and with 2 specs the entry budget at zero). The17 * picker now anchors the last slot itself when no 2FA chip is eligible.18 */19class AutofillPickerSpecSelectionTest {20    private val a = "spec-A"21    private val b = "spec-B"22    private val c = "spec-C"23    private val d = "spec-D"2425    // --- no 2FA chip: picker anchors the last slot (v2.14.8) ---2627    @Test fun empty_specs_yield_null_picker() {28        assertNull(pickerSpecFor(emptyList(), otpEligible = false))29        assertNull(pickerSpecFor(emptyList(), otpEligible = true))30    }3132    @Test fun single_spec_goes_to_the_picker_when_no_otp_chip() {33        assertEquals(a, pickerSpecFor(listOf(a), otpEligible = false))34    }3536    @Test fun without_otp_the_picker_takes_the_last_slot() {37        assertEquals(b, pickerSpecFor(listOf(a, b), otpEligible = false))38        assertEquals(c, pickerSpecFor(listOf(a, b, c), otpEligible = false))39        assertEquals(d, pickerSpecFor(listOf(a, b, c, d), otpEligible = false))40    }4142    // --- with a 2FA chip: picker sits just before the OTP slot (v2.14.6) ---4344    @Test fun single_spec_yields_null_picker_so_otp_keeps_the_slot() {45        assertNull(pickerSpecFor(listOf(a), otpEligible = true))46    }4748    @Test fun with_otp_the_picker_sits_before_the_2fa_slot() {49        assertEquals(a, pickerSpecFor(listOf(a, b), otpEligible = true))50        assertEquals(b, pickerSpecFor(listOf(a, b, c), otpEligible = true))51        assertEquals(c, pickerSpecFor(listOf(a, b, c, d), otpEligible = true))52    }53}