Skip to content

Commit f19b103

Browse files
committed
Enhance Tests: button-toggle
1 parent 0ac5e8e commit f19b103

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

components/button/test/button-toggle.axe.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '../button-icon.js';
22
import '../button-toggle.js';
3-
import { expect, fixture, html } from '@brightspace-ui/testing';
3+
import { expect, fixture, focusElem, html } from '@brightspace-ui/testing';
44

55
describe('d2l-button-toggle', () => {
66

@@ -23,4 +23,40 @@ describe('d2l-button-toggle', () => {
2323
await expect(el).to.be.accessible();
2424
});
2525

26+
it('disabled', async() => {
27+
const el = await fixture(html`
28+
<d2l-button-toggle>
29+
<d2l-button-icon slot="not-pressed" disabled icon="tier1:pin-hollow" text="Unpinned, click to pin."></d2l-button-icon>
30+
<d2l-button-icon slot="pressed" disabled icon="tier1:pin-filled" text="Pinned, click to unpin."></d2l-button-icon>
31+
</d2l-button-toggle>
32+
`);
33+
await expect(el).to.be.accessible();
34+
});
35+
36+
describe('focus management', () => {
37+
38+
it('focused not-pressed button', async() => {
39+
const el = await fixture(html`
40+
<d2l-button-toggle>
41+
<d2l-button-icon slot="not-pressed" icon="tier1:pin-hollow" text="Unpinned, click to pin."></d2l-button-icon>
42+
<d2l-button-icon slot="pressed" icon="tier1:pin-filled" text="Pinned, click to unpin."></d2l-button-icon>
43+
</d2l-button-toggle>
44+
`);
45+
await focusElem(el);
46+
await expect(el).to.be.accessible();
47+
});
48+
49+
it('focused pressed button', async() => {
50+
const el = await fixture(html`
51+
<d2l-button-toggle pressed>
52+
<d2l-button-icon slot="not-pressed" icon="tier1:pin-hollow" text="Unpinned, click to pin."></d2l-button-icon>
53+
<d2l-button-icon slot="pressed" icon="tier1:pin-filled" text="Pinned, click to unpin."></d2l-button-icon>
54+
</d2l-button-toggle>
55+
`);
56+
await focusElem(el);
57+
await expect(el).to.be.accessible();
58+
});
59+
60+
});
61+
2662
});

components/button/test/button-toggle.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ describe('d2l-button-toggle', () => {
9292
const e = await oneEvent(el, 'd2l-button-toggle-change');
9393
expect(e.target.pressed).to.equal(true);
9494
});
95+
96+
it('d2l-button-toggle-before-change event has correct detail structure', async() => {
97+
clickElem(el.querySelector('[slot="not-pressed"]'));
98+
const e = await oneEvent(el, 'd2l-button-toggle-before-change');
99+
expect(e.detail).to.have.property('update').that.is.a('function');
100+
});
101+
});
102+
103+
describe('focus', () => {
104+
105+
it('throws error when no button exists to focus', async() => {
106+
const el = await fixture(html`<d2l-button-toggle></d2l-button-toggle>`);
107+
expect(() => el.focus()).to.throw('d2l-button-toggle: no button to focus');
108+
});
109+
95110
});
96111

97112
});

0 commit comments

Comments
 (0)