mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Opening Utilities while Data Layers is open no longer forgets that Contact was folded for the first, and closing one of them leaves Contact folded while the other is still open. Enter and Esc in a drawn shape's name keep focus in the field instead of dropping it to the page. The draw tool's destroy test now checks it stops following the board, and the Draw gate's amber-count comment sits on its function again.
186 lines
7.8 KiB
JavaScript
186 lines
7.8 KiB
JavaScript
// src/ui/views/panels/DrawMarkList.test.mjs — UTILITIES ▸ Draw's shapes:
|
|
// one row each, rendered from what the draw tool publishes, with the row
|
|
// controls answered through the display store. Rows are updated in place, so
|
|
// a board change never takes a half-typed name or the button under a click.
|
|
import '../../../testSupport/registerDom.mjs';
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createApp, nextTick } from 'vue';
|
|
import { createPinia } from 'pinia';
|
|
import { presentDrawMarks } from '../../../annotations/drawMarks.js';
|
|
import { useDisplayStore } from '../../stores/display.js';
|
|
import DrawMarkList from './DrawMarkList.vue';
|
|
|
|
const LINE = { id: 'a1', type: 'route', manual: true, name: null, label: '950 m', color: 'primary', hidden: false };
|
|
const PIN = { id: 'a2', type: 'pin', manual: true, name: 'Camp', label: 'Camp', color: 'amber', hidden: false };
|
|
const VOICE = { id: 'a3', type: 'area', manual: false, label: 'Texas', color: 'primary', hidden: false };
|
|
|
|
function mount(t) {
|
|
document.body.replaceChildren();
|
|
const toggle = document.body.appendChild(document.createElement('button'));
|
|
toggle.id = 'draw-toggle';
|
|
const pinia = createPinia();
|
|
const store = useDisplayStore(pinia);
|
|
const calls = [];
|
|
store.connect(
|
|
new Proxy(
|
|
{},
|
|
{ get: (_, name) => (...args) => calls.push([name, ...args]) },
|
|
),
|
|
);
|
|
const app = createApp(DrawMarkList).use(pinia);
|
|
app.mount(document.body.appendChild(document.createElement('div')));
|
|
t.after(() => app.unmount());
|
|
return { store, calls };
|
|
}
|
|
|
|
async function show(store, marks) {
|
|
store.publishDraw({ active: true, shape: 'area', color: 'primary', hint: '', marks: presentDrawMarks(marks) });
|
|
await nextTick();
|
|
}
|
|
const row = (id) => document.querySelector(`#draw-mark-list [data-mark-id="${id}"]`);
|
|
const control = (id, name) => row(id)?.querySelector(`[data-control="${name}"]`);
|
|
const key = (el, keyName) => {
|
|
const event = new KeyboardEvent('keydown', { key: keyName, bubbles: true, cancelable: true });
|
|
el.dispatchEvent(event);
|
|
return event;
|
|
};
|
|
|
|
test('lists only hand-drawn marks, named or by kind, with Import-style actions', async (t) => {
|
|
const { store } = mount(t);
|
|
const list = document.getElementById('draw-mark-list');
|
|
assert.equal(list.classList.contains('visible'), false);
|
|
await show(store, [LINE, PIN, VOICE]);
|
|
assert.equal(list.classList.contains('visible'), true);
|
|
assert.deepEqual([...list.children].map((node) => node.dataset.markId), ['a1', 'a2']);
|
|
assert.equal(control('a1', 'name').value, '');
|
|
assert.equal(control('a1', 'name').placeholder, 'Line · 950 m');
|
|
assert.equal(control('a2', 'name').value, 'Camp');
|
|
assert.match(control('a2', 'swatch').style.background, /#ffb547|rgb\(255, 181, 71\)/);
|
|
assert.equal(control('a2', 'toggle').getAttribute('aria-label'), 'Hide Camp');
|
|
assert.equal(control('a2', 'toggle').hasAttribute('aria-pressed'), false, 'the label says the state');
|
|
assert.equal(control('a2', 'fly').getAttribute('aria-label'), 'Fly to Camp');
|
|
assert.equal(control('a2', 'remove').getAttribute('aria-label'), 'Remove Camp');
|
|
});
|
|
|
|
test('show/hide, fly to and remove act on that one mark', async (t) => {
|
|
const { store, calls } = mount(t);
|
|
await show(store, [LINE, PIN]);
|
|
control('a2', 'toggle').click();
|
|
control('a1', 'fly').click();
|
|
control('a1', 'remove').click();
|
|
assert.deepEqual(calls, [
|
|
['toggleDrawMark', 'a2'],
|
|
['flyToDrawMark', 'a1'],
|
|
['removeDrawMark', 'a1'],
|
|
]);
|
|
await show(store, [{ ...PIN, hidden: true }]);
|
|
assert.equal(control('a2', 'toggle').getAttribute('aria-label'), 'Show Camp');
|
|
assert.ok(row('a2').classList.contains('hidden-mark'));
|
|
});
|
|
|
|
test('the swatch opens the colours in the row; a colour recolours and closes it', async (t) => {
|
|
const { store, calls } = mount(t);
|
|
await show(store, [LINE]);
|
|
control('a1', 'swatch').click();
|
|
await nextTick();
|
|
assert.equal(control('a1', 'swatch').getAttribute('aria-expanded'), 'true');
|
|
control('a1', 'color-red').click();
|
|
await nextTick();
|
|
await nextTick();
|
|
assert.deepEqual(calls, [['recolorDrawMark', 'a1', 'red']]);
|
|
assert.equal(control('a1', 'picker'), null, 'choosing closes the picker');
|
|
assert.equal(document.activeElement, control('a1', 'swatch'), 'and focus goes back to the swatch');
|
|
});
|
|
|
|
test('a name is saved on Enter or leaving the field; an unchanged one costs nothing', async (t) => {
|
|
const { store, calls } = mount(t);
|
|
await show(store, [LINE, PIN]);
|
|
const name = control('a1', 'name');
|
|
name.focus();
|
|
name.value = ' Ridge walk ';
|
|
key(name, 'Enter');
|
|
assert.deepEqual(calls, [['renameDrawMark', 'a1', 'Ridge walk']]);
|
|
assert.equal(document.activeElement, name, 'Enter keeps focus in the field');
|
|
name.blur();
|
|
assert.equal(calls.length, 1, 'the blur after Enter saves nothing more');
|
|
const pinName = control('a2', 'name');
|
|
pinName.focus();
|
|
pinName.blur();
|
|
assert.equal(calls.length, 1, 'leaving an unchanged name saves nothing');
|
|
pinName.focus();
|
|
pinName.value = 'Base';
|
|
pinName.blur();
|
|
assert.deepEqual(calls.at(-1), ['renameDrawMark', 'a2', 'Base']);
|
|
});
|
|
|
|
test('Escape drops the draft and stays in the list, even with the row\'s colours open', async (t) => {
|
|
const { store, calls } = mount(t);
|
|
await show(store, [PIN]);
|
|
control('a2', 'swatch').click();
|
|
await nextTick();
|
|
const name = control('a2', 'name');
|
|
name.focus();
|
|
name.value = 'Base';
|
|
const event = key(name, 'Escape');
|
|
assert.equal(event.defaultPrevented, true);
|
|
assert.equal(name.value, 'Camp', 'the saved name comes back');
|
|
assert.equal(document.activeElement, name, 'focus stays in the field');
|
|
await nextTick();
|
|
assert.deepEqual(calls, [], 'the draft is not saved');
|
|
// Escape in the open colours closes them and gives focus to the swatch.
|
|
control('a2', 'color-green').focus();
|
|
key(control('a2', 'color-green'), 'Escape');
|
|
await nextTick();
|
|
await nextTick();
|
|
assert.equal(control('a2', 'picker'), null);
|
|
assert.equal(document.activeElement, control('a2', 'swatch'));
|
|
});
|
|
|
|
test('a board change keeps the row, the name being typed and the focus', async (t) => {
|
|
const { store } = mount(t);
|
|
await show(store, [LINE, PIN]);
|
|
const before = row('a1');
|
|
const name = control('a1', 'name');
|
|
name.focus();
|
|
name.value = 'Half typ';
|
|
await show(store, [{ ...LINE, color: 'green' }, PIN, VOICE]);
|
|
assert.equal(row('a1'), before, 'the row is kept');
|
|
assert.equal(control('a1', 'name').value, 'Half typ', 'the draft survives');
|
|
assert.equal(document.activeElement, name);
|
|
});
|
|
|
|
test('when the focused row goes, focus moves to the next row, else the Draw button', async (t) => {
|
|
const { store } = mount(t);
|
|
await show(store, [LINE, PIN]);
|
|
control('a1', 'remove').focus();
|
|
await show(store, [PIN]);
|
|
assert.equal(document.activeElement, control('a2', 'remove'));
|
|
await show(store, []);
|
|
assert.equal(document.activeElement, document.getElementById('draw-toggle'));
|
|
});
|
|
|
|
test('the colours open next to the swatch with the current one focused, and the arrows try others', async (t) => {
|
|
const { store, calls } = mount(t);
|
|
await show(store, [PIN]);
|
|
control('a2', 'swatch').click();
|
|
await nextTick();
|
|
const picker = control('a2', 'picker');
|
|
assert.equal(control('a2', 'swatch').getAttribute('aria-controls'), picker.id);
|
|
assert.equal(picker.previousElementSibling, control('a2', 'swatch'), 'right after its swatch');
|
|
assert.equal(document.activeElement, control('a2', 'color-amber'), 'the current colour has focus');
|
|
assert.deepEqual(
|
|
[...picker.querySelectorAll('[role="radio"]')].map((node) => node.getAttribute('tabindex')),
|
|
['-1', '0', '-1', '-1', '-1'],
|
|
'one tab stop, on the checked colour',
|
|
);
|
|
key(control('a2', 'color-amber'), 'ArrowRight');
|
|
key(control('a2', 'color-amber'), 'End');
|
|
assert.deepEqual(calls, [
|
|
['recolorDrawMark', 'a2', 'cyan'],
|
|
['recolorDrawMark', 'a2', 'red'],
|
|
]);
|
|
await nextTick();
|
|
assert.ok(control('a2', 'picker'), 'the arrows keep the colours open');
|
|
});
|