Skip to content

Commit e031bfd

Browse files
committed
test(onboarding): adds S5 BDD scenario, fixes review gaps
1 parent edc305b commit e031bfd

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

tests/acceptance/org-order-stability.feature

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ Feature: Freeze org display order in RepoSelector after initial sort
3232
When all orgs finish loading
3333
Then the org header order is "charlie", "acme-corp", "beta-org", "delta-inc"
3434

35-
# S5 DEFERRED until accordion layout merges from worktree-ux-improvements.
36-
# Without accordion, S5 duplicates S1's code path with more orgs.
37-
# Scenario: S5 - Org order stable in accordion layout after retry
38-
# Given the RepoSelector displays 7 orgs in accordion layout with "alice" first and "echo-labs" showing a Retry button
39-
# When the user clicks Retry on "echo-labs" and its repos load successfully
40-
# Then the org header order remains "alice", "acme-corp", "beta-org", "charlie-co", "delta-inc", "echo-labs", "foxtrot-io"
41-
# And the currently expanded accordion panel remains expanded
35+
Scenario: S5 - Org order stable in accordion layout after retry
36+
Given the RepoSelector displays 7 orgs in accordion layout with "alice" first and "echo-labs" showing a Retry button
37+
When the user clicks Retry on "echo-labs" and its repos load successfully
38+
Then the org header order remains "alice", "acme-corp", "beta-org", "charlie-co", "delta-inc", "echo-labs", "foxtrot-io"
39+
And the currently expanded accordion panel remains expanded
4240

4341
Scenario: S6 - New org appears in correct sorted position with 6+ orgs
4442
Given the RepoSelector displays 6 orgs all loaded and sorted with "alice" as the personal org

tests/acceptance/steps/org-order-stability.steps.tsx

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { vi, expect } from "vitest";
1+
import { vi, expect, afterAll } from "vitest";
22

33
// vitest-cucumber maps each Given/When/Then to a separate test(). The DOM must
44
// persist across steps within a scenario, but @solidjs/testing-library registers
@@ -39,6 +39,13 @@ import { render, screen, waitFor, fireEvent, cleanup } from "@solidjs/testing-li
3939

4040
const feature = await loadFeature("../org-order-stability.feature");
4141

42+
// STL_SKIP_AUTO_CLEANUP is file-scoped (Vitest isolates each file in its own
43+
// module context), but clean it up explicitly so the env doesn't leak if
44+
// Vitest's isolation model changes in future versions.
45+
afterAll(() => {
46+
delete process.env.STL_SKIP_AUTO_CLEANUP;
47+
});
48+
4249
// ── Org entry fixtures ────────────────────────────────────────────────────────
4350
const aliceEntry = { login: "alice", avatarUrl: "", type: "user" as const };
4451
const acmeEntry = { login: "acme-corp", avatarUrl: "", type: "org" as const };
@@ -58,8 +65,10 @@ function makeOrgRepos(org: string): RepoEntry[] {
5865
}
5966

6067
// ── Helper: flat (non-accordion) org header order ────────────────────────────
68+
// Org names follow GitHub's [A-Za-z0-9-] pattern — no regex escaping needed.
6169
function getOrgHeaderOrder(orgNames: string[]): string[] {
62-
const pattern = new RegExp(`^(${orgNames.join("|")})$`);
70+
const escaped = orgNames.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
71+
const pattern = new RegExp(`^(${escaped.join("|")})$`);
6372
return screen.getAllByText(pattern).map((el) => el.textContent!);
6473
}
6574

@@ -285,6 +294,79 @@ describeFeature(feature, ({ Scenario, Background, BeforeEachScenario, AfterEachS
285294
);
286295
});
287296

297+
// ── S5: Org order stable in accordion layout after retry ────────────────
298+
Scenario(
299+
"S5 - Org order stable in accordion layout after retry",
300+
({ Given, When, Then, And }) => {
301+
const sevenOrgs = ["alice", "acme-corp", "beta-org", "charlie-co", "delta-inc", "echo-labs", "foxtrot-io"];
302+
303+
Given(
304+
'the RepoSelector displays 7 orgs in accordion layout with "alice" first and "echo-labs" showing a Retry button',
305+
async () => {
306+
vi.mocked(api.fetchRepos).mockImplementation((_client, org) => {
307+
if (org === "echo-labs") return Promise.reject(new Error("echo load failed"));
308+
return Promise.resolve(makeOrgRepos(org as string));
309+
});
310+
311+
const sevenEntries = sevenOrgs.map((login) => ({
312+
login,
313+
avatarUrl: "",
314+
type: login === "alice" ? ("user" as const) : ("org" as const),
315+
}));
316+
317+
render(() => (
318+
<RepoSelector
319+
selectedOrgs={sevenOrgs}
320+
orgEntries={sevenEntries}
321+
selected={[]}
322+
onChange={vi.fn()}
323+
/>
324+
));
325+
326+
// Wait for accordion mode to render, expand echo-labs to show Retry
327+
await waitFor(() => {
328+
screen.getByRole("button", { name: /alice/ });
329+
});
330+
331+
const echoBtn = screen.getByRole("button", { name: /echo-labs/ });
332+
fireEvent.click(echoBtn);
333+
334+
await waitFor(() => {
335+
screen.getByText("Retry");
336+
});
337+
}
338+
);
339+
340+
When(
341+
'the user clicks Retry on "echo-labs" and its repos load successfully',
342+
async () => {
343+
vi.mocked(api.fetchRepos).mockImplementation((_client, org) =>
344+
Promise.resolve(makeOrgRepos(org as string))
345+
);
346+
347+
fireEvent.click(screen.getByText("Retry"));
348+
349+
await waitFor(() => {
350+
screen.getByText("echo-labs-repo");
351+
});
352+
}
353+
);
354+
355+
Then(
356+
'the org header order remains "alice", "acme-corp", "beta-org", "charlie-co", "delta-inc", "echo-labs", "foxtrot-io"',
357+
() => {
358+
const order = getAccordionOrder(sevenOrgs);
359+
expect(order).toEqual(sevenOrgs);
360+
}
361+
);
362+
363+
And("the currently expanded accordion panel remains expanded", () => {
364+
const echoBtn = screen.getByRole("button", { name: /echo-labs/ });
365+
expect(echoBtn.getAttribute("aria-expanded")).toBe("true");
366+
});
367+
}
368+
);
369+
288370
// ── S6: New org appears in correct sorted position with 6+ orgs ──────────
289371
Scenario(
290372
"S6 - New org appears in correct sorted position with 6+ orgs",

0 commit comments

Comments
 (0)