Skip to content

Commit 74fb516

Browse files
nickrolfeCopilot
andcommitted
Fix RepoRow checkbox lookup for vscode-elements 2.x
The vscode-checkbox host element no longer exposes a "checkbox" ARIA role in @vscode-elements/elements 2.x (the role now lives on an <input> inside its shadow DOM, which testing-library cannot reach). Find the checkbox by tag name instead, waiting for the disabled attribute that Lit reflects asynchronously. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f20698a7-f008-46a3-92a4-63037eb03a05
1 parent e5d0073 commit 74fb516

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

‎extensions/ql-vscode/src/view/variant-analysis/__tests__/RepoRow.spec.tsx‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { act, render as reactRender, screen } from "@testing-library/react";
1+
import {
2+
act,
3+
render as reactRender,
4+
screen,
5+
waitFor,
6+
} from "@testing-library/react";
27
import {
38
VariantAnalysisRepoStatus,
49
VariantAnalysisScannedRepositoryDownloadStatus,
@@ -24,6 +29,21 @@ describe(RepoRow.name, () => {
2429
);
2530
};
2631

32+
// The `vscode-checkbox` web component no longer exposes a `checkbox` ARIA role
33+
// on its host element (the role now lives on an <input> inside its shadow DOM,
34+
// which testing-library cannot reach), so find it by tag name instead. The
35+
// `disabled` property is reflected to a `disabled` attribute asynchronously by
36+
// Lit, so wait for the expected state.
37+
const findCheckbox = async (container: HTMLElement): Promise<HTMLElement> => {
38+
return waitFor(() => {
39+
const checkbox = container.querySelector("vscode-checkbox");
40+
if (!checkbox) {
41+
throw new Error("Unable to find a vscode-checkbox element");
42+
}
43+
return checkbox as HTMLElement;
44+
});
45+
};
46+
2747
it("renders the pending state", () => {
2848
render();
2949

@@ -394,38 +414,38 @@ describe(RepoRow.name, () => {
394414
});
395415

396416
it("does not allow selecting the item if the item has not succeeded", async () => {
397-
render({
417+
const { container } = render({
398418
status: VariantAnalysisRepoStatus.InProgress,
399419
});
400420

401-
const checkbox = await screen.findByRole("checkbox");
421+
const checkbox = await findCheckbox(container);
402422
expect(checkbox).toBeDisabled();
403423
});
404424

405425
it("does not allow selecting the item if the item has not been downloaded", async () => {
406-
render({
426+
const { container } = render({
407427
status: VariantAnalysisRepoStatus.Succeeded,
408428
});
409429

410-
const checkbox = await screen.findByRole("checkbox");
430+
const checkbox = await findCheckbox(container);
411431
expect(checkbox).toBeDisabled();
412432
});
413433

414434
it("does not allow selecting the item if the item has not been downloaded successfully", async () => {
415-
render({
435+
const { container } = render({
416436
status: VariantAnalysisRepoStatus.Succeeded,
417437
downloadState: {
418438
repositoryId: 1,
419439
downloadStatus: VariantAnalysisScannedRepositoryDownloadStatus.Failed,
420440
},
421441
});
422442

423-
const checkbox = await screen.findByRole("checkbox");
443+
const checkbox = await findCheckbox(container);
424444
expect(checkbox).toBeDisabled();
425445
});
426446

427447
it("allows selecting the item if the item has been downloaded", async () => {
428-
render({
448+
const { container } = render({
429449
status: VariantAnalysisRepoStatus.Succeeded,
430450
downloadState: {
431451
repositoryId: 1,
@@ -434,7 +454,7 @@ describe(RepoRow.name, () => {
434454
},
435455
});
436456

437-
const checkbox = await screen.findByRole("checkbox");
457+
const checkbox = await findCheckbox(container);
438458
expect(checkbox).toBeEnabled();
439459
});
440460
});

0 commit comments

Comments
 (0)