-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdropdown.test.focus.single.ts
68 lines (52 loc) · 2.15 KB
/
dropdown.test.focus.single.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { expect, fixture, html } from '@open-wc/testing';
import './dropdown.option.js';
import { sendKeys } from '@web/test-runner-commands';
import GlideCoreDropdown from './dropdown.js';
it('focuses its primary button when `focus()` is called', async () => {
const host = await fixture<GlideCoreDropdown>(
html`<glide-core-dropdown label="Label">
<glide-core-dropdown-option label="Label"></glide-core-dropdown-option>
</glide-core-dropdown>`,
);
await sendKeys({ press: 'Tab' });
expect(host.shadowRoot?.activeElement).to.equal(
host.shadowRoot?.querySelector('[data-test="primary-button"]'),
);
});
it('focuses the button on submit', async () => {
const form = document.createElement('form');
const host = await fixture<GlideCoreDropdown>(
html`<glide-core-dropdown label="Label" required>
<glide-core-dropdown-option label="Label"></glide-core-dropdown-option>
</glide-core-dropdown>`,
{
parentNode: form,
},
);
form.requestSubmit();
const button = host.shadowRoot?.querySelector('[data-test="primary-button"]');
expect(host.shadowRoot?.activeElement).to.be.equal(button);
});
it('focuses its primary button when `reportValidity()` is called when required and no option is selected', async () => {
const form = document.createElement('form');
const host = await fixture<GlideCoreDropdown>(
html`<glide-core-dropdown label="Label" required>
<glide-core-dropdown-option label="Label"></glide-core-dropdown-option>
</glide-core-dropdown>`,
{ parentNode: form },
);
host.reportValidity();
const button = host.shadowRoot?.querySelector('[data-test="primary-button"]');
expect(host.shadowRoot?.activeElement).to.equal(button);
});
it('does not focus its primary button when `checkValidity()` is called', async () => {
const form = document.createElement('form');
const host = await fixture<GlideCoreDropdown>(
html`<glide-core-dropdown label="Label" required>
<glide-core-dropdown-option label="Label"></glide-core-dropdown-option>
</glide-core-dropdown>`,
{ parentNode: form },
);
host.checkValidity();
expect(host.shadowRoot?.activeElement).to.equal(null);
});