Skip to content

Commit e2cf082

Browse files
authored
test: prefer getDeepActiveElement in assertions (#5869)
1 parent 82b3017 commit e2cf082

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

‎packages/dialog/test/dialog.test.js‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from '@esm-bundle/chai';
22
import { aTimeout, esc, fixtureSync, oneEvent } from '@vaadin/testing-helpers';
33
import '../vaadin-dialog.js';
4-
import { isElementFocused } from '@vaadin/a11y-base/src/focus-utils.js';
4+
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
55

66
describe('vaadin-dialog', () => {
77
describe('custom element definition', () => {
@@ -164,7 +164,7 @@ describe('vaadin-dialog', () => {
164164
});
165165

166166
describe('focus restoration', () => {
167-
let dialog, button;
167+
let dialog, button, overlay;
168168

169169
beforeEach(() => {
170170
const wrapper = fixtureSync(`
@@ -174,21 +174,22 @@ describe('vaadin-dialog', () => {
174174
</div>
175175
`);
176176
[dialog, button] = wrapper.children;
177+
overlay = dialog.$.overlay;
177178
button.focus();
178179
});
179180

180181
it('should move focus to the dialog on open', async () => {
181182
dialog.opened = true;
182-
await oneEvent(dialog.$.overlay, 'vaadin-overlay-open');
183-
expect(isElementFocused(dialog.$.overlay)).to.be.true;
183+
await oneEvent(overlay, 'vaadin-overlay-open');
184+
expect(getDeepActiveElement()).to.equal(overlay.$.overlay);
184185
});
185186

186187
it('should restore focus on dialog close', async () => {
187188
dialog.opened = true;
188-
await oneEvent(dialog.$.overlay, 'vaadin-overlay-open');
189+
await oneEvent(overlay, 'vaadin-overlay-open');
189190
dialog.opened = false;
190191
await aTimeout(0);
191-
expect(isElementFocused(button)).to.be.true;
192+
expect(getDeepActiveElement()).to.equal(button);
192193
});
193194
});
194195
});

‎packages/grid/test/keyboard-navigation.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import '../vaadin-grid.js';
1919
import '../vaadin-grid-tree-column.js';
2020
import '../vaadin-grid-column-group.js';
2121
import '../vaadin-grid-selection-column.js';
22-
import { isElementFocused } from '@vaadin/a11y-base/src/focus-utils.js';
22+
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
2323
import {
2424
attributeRenderer,
2525
flushGrid,
@@ -1606,7 +1606,7 @@ describe('keyboard navigation', () => {
16061606

16071607
enter();
16081608

1609-
expect(isElementFocused(focusable)).to.be.true;
1609+
expect(getDeepActiveElement()).to.equal(focusable);
16101610
});
16111611

16121612
it('should exit interaction mode from focused single-line input with enter', () => {

‎packages/overlay/test/restore-focus.test.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from '@esm-bundle/chai';
22
import { fixtureSync } from '@vaadin/testing-helpers';
33
import '../src/vaadin-overlay.js';
44
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
5-
import { isElementFocused } from '@vaadin/a11y-base/src/focus-utils.js';
5+
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
66
import { close, open } from './helpers.js';
77

88
customElements.define(
@@ -66,7 +66,7 @@ describe('restore focus', () => {
6666
focusInput.focus();
6767
await open(overlay);
6868
await close(overlay);
69-
expect(isElementFocused(focusInput)).to.be.false;
69+
expect(getDeepActiveElement()).to.not.equal(focusInput);
7070
});
7171

7272
it('should not restore focus-ring attribute on close by default', async () => {
@@ -87,7 +87,7 @@ describe('restore focus', () => {
8787
focusInput.focus();
8888
await open(overlay);
8989
await close(overlay);
90-
expect(isElementFocused(focusInput)).to.be.false;
90+
expect(getDeepActiveElement()).to.not.equal(focusInput);
9191
});
9292

9393
it('should not restore focus-ring attribute on close by default', async () => {
@@ -119,7 +119,7 @@ describe('restore focus', () => {
119119
focusInput.focus();
120120
await open(overlay);
121121
await close(overlay);
122-
expect(isElementFocused(focusInput)).to.be.true;
122+
expect(getDeepActiveElement()).to.equal(focusInput);
123123
});
124124

125125
it('should restore focus-ring attribute on close', async () => {
@@ -142,15 +142,15 @@ describe('restore focus', () => {
142142
focusable.focus();
143143
await open(overlay);
144144
await close(overlay);
145-
expect(isElementFocused(focusable)).to.be.true;
145+
expect(getDeepActiveElement()).to.equal(focusable);
146146
});
147147

148148
it('should restore focus on close if focus was moved to body', async () => {
149149
focusInput.focus();
150150
await open(overlay);
151151
overlay.blur();
152152
await close(overlay);
153-
expect(isElementFocused(focusInput)).to.be.true;
153+
expect(getDeepActiveElement()).to.equal(focusInput);
154154
});
155155

156156
it('should restore focus-ring attribute on close if focus was moved to body', async () => {
@@ -168,7 +168,7 @@ describe('restore focus', () => {
168168
await open(overlay);
169169
focusable.focus();
170170
await close(overlay);
171-
expect(isElementFocused(focusable)).to.be.true;
171+
expect(getDeepActiveElement()).to.equal(focusable);
172172
});
173173

174174
it('should not restore focus-ring attribute if focus was moved outside overlay', async () => {
@@ -190,7 +190,7 @@ describe('restore focus', () => {
190190
focusable.focus();
191191
await open(overlay);
192192
await close(overlay);
193-
expect(isElementFocused(focusInput)).to.be.true;
193+
expect(getDeepActiveElement()).to.equal(focusInput);
194194
});
195195

196196
it('should restore focus-ring attribute on the restoreFocusNode', async () => {

0 commit comments

Comments
 (0)