Skip to content

Commit 2c6921a

Browse files
committed
fix tests
1 parent 66ce969 commit 2c6921a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

packages/@react-spectrum/menu/test/SubMenuTrigger.test.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,16 @@ describe('SubMenu', function () {
822822
expect(subMenu1).toHaveAttribute('aria-label', subMenuTrigger1.textContent);
823823
buttons = within(tray).getAllByRole('button');
824824
expect(buttons).toHaveLength(3);
825+
let menuHeader = within(tray).getAllByText(subMenuTrigger1.textContent)[0];
826+
expect(menuHeader).toBeVisible();
827+
expect(menuHeader.tagName).toBe('SPAN');
825828
for (let button of buttons) {
826829
if (button.getAttribute('aria-label') !== 'Dismiss') {
827-
expect(button).toHaveAttribute('aria-label', `Return to ${subMenuTrigger1.textContent}`);
830+
expect(button).toHaveAttribute('aria-label', 'Return to ');
831+
expect(button).toHaveAttribute('aria-labelledby', `${button.id} ${menuHeader.id}`)
828832
}
829833
}
830-
let menuHeader = within(tray).getAllByText(subMenuTrigger1.textContent)[0];
831-
expect(menuHeader).toBeVisible();
832-
expect(menuHeader.tagName).toBe('SPAN');
834+
833835
let subMenu1Items = within(subMenu1).getAllByRole('menuitem');
834836
let subMenuTrigger2 = subMenu1Items[2];
835837
triggerTouch(subMenuTrigger2);
@@ -844,14 +846,16 @@ describe('SubMenu', function () {
844846
expect(subMenu2).toHaveAttribute('aria-label', subMenuTrigger2.textContent);
845847
buttons = within(tray).getAllByRole('button');
846848
expect(buttons).toHaveLength(3);
849+
menuHeader = within(tray).getAllByText(subMenuTrigger2.textContent)[0];
850+
expect(menuHeader).toBeVisible();
851+
expect(menuHeader.tagName).toBe('SPAN');
852+
847853
for (let button of buttons) {
848854
if (button.getAttribute('aria-label') !== 'Dismiss') {
849-
expect(button).toHaveAttribute('aria-label', `Return to ${subMenuTrigger2.textContent}`);
855+
expect(button).toHaveAttribute('aria-label', 'Return to ');
856+
expect(button).toHaveAttribute('aria-labelledby', `${button.id} ${menuHeader.id}`);
850857
}
851858
}
852-
menuHeader = within(tray).getAllByText(subMenuTrigger2.textContent)[0];
853-
expect(menuHeader).toBeVisible();
854-
expect(menuHeader.tagName).toBe('SPAN');
855859
});
856860

857861
it('should provide a back button to close the submenu', async function () {
@@ -882,7 +886,7 @@ describe('SubMenu', function () {
882886
expect(menuItems[0]).toHaveTextContent('Lvl 3');
883887
let buttons = within(tray).getAllByRole('button');
884888
expect(buttons).toHaveLength(3);
885-
expect(buttons[1]).toHaveAttribute('aria-label', `Return to ${subMenuTrigger2.textContent}`);
889+
expect(buttons[1]).toHaveAttribute('aria-label', 'Return to ');
886890
triggerTouch(buttons[1]);
887891
act(() => {jest.runAllTimers();});
888892

@@ -893,7 +897,7 @@ describe('SubMenu', function () {
893897
expect(document.activeElement).toBe(subMenuTrigger2);
894898
buttons = within(tray).getAllByRole('button');
895899
expect(buttons).toHaveLength(3);
896-
expect(buttons[1]).toHaveAttribute('aria-label', `Return to ${subMenuTrigger1.textContent}`);
900+
expect(buttons[1]).toHaveAttribute('aria-label', 'Return to ');
897901
triggerTouch(buttons[1]);
898902
act(() => {jest.runAllTimers();});
899903

@@ -983,7 +987,7 @@ describe('SubMenu', function () {
983987
expect(document.activeElement).toBe(menuItems[0]);
984988

985989
await user.tab({shift: true});
986-
expect(document.activeElement).toHaveAttribute('aria-label', `Return to ${subMenuTrigger1.textContent}`);
990+
expect(document.activeElement).toHaveAttribute('aria-label', 'Return to ');
987991
await user.keyboard('[Enter]');
988992
act(() => {jest.runAllTimers();});
989993

0 commit comments

Comments
 (0)