import assert from 'node:assert/strict' import { test } from 'node:test' import { nextPin, pinAction } from '../src/components/pin.js' test('keys map to actions', () => { assert.deepEqual(pinAction('7'), { type: 'digit', digit: '7' }) assert.deepEqual(pinAction('Backspace'), { type: 'backspace' }) assert.deepEqual(pinAction('Delete'), { type: 'backspace' }) for (const k of ['a', 'Enter', 'Escape', ' ', '12', '']) assert.equal(pinAction(k), null, k) }) test('digits stop at the length', () => { let v = '' for (const k of '123456') v = nextPin(v, pinAction(k), 4) assert.equal(v, '1234') }) test('backspace and clear', () => { assert.equal(nextPin('123', { type: 'backspace' }, 4), '12') assert.equal(nextPin('', { type: 'backspace' }, 4), '') assert.equal(nextPin('123', { type: 'clear' }, 4), '') assert.equal(nextPin('12', null, 4), '12') })