Skip to content

Commit 0ac5e8e

Browse files
Enhance Tests: button-add (#6292)
* Enhance Tests: button-add * Update button-add.vdiff.js * Updating vdiff goldens (#6293) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * code review feedback: remove unnecessary setTimeouts --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ad8bb05 commit 0ac5e8e

9 files changed

+108
-6
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,32 @@ describe('d2l-button-add', () => {
3434
await focusElem(el);
3535
await expect(el).to.be.accessible();
3636
});
37+
3738
it('focused, icon-when-interacted mode', async() => {
3839
const el = await fixture(html`<d2l-button-add mode="icon-when-interacted"></d2l-button-add>`);
3940
await focusElem(el);
4041
await expect(el).to.be.accessible();
4142
});
4243

44+
describe('tooltip', () => {
45+
46+
it('should have tooltip for attribute matching button id in icon mode', async() => {
47+
const el = await fixture(html`<d2l-button-add text="Add New Item"></d2l-button-add>`);
48+
const button = el.shadowRoot.querySelector('button');
49+
const tooltip = el.shadowRoot.querySelector('d2l-tooltip');
50+
expect(tooltip).to.exist;
51+
expect(tooltip.getAttribute('for-type')).to.equal('label');
52+
expect(button.id).to.equal(tooltip.getAttribute('for'));
53+
});
54+
55+
it('should have tooltip for attribute matching button id in icon-when-interacted mode', async() => {
56+
const el = await fixture(html`<d2l-button-add mode="icon-when-interacted" text="Add New Item"></d2l-button-add>`);
57+
const button = el.shadowRoot.querySelector('button');
58+
const tooltip = el.shadowRoot.querySelector('d2l-tooltip');
59+
expect(tooltip).to.exist;
60+
expect(button.id).to.equal(tooltip.getAttribute('for'));
61+
});
62+
63+
});
64+
4365
});

components/button/test/button-add.test.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '../button-add.js';
2-
import { clickElem, expect, fixture, html, oneEvent, runConstructor } from '@brightspace-ui/testing';
2+
import { clickElem, expect, fixture, html, oneEvent, runConstructor, sendKeysElem } from '@brightspace-ui/testing';
33
import { createMessage } from '../../../mixins/property-required/property-required-mixin.js';
44

55
describe('d2l-button-add', () => {
@@ -12,12 +12,11 @@ describe('d2l-button-add', () => {
1212

1313
});
1414

15-
describe('events', () => {
15+
describe('properties', () => {
1616

17-
it('dispatches click event when clicked', async() => {
18-
const el = await fixture(html`<d2l-button-add></d2l-button-add>`);
19-
setTimeout(() => clickElem(el));
20-
await oneEvent(el, 'click');
17+
it('should default mode to "icon"', async() => {
18+
const el = await fixture(html`<d2l-button-add text="Add"></d2l-button-add>`);
19+
expect(el.mode).to.equal('icon');
2120
});
2221

2322
it('throws error when no text', async() => {
@@ -33,4 +32,31 @@ describe('d2l-button-add', () => {
3332

3433
});
3534

35+
describe('focus', () => {
36+
37+
it('should focus on button element', async() => {
38+
const el = await fixture(html`<d2l-button-add text="Add"></d2l-button-add>`);
39+
await el.focus();
40+
const button = el.shadowRoot.querySelector('button');
41+
expect(el.shadowRoot.activeElement).to.equal(button);
42+
});
43+
44+
});
45+
46+
describe('events', () => {
47+
48+
it('dispatches click event when clicked', async() => {
49+
const el = await fixture(html`<d2l-button-add text="Add"></d2l-button-add>`);
50+
clickElem(el);
51+
await oneEvent(el, 'click');
52+
});
53+
54+
it('dispatches click event when press enter', async() => {
55+
const el = await fixture(html`<d2l-button-add text="Add"></d2l-button-add>`);
56+
sendKeysElem(el, 'press', 'Enter');
57+
await oneEvent(el, 'click');
58+
});
59+
60+
});
61+
3662
});

components/button/test/button-add.vdiff.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,58 @@ describe('button-add', () => {
5050
});
5151
});
5252
});
53+
54+
describe('edge cases', () => {
55+
56+
it('long text icon mode', async() => {
57+
const elem = await fixture(html`<d2l-button-add text="Add a New Item with a Very Long Description That Should Be Handled Properly"></d2l-button-add>`);
58+
await focusElem(elem);
59+
await oneEvent(elem, 'd2l-tooltip-show');
60+
await expect(elem).to.be.golden({ margin: 12 });
61+
});
62+
63+
it('long text icon-and-text mode', async() => {
64+
const elem = await fixture(html`<d2l-button-add mode="icon-and-text" text="Add a New Item with a Very Long Description That Should Be Handled Properly"></d2l-button-add>`);
65+
await expect(elem).to.be.golden({ margin: 12 });
66+
});
67+
68+
it('long text icon-and-text mode constrained width', async() => {
69+
const elem = await fixture(html`
70+
<div style="width: 400px;">
71+
<d2l-button-add mode="icon-and-text" text="Add a New Item with a Very Long Description That Should Be Handled Properly"></d2l-button-add>
72+
</div>
73+
`);
74+
await expect(elem).to.be.golden();
75+
});
76+
77+
it('long text icon-when-interacted mode hover', async() => {
78+
const elem = await fixture(html`<d2l-button-add mode="icon-when-interacted" text="Add a New Item with a Very Long Description That Should Be Handled Properly"></d2l-button-add>`);
79+
await hoverElem(elem);
80+
await oneEvent(elem, 'd2l-tooltip-show');
81+
await expect(elem).to.be.golden({ margin: 12 });
82+
});
83+
84+
});
85+
86+
describe('backgrounds', () => {
87+
88+
it('colored background', async() => {
89+
const elem = await fixture(html`
90+
<div style="background-color: #f9fafb; padding: 20px;">
91+
<d2l-button-add mode="icon-and-text" text="Add Item"></d2l-button-add>
92+
</div>
93+
`);
94+
await expect(elem).to.be.golden();
95+
});
96+
97+
it('dark background icon mode', async() => {
98+
const elem = await fixture(html`
99+
<div style="background-color: #494c4e; padding: 20px;">
100+
<d2l-button-add text="Add Item"></d2l-button-add>
101+
</div>
102+
`);
103+
await expect(elem).to.be.golden();
104+
});
105+
106+
});
53107
});
4.93 KB
Loading
2.72 KB
Loading
8.85 KB
Loading
12 KB
Loading
17.1 KB
Loading
16.2 KB
Loading

0 commit comments

Comments
 (0)