import { describe, expect, it } from 'vitest'; import { isFlashTarget } from '@/journey/flash-target'; function dom(html: string): Document { document.body.innerHTML = html; return document; } describe('click to flash: which clicks lift the high beam', () => { it('flashes from the open page: body, a section, a paragraph', () => { const d = dom('

road

'); expect(isFlashTarget(d.body, '')).toBe(true); expect(isFlashTarget(d.getElementById('m'), null)).toBe(true); expect(isFlashTarget(d.getElementById('p'), undefined)).toBe(true); }); it('never from a control, its descendants, a form field or the dashcam frame', () => { const d = dom(` link
go
more
frame
`); for (const id of ['a', 'in-a', 'b', 'svg', 'rb', 'i', 't', 's', 'o', 'l', 'sum', 'dc']) { expect(isFlashTarget(d.getElementById(id), ''), id).toBe(false); } }); it('never while text is selected, and never from a non-element target', () => { const d = dom('

road

'); expect(isFlashTarget(d.getElementById('p'), 'road')).toBe(false); expect(isFlashTarget(null, '')).toBe(false); expect(isFlashTarget(d, '')).toBe(false); }); });