garage44.eu/jeroen/midas

logclone: git clone https://garage44.eu/jeroen/midas.git

.. /web/src/lib/confirm.test.ts

raw

import {expect, test} from 'bun:test'

import {ARMED_MS, isArmed, tap} from '@/lib/confirm'

test('the first tap arms, a second within the time does it', () => {
    const s = {key: '', until: 0}
    expect(tap(s, 'stop', 0)).toBe('arm')
    expect(isArmed(s, 'stop', 100)).toBe(true)
    expect(tap(s, 'stop', 100)).toBe('fire')
    expect(isArmed(s, 'stop', 100)).toBe(false)
})

test('too late, or another button, arms again rather than doing it', () => {
    const s = {key: '', until: 0}
    tap(s, 'stop', 0)
    expect(tap(s, 'stop', ARMED_MS + 1)).toBe('arm')
    expect(tap(s, 'done', ARMED_MS + 2)).toBe('arm')
    expect(isArmed(s, 'stop', ARMED_MS + 2)).toBe(false)
})