Skip to content

Commit a1f3a88

Browse files
committed
🤖 fix: use aria-label to target experiment toggles in stories
Select switches by name instead of DOM order to prevent flaky tests when new switches are added to the Settings modal.
1 parent 9e6699e commit a1f3a88

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/browser/stories/App.settings.stories.tsx

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,9 @@ export const ExperimentsToggleOn: AppStory = {
186186
const modal = body.getByRole("dialog");
187187
const modalCanvas = within(modal);
188188

189-
// Find the switch by its role - experiments use role="switch"
190-
const switches = await modalCanvas.findAllByRole("switch");
191-
if (switches.length > 0) {
192-
// Toggle the first experiment on
193-
await userEvent.click(switches[0]);
194-
}
189+
// Find the experiment toggle by its aria-label (set in ExperimentsSection.tsx)
190+
const toggle = await modalCanvas.findByRole("switch", { name: /Post-Compaction Context/i });
191+
await userEvent.click(toggle);
195192
},
196193
};
197194

@@ -205,13 +202,10 @@ export const ExperimentsToggleOff: AppStory = {
205202
const modal = body.getByRole("dialog");
206203
const modalCanvas = within(modal);
207204

208-
// Find the switch
209-
const switches = await modalCanvas.findAllByRole("switch");
210-
if (switches.length > 0) {
211-
// Toggle on first
212-
await userEvent.click(switches[0]);
213-
// Then toggle off
214-
await userEvent.click(switches[0]);
215-
}
205+
// Find the experiment toggle by its aria-label (set in ExperimentsSection.tsx)
206+
const toggle = await modalCanvas.findByRole("switch", { name: /Post-Compaction Context/i });
207+
// Toggle on first, then toggle off
208+
await userEvent.click(toggle);
209+
await userEvent.click(toggle);
216210
},
217211
};

0 commit comments

Comments
 (0)