mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
UiCloseButton is a UiButton with a fixed glyph (× or the Material close symbol through UiIcon), a required accessible label and no tip unless the site passes a title. Attributes and classes pass through, so each site keeps its id, feature class, data and aria attributes, and its look. Its kit class, ui-close-button (close-button.css, loaded before the feature stylesheets), is Core's common look: a bare glyph with no padding, border or background of its own, and a pointer. The guide's close button shares the rule, and the copies of those declarations leave the feature rules. `bare` leaves the look off for Street Level's and the space mission's close buttons, whose skins keep the browser's padding. UiIcon takes size null to leave the glyph's size to the stylesheet. The sixteen hand-written close, dismiss and clear buttons in the SFCs are now UiCloseButtons; closeButtons.test.mjs pins that none remain. Co-authored-by: Manjunath Paparaju <[email protected]>
99 lines
3.2 KiB
JavaScript
99 lines
3.2 KiB
JavaScript
import { after, before, test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { installVueDom } from '../../testSupport/vueDom.mjs';
|
||
|
||
let mount;
|
||
let UiCloseButton;
|
||
let uninstall;
|
||
before(async () => {
|
||
uninstall = installVueDom();
|
||
({ mount } = await import('@vue/test-utils'));
|
||
UiCloseButton = (await import('./UiCloseButton.vue')).default;
|
||
});
|
||
after(() => uninstall());
|
||
|
||
function mountClose(props = {}, attrs = {}) {
|
||
return mount(UiCloseButton, {
|
||
attachTo: document.body,
|
||
props: { label: 'Close card', ...props },
|
||
attrs,
|
||
});
|
||
}
|
||
|
||
test('a close button is a button named by its label, with no tip of its own', () => {
|
||
const wrapper = mountClose();
|
||
const button = wrapper.get('button');
|
||
assert.equal(button.attributes('type'), 'button');
|
||
assert.equal(button.attributes('aria-label'), 'Close card');
|
||
assert.equal(button.attributes('title'), undefined);
|
||
assert.ok(button.classes().includes('ui-close-button'));
|
||
wrapper.unmount();
|
||
});
|
||
|
||
test('glyph="times" draws the × character', () => {
|
||
const wrapper = mountClose();
|
||
const button = wrapper.get('button');
|
||
assert.equal(button.element.innerHTML, '×');
|
||
wrapper.unmount();
|
||
});
|
||
|
||
test('glyph="icon" draws the Material close symbol, sized by the stylesheet', () => {
|
||
const wrapper = mountClose({ glyph: 'icon' });
|
||
const icon = wrapper.get('button > span');
|
||
assert.equal(wrapper.get('button').element.children.length, 1);
|
||
assert.equal(icon.text(), 'close');
|
||
assert.ok(icon.classes().includes('material-symbols-outlined'));
|
||
assert.equal(icon.attributes('aria-hidden'), 'true');
|
||
assert.equal(icon.attributes('style'), undefined);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
test('attributes and classes pass through to the button', () => {
|
||
const wrapper = mountClose(
|
||
{},
|
||
{
|
||
id: 'gev-chat-close',
|
||
class: 'data-toggle-chip',
|
||
title: 'Clear reading',
|
||
'data-action-id': 'clear',
|
||
'aria-hidden': 'true',
|
||
disabled: true,
|
||
hidden: true,
|
||
},
|
||
);
|
||
const button = wrapper.get('button');
|
||
assert.equal(button.attributes('id'), 'gev-chat-close');
|
||
assert.ok(button.classes().includes('data-toggle-chip'));
|
||
assert.ok(button.classes().includes('ui-close-button'));
|
||
assert.equal(button.attributes('title'), 'Clear reading');
|
||
assert.equal(button.attributes('data-action-id'), 'clear');
|
||
assert.equal(button.attributes('aria-hidden'), 'true');
|
||
assert.equal(button.element.disabled, true);
|
||
assert.equal(button.element.hidden, true);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
test('bare leaves the kit look off', () => {
|
||
const wrapper = mountClose({ bare: true }, { class: 'sl-viewer-x' });
|
||
const classes = wrapper.get('button').classes();
|
||
assert.ok(classes.includes('sl-viewer-x'));
|
||
assert.equal(classes.includes('ui-close-button'), false);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
test('a click is emitted with its event', async () => {
|
||
const wrapper = mountClose();
|
||
await wrapper.get('button').trigger('click');
|
||
const clicks = wrapper.emitted('click');
|
||
assert.equal(clicks.length, 1);
|
||
assert.ok(clicks[0][0] instanceof Event);
|
||
wrapper.unmount();
|
||
});
|
||
|
||
test('a disabled close button emits no click', async () => {
|
||
const wrapper = mountClose({}, { disabled: true });
|
||
await wrapper.get('button').trigger('click');
|
||
assert.equal(wrapper.emitted('click'), undefined);
|
||
wrapper.unmount();
|
||
});
|