37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
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('<main id="m"><section class="plate"><p id="p">road</p></section></main>');
|
|
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(`
|
|
<a href="#x" id="a"><span id="in-a">link</span></a>
|
|
<button id="b"><svg id="svg"></svg></button>
|
|
<div role="button" id="rb">go</div>
|
|
<input id="i"><textarea id="t"></textarea><select id="s"><option id="o">1</option></select>
|
|
<label id="l">label</label><details><summary id="sum">more</summary></details>
|
|
<div class="dashcam-frame"><div id="dc">frame</div></div>`);
|
|
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('<p id="p">road</p>');
|
|
expect(isFlashTarget(d.getElementById('p'), 'road')).toBe(false);
|
|
expect(isFlashTarget(null, '')).toBe(false);
|
|
expect(isFlashTarget(d, '')).toBe(false);
|
|
});
|
|
});
|