Skip to content

Commit 8d76f19

Browse files
committed
Tests: Make E2E tests close context menu when relevant
1 parent 41da2ab commit 8d76f19

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

test-storybooks/portable-stories-kitchen-sink/react/e2e-tests/component-testing.spec.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ test.describe("component testing", () => {
504504
.getByRole("button", { name: "test" });
505505
await expect(storyElement).toBeVisible({ timeout: 30000 });
506506

507-
// Act - Open sidebar context menu and start focused test
507+
// Act - Open sidebar context menu, start focused test then close menu
508508
await page
509509
.locator('[data-item-id="addons-group-test--expected-failure"]')
510510
.hover();
@@ -513,7 +513,7 @@ test.describe("component testing", () => {
513513
'[data-item-id="addons-group-test--expected-failure"] button[data-testid="context-menu"]'
514514
)
515515
.click();
516-
const sidebarContextMenu = page.getByTestId("tooltip");
516+
const sidebarContextMenu = page.getByRole('dialog');
517517
await sidebarContextMenu.getByLabel("Start test run").click();
518518

519519
// Assert - Only one test is running and reported
@@ -553,9 +553,17 @@ test.describe("component testing", () => {
553553
'[data-item-id="example-unhandlederrors"] button[data-testid="context-menu"]'
554554
)
555555
.click();
556-
const sidebarContextMenu = page.getByTestId("tooltip");
556+
const sidebarContextMenu = page.getByRole('dialog');
557557
await sidebarContextMenu.getByLabel("Start test run").click();
558558

559+
// HACK: the testing module popover has poor tracking of focus due to how many disabled
560+
// buttons it has and how deeply it changes its UI on events. This would be solved once
561+
// we move to a declarative menu, and there's an ongoing PR for that. Until then, we tab
562+
// around to reset focus.
563+
await page.keyboard.press('Tab');
564+
await page.keyboard.press('Escape');
565+
await expect(sidebarContextMenu).not.toBeVisible();
566+
559567
// Assert - Tests are running and errors are reported
560568
const errorLink = page.locator(
561569
"#storybook-testing-module #testing-module-description a"
@@ -600,9 +608,17 @@ test.describe("component testing", () => {
600608
'[data-item-id="addons-group-test"] button[data-testid="context-menu"]'
601609
)
602610
.click();
603-
const sidebarContextMenu = page.getByTestId("tooltip");
611+
const sidebarContextMenu = page.getByRole('dialog');
604612
await sidebarContextMenu.getByLabel("Start test run").click();
605613

614+
// HACK: the testing module popover has poor tracking of focus due to how many disabled
615+
// buttons it has and how deeply it changes its UI on events. This would be solved once
616+
// we move to a declarative menu, and there's an ongoing PR for that. Until then, we tab
617+
// around to reset focus.
618+
await page.keyboard.press('Tab');
619+
await page.keyboard.press('Escape');
620+
await expect(sidebarContextMenu).not.toBeVisible();
621+
606622
// Assert - Tests are running and reported
607623
await expect(
608624
sidebarContextMenu.locator("#testing-module-description")
@@ -648,9 +664,17 @@ test.describe("component testing", () => {
648664
'[data-item-id="addons-group"] button[data-testid="context-menu"]'
649665
)
650666
.click();
651-
const sidebarContextMenu = page.getByTestId("tooltip");
667+
const sidebarContextMenu = page.getByRole('dialog');
652668
await sidebarContextMenu.getByLabel("Start test run").click();
653669

670+
// HACK: the testing module popover has poor tracking of focus due to how many disabled
671+
// buttons it has and how deeply it changes its UI on events. This would be solved once
672+
// we move to a declarative menu, and there's an ongoing PR for that. Until then, we tab
673+
// around to reset focus.
674+
await page.keyboard.press('Tab');
675+
await page.keyboard.press('Escape');
676+
await expect(sidebarContextMenu).not.toBeVisible();
677+
654678
// Assert - Tests are running and reported
655679
await expect(
656680
sidebarContextMenu.locator("#testing-module-description")
@@ -706,9 +730,17 @@ test.describe("component testing", () => {
706730
'[data-item-id="example-button--csf-3-primary"] button[data-testid="context-menu"]'
707731
)
708732
.click();
709-
const sidebarContextMenu = page.getByTestId("tooltip");
733+
const sidebarContextMenu = page.getByRole('dialog');
710734
await sidebarContextMenu.getByLabel("Start test run").click();
711735

736+
// HACK: the testing module popover has poor tracking of focus due to how many disabled
737+
// buttons it has and how deeply it changes its UI on events. This would be solved once
738+
// we move to a declarative menu, and there's an ongoing PR for that. Until then, we tab
739+
// around to reset focus.
740+
await page.keyboard.press('Tab');
741+
await page.keyboard.press('Escape');
742+
await expect(sidebarContextMenu).not.toBeVisible();
743+
712744
// Arrange - Wait for test to finish and unfocus sidebar context menu
713745
await expect(
714746
sidebarContextMenu.locator("#testing-module-description")

0 commit comments

Comments
 (0)