Skip to content

Commit 548f661

Browse files
test(dashboard): Pick e2e options through pickOption (#3925)
A list that closes on a pick, such as a select, a search, or the command palette, closes with a transition. If a press on another control lands before that transition ends, it can be lost. That race made the snooze specs flaky (#3918). This turns that fix into a shared rule. `pickOption(option)` in `e2e/pick-option.ts` clicks the option and waits for it to hide. The ast-grep rule `e2e-option-click-through-pick-option` makes dashboard e2e specs pick options only through it, and its autofix rewrites a raw option click. Every option pick in the specs now uses the helper. That includes the search pick in `inbox-snoozes.spec.ts`, which is followed at once by a click on the Event select: the same race. The rule can't see an option locator that is held in a variable, so I converted those calls by hand. <!-- junior-request-attribution:start --> via @dcramer. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CHB3YHES2%3A1795218787.096889 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CHB3YHES2%3A1795218787.096889) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CHB3YHES2%3A1795218787.096889/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: David Cramer <[email protected]>
1 parent 7c11f1d commit 548f661

13 files changed

Lines changed: 89 additions & 35 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
id: e2e-option-click-through-pick-option
2+
language: TypeScript
3+
severity: error
4+
message: "Pick a dashboard e2e option with pickOption from packages/junior-dashboard/e2e/pick-option.ts, not with a raw click. pickOption waits for the list to close. A list closes with a transition, and a press on another control before it ends can be lost, which makes the test flaky."
5+
files:
6+
- packages/junior-dashboard/e2e/**/*.ts
7+
rule:
8+
pattern: $OPTION.click($$$)
9+
constraints:
10+
OPTION:
11+
any:
12+
- matches: option-locator
13+
- has:
14+
stopBy: end
15+
matches: option-locator
16+
utils:
17+
option-locator:
18+
any:
19+
- pattern: $LIST.getByRole("option")
20+
- pattern: $LIST.getByRole("option", $$$)
21+
fix: pickOption($OPTION)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
id: e2e-option-click-through-pick-option
2+
valid:
3+
- 'await pickOption(page.getByRole("option", { name: "Private" }));'
4+
- 'await page.getByRole("button", { name: "Snooze" }).click();'
5+
- 'await expect(page.getByRole("option")).toHaveCount(0);'
6+
invalid:
7+
- 'await page.getByRole("option", { name: "Private" }).click();'
8+
- 'await files.getByRole("option").click();'
9+
- 'await palette.getByRole("option", { name: /Send/ }).first().click();'
10+
- "await page\n .getByRole(\"option\", { name: /Archived/ })\n .click();"

‎packages/junior-dashboard/e2e/composer-references.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Page } from "@playwright/test";
22

33
import { expect, test } from "./test";
4+
import { pickOption } from "./pick-option";
45

56
// A Thread the viewer takes part in. It has a nested Thread and two files.
67
const THREAD_ID = "junior:internal:dashboard-qa:thread";
@@ -83,7 +84,7 @@ test("@ finds Conversations, Tasks and files, and links the work it sends", asyn
8384
const files = mentions.getByRole("group", { name: "Files" });
8485
await expect(files.getByRole("option")).toHaveText([/pinned-rows\.txt/]);
8586
await expect(mentions).not.toHaveAttribute("aria-busy", "true");
86-
await files.getByRole("option").click();
87+
await pickOption(files.getByRole("option"));
8788
await expect(composer.locator("[data-reference='file']")).toHaveText(
8889
"pinned-rows.txt",
8990
);

‎packages/junior-dashboard/e2e/conversation-archive.spec.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { viewAsParticipant } from "./conversationMenu";
22
import { expect, test } from "./test";
3+
import { pickOption } from "./pick-option";
34

45
// Only participants can archive or restore.
56
test.beforeEach(async ({ page }) => viewAsParticipant(page));
@@ -18,9 +19,9 @@ test("finds an old archived conversation by title and restores it", async ({
1819
await page.keyboard.press("ControlOrMeta+k");
1920
const palette = page.getByRole("dialog", { name: "Go to conversation" });
2021
await palette.getByRole("combobox").fill("archived restore");
21-
await palette
22-
.getByRole("option", { name: /Archived restore target.*Archived/ })
23-
.click();
22+
await pickOption(
23+
palette.getByRole("option", { name: /Archived restore target.*Archived/ }),
24+
);
2425
await expect(
2526
page.getByRole("heading", { name: "Archived restore target" }),
2627
).toBeVisible();

‎packages/junior-dashboard/e2e/conversation-send.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { expect, test } from "./test";
1313
import { routeConversationVersion, withRequestedMailbox } from "./harness";
1414
import { screenshot } from "./screenshot";
1515
import { mockChartPng } from "../src/mock-reporting/chart-png";
16+
import { pickOption } from "./pick-option";
1617

1718
test("starts and continues conversations from the dashboard", async ({
1819
page,
@@ -111,7 +112,7 @@ test("starts and continues conversations from the dashboard", async ({
111112
page.getByRole("heading", { name: "What do you need?" }),
112113
).toBeVisible();
113114
await page.getByRole("combobox", { name: "Conversation visibility" }).click();
114-
await page.getByRole("option", { name: "Private" }).click();
115+
await pickOption(page.getByRole("option", { name: "Private" }));
115116
const startComposer = page.getByLabel("Start a conversation");
116117
const imageBase64 = mockChartPng.toString("base64");
117118
// Any file type goes. A file over the per-file cap does not. Build large

‎packages/junior-dashboard/e2e/inbox/command-palette.spec.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mockLandingAutomationApis } from "../automation-landing-fixture";
55
import { expandRow, mockReviewItems, rollout, rowHead } from "./inbox-fixture";
66
import { expect, test } from "../test";
77
import { mobile, screenshot } from "../screenshot";
8+
import { pickOption } from "../pick-option";
89

910
// Only the inbox project runs `@new` tests.
1011
test.describe("new UI", { tag: "@new" }, () => {
@@ -314,7 +315,7 @@ test.describe("new UI", { tag: "@new" }, () => {
314315
await page.setViewportSize(mobile);
315316
await page.keyboard.press("ControlOrMeta+k");
316317
await palette.getByRole("combobox").fill("feedback");
317-
await palette.getByRole("option", { name: "Send feedback" }).click();
318+
await pickOption(palette.getByRole("option", { name: "Send feedback" }));
318319
await expect(dialog).toBeVisible();
319320
});
320321

@@ -355,7 +356,7 @@ test.describe("new UI", { tag: "@new" }, () => {
355356
const inbox = palette.getByRole("group", { exact: true, name: "Inbox" });
356357
const match = inbox.getByRole("option").first();
357358
await expect(match).toHaveAccessibleName(new RegExp(rollout.title));
358-
await match.click();
359+
await pickOption(match);
359360
await expect(page).toHaveURL(/\/\?view=inbox$/);
360361
await expect(
361362
// In its stack, the item's own row opens, under its question.
@@ -384,10 +385,11 @@ test.describe("new UI", { tag: "@new" }, () => {
384385
const palette = page.getByRole("dialog", { name: "Go to conversation" });
385386
await page.keyboard.press("ControlOrMeta+k");
386387
await palette.getByRole("combobox").fill("canary error");
387-
await palette
388-
.getByRole("group", { exact: true, name: "Inbox" })
389-
.getByRole("option", { name: new RegExp(rollout.title) })
390-
.click();
388+
await pickOption(
389+
palette
390+
.getByRole("group", { exact: true, name: "Inbox" })
391+
.getByRole("option", { name: new RegExp(rollout.title) }),
392+
);
391393
await expect(page).toHaveURL(/\/\?view=snoozed$/);
392394
const asks = page.getByRole("region", { name: /: asks$/ });
393395
await expect(
@@ -483,7 +485,7 @@ test.describe("new UI", { tag: "@new" }, () => {
483485
await expect(groups.nth(1)).toHaveAccessibleName("Done");
484486
const closed = groups.nth(1).getByRole("option").first();
485487
await expect(closed).toHaveAccessibleName(/initech license entry/);
486-
await closed.click();
488+
await pickOption(closed);
487489
// Done opens with the item's row expanded.
488490
await expect(page).toHaveURL(/\/\?view=done$/);
489491
await expect(
@@ -608,7 +610,7 @@ test.describe("new UI", { tag: "@new" }, () => {
608610
await expect(match).toHaveAccessibleName(/Deploy the payments service/);
609611
expect(queries).toContain("deploy");
610612

611-
await match.click();
613+
await pickOption(match);
612614
await expect(page).toHaveURL(
613615
`${dashboard.baseURL}/plugins/fixture/checklists#record-checklist-21`,
614616
);

‎packages/junior-dashboard/e2e/inbox/conversation-archive.spec.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { viewAsParticipant } from "./conversationMenu";
22
import type { Locator } from "@playwright/test";
33
import { openRow } from "./inbox-fixture";
44
import { expect, test } from "../test";
5+
import { pickOption } from "../pick-option";
56

67
/**
78
* Rest the pointer on an Inbox row's head until the row stops moving, so
@@ -58,9 +59,11 @@ test.describe("new UI", { tag: "@new" }, () => {
5859
await page.keyboard.press("ControlOrMeta+k");
5960
const palette = page.getByRole("dialog", { name: "Go to conversation" });
6061
await palette.getByRole("combobox").fill("archived restore");
61-
await palette
62-
.getByRole("option", { name: /Archived restore target.*Archived/ })
63-
.click();
62+
await pickOption(
63+
palette.getByRole("option", {
64+
name: /Archived restore target.*Archived/,
65+
}),
66+
);
6467
await expect(
6568
page.getByRole("heading", { name: "Archived restore target" }),
6669
).toBeVisible();

‎packages/junior-dashboard/e2e/inbox/conversations-event-log.spec.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
routeConversationVersion,
99
withRequestedMailbox,
1010
} from "../harness";
11+
import { pickOption } from "../pick-option";
1112

1213
// Only the inbox project runs `@new` tests.
1314
test.describe("new UI", { tag: "@new" }, () => {
@@ -338,7 +339,7 @@ test.describe("new UI", { tag: "@new" }, () => {
338339
const events = palette.getByRole("group").first();
339340
await expect(events).toHaveAccessibleName("Events");
340341
await expect(events.getByRole("option")).toHaveCount(1);
341-
await events.getByRole("option").click();
342+
await pickOption(events.getByRole("option"));
342343
await expect(page).toHaveURL(/[?&]event=2(&|$)/);
343344
await expect(
344345
log.getByRole("button", { name: "Event 2: turn_context", exact: true }),
@@ -639,10 +640,9 @@ test.describe("new UI", { tag: "@new" }, () => {
639640
await page.keyboard.press("ControlOrMeta+k");
640641
const palette = page.getByRole("dialog", { name: "Go to conversation" });
641642
await palette.getByRole("combobox").fill("row 1234.");
642-
await palette
643-
.getByRole("group", { name: "Events" })
644-
.getByRole("option")
645-
.click();
643+
await pickOption(
644+
palette.getByRole("group", { name: "Events" }).getByRole("option"),
645+
);
646646
await expect(entry(1234)).toBeInViewport();
647647
await expect(entry(1234)).toHaveAttribute("aria-expanded", "true");
648648
});

‎packages/junior-dashboard/e2e/inbox/inbox-navigation.spec.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "./inbox-fixture";
1010
import { screenshot } from "../screenshot";
1111
import { expect, test } from "../test";
12+
import { pickOption } from "../pick-option";
1213

1314
// Only the inbox project runs `@new` tests.
1415
test.describe("new UI", { tag: "@new" }, () => {
@@ -672,10 +673,11 @@ test.describe("new UI", { tag: "@new" }, () => {
672673
await expect(composer).toBeFocused();
673674
await page.goto(`${dashboard.baseURL}/settings`);
674675
await page.keyboard.press("ControlOrMeta+k");
675-
await page
676-
.getByRole("dialog", { name: "Go to conversation" })
677-
.getByRole("option", { name: "New conversation" })
678-
.click();
676+
await pickOption(
677+
page
678+
.getByRole("dialog", { name: "Go to conversation" })
679+
.getByRole("option", { name: "New conversation" }),
680+
);
679681
await expect(page).toHaveURL(/\/conversations\/new$/);
680682
await expect(composer).toBeFocused();
681683
});

‎packages/junior-dashboard/e2e/inbox/inbox-snoozes.spec.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { automationReport } from "./automation-fixture";
1818
import { mobile, screenshot } from "../screenshot";
1919
import { expect, test } from "../test";
20+
import { pickOption } from "../pick-option";
2021

2122
// The open row. Every row has its own quick Snooze, so scope to this one.
2223
const openRowOf = (page: Page) =>
@@ -32,11 +33,7 @@ async function pickEvent(page: Page, index: number, phrase: string) {
3233
.getByRole("combobox", { name: "Event" })
3334
.nth(index)
3435
.click();
35-
const option = page.getByRole("option", { exact: true, name: phrase });
36-
await option.click();
37-
// The options close with a transition. A press on the next Event select
38-
// before it ends does not open that select.
39-
await expect(option).toBeHidden();
36+
await pickOption(page.getByRole("option", { exact: true, name: phrase }));
4037
}
4138

4239
// The next snooze that the page saves.
@@ -494,7 +491,7 @@ test.describe("new UI", { tag: "@new" }, () => {
494491
lightTheme: true,
495492
view: "desktop",
496493
});
497-
await found.click();
494+
await pickOption(found);
498495
await pickEvent(page, 0, "is merged");
499496
await expect(
500497
dialog.getByRole("group", {
@@ -550,13 +547,15 @@ test.describe("new UI", { tag: "@new" }, () => {
550547
await page
551548
.getByPlaceholder("Search pull requests or paste a link")
552549
.fill(issue);
553-
await page.getByRole("option", { name: issue }).click();
550+
await pickOption(page.getByRole("option", { name: issue }));
554551
// The second condition offers the issue's Events.
555552
await dialog.getByRole("combobox", { name: "Event" }).nth(1).click();
556553
await expect(
557554
page.getByRole("option", { exact: true, name: "is merged" }),
558555
).toHaveCount(0);
559-
await page.getByRole("option", { exact: true, name: "is closed" }).click();
556+
await pickOption(
557+
page.getByRole("option", { exact: true, name: "is closed" }),
558+
);
560559
await expect(
561560
dialog.getByRole("group", { name: "When the issue is closed" }),
562561
).toBeVisible();
@@ -603,7 +602,7 @@ test.describe("new UI", { tag: "@new" }, () => {
603602
// The mock viewer cannot see this repository.
604603
const hidden = "https://github.com/acme/private/pull/1";
605604
await search.fill(hidden);
606-
await page.getByRole("option", { name: hidden }).click();
605+
await pickOption(page.getByRole("option", { name: hidden }));
607606
await expect(
608607
dialog.getByText("You cannot snooze on this link."),
609608
).toBeVisible();

0 commit comments

Comments
 (0)