Skip to content

Commit edbd9c5

Browse files
committed
test(mobile): cover repeated fold layout round trips
1 parent 1919262 commit edbd9c5

1 file changed

Lines changed: 34 additions & 33 deletions

File tree

‎apps/mobile/src/features/home/home-list-options.test.ts‎

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { act, createElement, useLayoutEffect } from "react";
33
import { createRoot, type Root } from "react-dom/client";
44
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
55

6-
import {
7-
HomeListOptionsProvider,
8-
useHomeListOptions,
9-
} from "./home-list-options";
6+
import { HomeListOptionsProvider, useHomeListOptions } from "./home-list-options";
107

118
describe("home list options across layout changes", () => {
129
const environmentId = EnvironmentId.make("environment-1");
@@ -61,34 +58,38 @@ describe("home list options across layout changes", () => {
6158
vi.unstubAllGlobals();
6259
});
6360

64-
it("retains filters in both directions and does not restore a cleared project", async () => {
65-
await showLayout("compact");
66-
await act(() => {
67-
latest.setSelectedEnvironmentId(environmentId);
68-
latest.setSelectedProjectKey("repository:one");
69-
latest.setProjectSortOrder("created_at");
70-
});
71-
72-
await showLayout("sidebar");
73-
expect(latest.options).toEqual({
74-
selectedEnvironmentId: environmentId,
75-
selectedProjectKey: "repository:one",
76-
projectSortOrder: "created_at",
77-
projectGroupingMode: "repository",
78-
});
61+
it.each([
62+
["compact", "sidebar"],
63+
["sidebar", "compact"],
64+
] as const)(
65+
"retains filters through repeated %s → %s round trips and keeps clears",
66+
async (initialLayout, otherLayout) => {
67+
await showLayout(initialLayout);
7968

80-
await act(() => latest.setSelectedProjectKey("repository:two"));
81-
await showLayout("compact");
82-
expect(latest.options.selectedProjectKey).toBe("repository:two");
83-
84-
await act(() => latest.setSelectedProjectKey(null));
85-
await showLayout("sidebar");
86-
await showLayout("compact");
87-
expect(latest.options).toEqual({
88-
selectedEnvironmentId: environmentId,
89-
selectedProjectKey: null,
90-
projectSortOrder: "created_at",
91-
projectGroupingMode: "repository",
92-
});
93-
});
69+
for (const [selectedEnvironmentId, selectedProjectKey] of [
70+
[environmentId, "repository:one"],
71+
[environmentId, "repository:two"],
72+
[environmentId, null],
73+
[null, null],
74+
[null, "repository:one"],
75+
] as const) {
76+
await act(() => {
77+
latest.setSelectedEnvironmentId(selectedEnvironmentId);
78+
latest.setSelectedProjectKey(selectedProjectKey);
79+
});
80+
for (let cycle = 0; cycle < 3; cycle += 1) {
81+
for (const layout of [otherLayout, initialLayout]) {
82+
await showLayout(layout);
83+
expect(latest.options).toMatchObject({
84+
selectedEnvironmentId,
85+
selectedProjectKey,
86+
projectGroupingMode: "repository",
87+
});
88+
}
89+
}
90+
// Make the next selection (or clear it) from the opposite layout.
91+
await showLayout(otherLayout);
92+
}
93+
},
94+
);
9495
});

0 commit comments

Comments
 (0)