mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(globe): answer the clear and share actions through the globe actions store
The top-center bar is now GlobeActions.vue. The shell publishes whether a clear is under way and answers the clear and share buttons through the globe actions store, instead of binding listeners and writing attributes on the buttons. A shell disposed mid-clear resets the busy state, so the next shell's bar is not left busy. bindClearLayersControl stays exported and is deprecated.
This commit is contained in:
1 parent
f269f5be4f
commit
7edf8a577e
15 files changed
+242
-75
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// src/ui/globeActions.test.mjs — the top-center globe actions call their
|
||||
// owners through the globe actions store, and a clear under way keeps its
|
||||
// button focusable and marks it busy.
|
||||
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 { useGlobeActionsStore } from './stores/globeActions.js';
|
||||
import GlobeActions from './views/panels/GlobeActions.vue';
|
||||
|
||||
function mount(t) {
|
||||
document.body.replaceChildren();
|
||||
const pinia = createPinia();
|
||||
const store = useGlobeActionsStore(pinia);
|
||||
const calls = [];
|
||||
store.connect({
|
||||
clear: () => calls.push('clear'),
|
||||
share: () => calls.push('share'),
|
||||
});
|
||||
const app = createApp(GlobeActions).use(pinia);
|
||||
app.mount(document.body.appendChild(document.createElement('div')));
|
||||
t.after(() => app.unmount());
|
||||
return { calls, store };
|
||||
}
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
test('the clear and share buttons call their owners', (t) => {
|
||||
const { calls } = mount(t);
|
||||
$('clear-selected-layers').click();
|
||||
$('share-btn').click();
|
||||
assert.deepEqual(calls, ['clear', 'share']);
|
||||
});
|
||||
|
||||
test('a clear under way marks the button busy and keeps it focusable', async (t) => {
|
||||
const { store } = mount(t);
|
||||
const clear = $('clear-selected-layers');
|
||||
assert.equal(clear.getAttribute('aria-label'), 'Clear selected data layers');
|
||||
assert.equal(clear.hasAttribute('aria-busy'), false);
|
||||
store.publishClearBusy(true);
|
||||
await nextTick();
|
||||
assert.equal(clear.getAttribute('aria-busy'), 'true');
|
||||
assert.equal(clear.getAttribute('aria-disabled'), 'true');
|
||||
assert.equal(
|
||||
clear.getAttribute('aria-label'),
|
||||
'Clearing selected data layers',
|
||||
);
|
||||
assert.equal(clear.disabled, false);
|
||||
store.publishClearBusy(false);
|
||||
await nextTick();
|
||||
assert.equal(clear.getAttribute('aria-busy'), 'false');
|
||||
assert.equal(clear.getAttribute('aria-label'), 'Clear selected data layers');
|
||||
// A shell disposed mid-clear hands the next one a bar that is not busy.
|
||||
store.publishClearBusy(true);
|
||||
store.publishClearBusy(null);
|
||||
await nextTick();
|
||||
assert.equal(clear.hasAttribute('aria-busy'), false);
|
||||
assert.equal(clear.hasAttribute('aria-disabled'), false);
|
||||
assert.equal(clear.getAttribute('aria-label'), 'Clear selected data layers');
|
||||
});
|
||||
|
||||
test('a detached owner no longer answers', (t) => {
|
||||
const { calls, store } = mount(t);
|
||||
const token = store.connect({ share: () => calls.push('newer share') });
|
||||
$('share-btn').click();
|
||||
store.detach(token);
|
||||
$('share-btn').click();
|
||||
assert.deepEqual(calls, ['newer share', 'share']);
|
||||
});
|
||||
Reference in new issue
Block a user