package com.peachpasswords.autofill import org.junit.Assert.assertEquals import org.junit.Test class OtpDigitsTest { @Test fun distributes_a_code_one_character_per_box() { assertEquals( listOf("1", "2", "3", "4", "5", "6"), AutofillResponseBuilder.otpDigitsFor(6, "123456"), ) } @Test fun stops_at_the_box_count_when_the_code_is_longer() { assertEquals(listOf("1", "2", "3", "4"), AutofillResponseBuilder.otpDigitsFor(4, "123456")) } @Test fun fills_fewer_boxes_than_code_length_when_there_are_more_boxes() { assertEquals( listOf("1", "2", "3", "4", "5", "6"), AutofillResponseBuilder.otpDigitsFor(8, "123456"), ) } @Test fun strips_whitespace_before_distributing() { assertEquals(listOf("1", "2", "3"), AutofillResponseBuilder.otpDigitsFor(6, "1 2 3")) } @Test fun six_boxes_map_to_a_full_six_digit_code() { // Common 2FA split layout: 6 single-character boxes for a 6-digit TOTP. // Mirrors the inline chip path where [parsed.otpDigitBoxIds] is six // AutofillIds and the entry's TOTP seed generates a fresh code. val boxes = AutofillResponseBuilder.otpDigitsFor(6, "481208") assertEquals(listOf("4", "8", "1", "2", "0", "8"), boxes) } @Test fun empty_code_produces_empty_boxes() { // Edge case: the entry has no TOTP seed and generateCode returned null; // otpDigitsFor must not crash when there is no code to distribute. assertEquals(emptyList(), AutofillResponseBuilder.otpDigitsFor(6, "")) } }