|
1 | 1 | import { expect, fixture, html, aTimeout, nextFrame } from '@open-wc/testing'; |
2 | | -import { sendKeys } from '@web/test-runner-commands'; |
3 | 2 |
|
4 | | -import { allUpdates, clickElementAtCenter } from '@patternfly/pfe-tools/test/utils.js'; |
| 3 | +import { allUpdates, clickElementAtCenter, press as pressKey } from '@patternfly/pfe-tools/test/utils.js'; |
5 | 4 | import { a11ySnapshot, querySnapshot } from '@patternfly/pfe-tools/test/a11y-snapshot.js'; |
6 | 5 |
|
7 | 6 | // Import the element we're testing. |
@@ -56,9 +55,9 @@ describe('<pf-v5-accordion>', function() { |
56 | 55 | await allUpdates(element); |
57 | 56 | } |
58 | 57 |
|
59 | | - function press(press: string) { |
| 58 | + function press(key: string) { |
60 | 59 | return async function() { |
61 | | - await sendKeys({ press }); |
| 60 | + await pressKey(key); |
62 | 61 | await allUpdates(element); |
63 | 62 | }; |
64 | 63 | } |
@@ -391,14 +390,7 @@ describe('<pf-v5-accordion>', function() { |
391 | 390 | describe('Tab', function() { |
392 | 391 | beforeEach(press('Tab')); |
393 | 392 | it('blurs out of the accordion', async function() { |
394 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
395 | | - }); |
396 | | - }); |
397 | | - |
398 | | - describe('Shift+Tab', function() { |
399 | | - beforeEach(press('Shift+Tab')); |
400 | | - it('blurs out of the accordion', async function() { |
401 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
| 393 | + expect(await a11ySnapshot()).to.not.axContainQuery({ role: 'button', focused: true }); |
402 | 394 | }); |
403 | 395 | }); |
404 | 396 |
|
@@ -479,7 +471,7 @@ describe('<pf-v5-accordion>', function() { |
479 | 471 | describe('Tab', function() { |
480 | 472 | beforeEach(press('Tab')); |
481 | 473 | it('moves focus to the body', async function() { |
482 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
| 474 | + expect(await a11ySnapshot()).to.not.axContainQuery({ role: 'button', focused: true }); |
483 | 475 | }); |
484 | 476 | }); |
485 | 477 |
|
@@ -554,13 +546,6 @@ describe('<pf-v5-accordion>', function() { |
554 | 546 | }); |
555 | 547 | }); |
556 | 548 |
|
557 | | - describe('Shift+Tab', function() { |
558 | | - beforeEach(press('Shift+Tab')); |
559 | | - it('moves focus to the body', async function() { |
560 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
561 | | - }); |
562 | | - }); |
563 | | - |
564 | 549 | describe('ArrowDown', function() { |
565 | 550 | beforeEach(press('ArrowDown')); |
566 | 551 | it('moves focus to the first header', async function() { |
@@ -628,14 +613,8 @@ describe('<pf-v5-accordion>', function() { |
628 | 613 |
|
629 | 614 | describe('Tab', function() { |
630 | 615 | beforeEach(press('Tab')); |
631 | | - it('moves focus to the body', async function() { |
632 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
633 | | - }); |
634 | | - describe('Shift+Tab', function() { |
635 | | - beforeEach(press('Shift+Tab')); |
636 | | - it('keeps focus on the link in the first panel', async function() { |
637 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(panel1.querySelector('a')); |
638 | | - }); |
| 616 | + it('moves focus out of the accordion', async function() { |
| 617 | + expect(await a11ySnapshot()).to.not.axContainQuery({ role: 'button', focused: true }); |
639 | 618 | }); |
640 | 619 | }); |
641 | 620 |
|
@@ -732,7 +711,9 @@ describe('<pf-v5-accordion>', function() { |
732 | 711 | describe('Home', function() { |
733 | 712 | beforeEach(press('Home')); |
734 | 713 | it('moves focus to the first header', async function() { |
735 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(header1); |
| 714 | + expect(await a11ySnapshot()) |
| 715 | + .axTreeFocusedNode.to.have |
| 716 | + .axName(header1.textContent!.trim()); |
736 | 717 | }); |
737 | 718 |
|
738 | 719 | it('does not open other panels', function() { |
@@ -822,7 +803,7 @@ describe('<pf-v5-accordion>', function() { |
822 | 803 | describe('Shift+Tab', function() { |
823 | 804 | beforeEach(press('Shift+Tab')); |
824 | 805 | it('moves focus to the body', async function() { |
825 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
| 806 | + expect(await a11ySnapshot()).to.not.axContainQuery({ role: 'button', focused: true }); |
826 | 807 | }); |
827 | 808 | }); |
828 | 809 |
|
@@ -1111,25 +1092,23 @@ describe('<pf-v5-accordion>', function() { |
1111 | 1092 | }); |
1112 | 1093 | beforeEach(() => allUpdates(element)); |
1113 | 1094 | it('expands the first top-level pair', async function() { |
1114 | | - const snapshot = await a11ySnapshot(); |
1115 | | - const expanded = snapshot?.children?.find(x => x.expanded); |
1116 | | - expect(expanded?.name).to.equal(topLevelHeader1.textContent?.trim()); |
| 1095 | + expect(await a11ySnapshot()) |
| 1096 | + .to.axContainQuery({ name: topLevelHeader1.textContent?.trim(), expanded: true }); |
1117 | 1097 | expect(topLevelHeader1.expanded).to.be.true; |
1118 | 1098 | expect(topLevelPanel1.hasAttribute('expanded')).to.be.true; |
1119 | 1099 | expect(topLevelPanel1.expanded).to.be.true; |
1120 | 1100 | }); |
1121 | 1101 | it('collapses the second top-level pair', async function() { |
1122 | | - const snapshot = await a11ySnapshot(); |
1123 | | - const header2 = querySnapshot(snapshot, { name: 'top-header-2' }); |
1124 | | - expect(header2).to.have.property('expanded', true); |
| 1102 | + expect(await a11ySnapshot()) |
| 1103 | + .to.axContainQuery({ name: 'top-header-2', expanded: true }); |
1125 | 1104 | }); |
1126 | 1105 | it('collapses the first nested pair', async function() { |
1127 | | - const snapshot = await a11ySnapshot(); |
1128 | | - expect(querySnapshot(snapshot, { name: 'nest-1-header-1' })).to.not.have.property('expanded'); |
| 1106 | + expect(await a11ySnapshot()) |
| 1107 | + .to.not.axContainQuery({ name: 'nest-1-header-1', expanded: true }); |
1129 | 1108 | }); |
1130 | 1109 | it('collapses the second nested pair', async function() { |
1131 | | - const snapshot = await a11ySnapshot(); |
1132 | | - expect(querySnapshot(snapshot, { name: 'nest-2-header-1' })).to.not.have.property('expanded'); |
| 1110 | + expect(await a11ySnapshot()) |
| 1111 | + .to.not.axContainQuery({ name: 'nest-2-header-1', expanded: true }); |
1133 | 1112 | }); |
1134 | 1113 | }); |
1135 | 1114 | }); |
@@ -1249,7 +1228,7 @@ describe('<pf-v5-accordion>', function() { |
1249 | 1228 | beforeEach(press('Tab')); |
1250 | 1229 | beforeEach(nextFrame); |
1251 | 1230 | it('should move focus back to the body', async function() { |
1252 | | - expect(await a11ySnapshot()).to.have.axTreeFocusOn(document.body); |
| 1231 | + expect(await a11ySnapshot()).to.not.axContainQuery({ role: 'button', focused: true }); |
1253 | 1232 | }); |
1254 | 1233 | }); |
1255 | 1234 | }); |
|
0 commit comments