Skip to content

Commit

Permalink
test(commonTests): restore disabled focus target testing for non-"non…
Browse files Browse the repository at this point in the history
…e" focus targets (#7235)

**Related Issue:** N/A

## Summary

Restores [assertions for tab/mouse focusing on disabled
components](https://github.com/Esri/calcite-components/blame/6777b06c5dbad5441ed651d676cd9562d79e6986/packages/calcite-components/src/tests/commonTests.ts#L1044-L1064)
removed in the [`disabled` test helper
refactor](#7089).
  • Loading branch information
jcfranco authored and benelan committed Jun 28, 2023
1 parent 2fc7b5d commit 3baf1d5
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions packages/calcite-components/src/tests/commonTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,14 +972,18 @@ export function disabled(
return focusTarget === "host" ? tag : await page.evaluate(() => document.activeElement?.tagName.toLowerCase());
}

const getTabAndClickFocusTarget = async (page: E2EPage, tag: string): Promise<string[]> => {
const focusTarget = options.focusTarget;
const focusTargetString = await getFocusTarget(page, tag, focusTarget as FocusTarget);
const getTabAndClickFocusTarget = async (
page: E2EPage,
tag: string,
focusTarget: DisabledOptions["focusTarget"]
): Promise<string[]> => {
if (typeof focusTarget === "object") {
return [focusTarget.tab, focusTarget.click];
}

const [tabFocusTarget, clickFocusTarget] =
typeof focusTarget === "object" ? [focusTarget.tab, focusTarget.click] : [focusTargetString, focusTargetString];
const sameClickAndTabFocusTarget = await getFocusTarget(page, tag, focusTarget);

return [tabFocusTarget, clickFocusTarget];
return [sameClickAndTabFocusTarget, sameClickAndTabFocusTarget];
};

const getShadowFocusableCenterCoordinates = async (page: E2EPage, tabFocusTarget: string): Promise<number[]> => {
Expand Down Expand Up @@ -1028,7 +1032,7 @@ export function disabled(

await page.keyboard.press("Tab");

const [tabFocusTarget, clickFocusTarget] = await getTabAndClickFocusTarget(page, tag);
const [tabFocusTarget, clickFocusTarget] = await getTabAndClickFocusTarget(page, tag, options.focusTarget);

expect(tabFocusTarget).not.toBe("body");
await expectToBeFocused(page, tabFocusTarget);
Expand Down Expand Up @@ -1061,6 +1065,28 @@ export function disabled(
expect(spy).toHaveReceivedEventTimes(1);
}
});

component.setProperty("disabled", true);
await page.waitForChanges();

expect(component.getAttribute("aria-disabled")).toBe("true");

await resetFocusOrder();
await page.keyboard.press("Tab");
await expectToBeFocused(page, "body");

await page.mouse.click(shadowFocusableCenterX, shadowFocusableCenterY);
await expectToBeFocused(page, "body");

assertOnMouseAndPointerEvents(eventSpies, (spy) => {
if (spy.eventName === "click") {
// some components emit more than one click event (e.g., from calling `click()`),
// so we check if at least one event is received
expect(spy.length).toBeGreaterThanOrEqual(2);
} else {
expect(spy).toHaveReceivedEventTimes(eventsExpectedToBubble.includes(spy.eventName) ? 2 : 1);
}
});
});

it("events are no longer blocked right after enabling", async () => {
Expand Down

0 comments on commit 3baf1d5

Please sign in to comment.