-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stepper-item): emits
calciteStepperItemSelect
event when selec…
…ted. (#6521) **Related Issue:** #6330 ## Summary This PR will add `calciteStepperItemSelect` event to `calcite-stepper-item` component . The event is emitted when the user select the header area.
- Loading branch information
1 parent
2ac969d
commit c349080
Showing
5 changed files
with
127 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,90 @@ | ||
import { newE2EPage } from "@stencil/core/testing"; | ||
import { html } from "../../../support/formatting"; | ||
import { disabled, renders, hidden } from "../../tests/commonTests"; | ||
import { clickStepperItemContent, getSelectedItemId, itemClicker } from "../stepper/utils"; | ||
|
||
describe("calcite-stepper-item", () => { | ||
it("renders", () => renders("calcite-stepper-item", { display: "flex" })); | ||
|
||
it("honors hidden attribute", async () => hidden("calcite-stepper-item")); | ||
|
||
it("can be disabled", () => disabled("calcite-stepper-item")); | ||
|
||
describe("should emit calciteStepperItemSelect on user interaction", () => { | ||
const stepperPage = html`<calcite-stepper> | ||
<calcite-stepper-item heading="Step 1" id="step-1"> | ||
<div>Step 1 content</div> | ||
</calcite-stepper-item> | ||
<calcite-stepper-item heading="Step 2" id="step-2"> | ||
<div>Step 2 content</div> | ||
</calcite-stepper-item> | ||
<calcite-stepper-item heading="Step 3" id="step-3" disabled> | ||
<div>Step 3 content</div> | ||
</calcite-stepper-item> | ||
<calcite-stepper-item heading="Step 4" id="step-4"> | ||
<div>Step 4 content</div> | ||
</calcite-stepper-item> | ||
</calcite-stepper>`; | ||
|
||
it("should emit calciteStepperItemSelect on mouse interaction", async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent(stepperPage); | ||
|
||
const item1 = await page.find("calcite-stepper-item#step-1"); | ||
expect(await item1.getProperty("selected")).toBe(true); | ||
expect(await getSelectedItemId(page)).toBe("step-1"); | ||
|
||
const item2 = await page.find("calcite-stepper-item#step-2"); | ||
const eventSpy = await item2.spyOnEvent("calciteStepperItemSelect"); | ||
item2.setProperty("selected", true); | ||
await page.waitForChanges(); | ||
expect(await getSelectedItemId(page)).toBe("step-2"); | ||
expect(eventSpy).toHaveReceivedEventTimes(1); | ||
|
||
await page.$eval("calcite-stepper-item#step-2", itemClicker); | ||
|
||
expect(await getSelectedItemId(page)).toBe("step-2"); | ||
expect(eventSpy).toHaveReceivedEventTimes(1); | ||
}); | ||
|
||
it("should emit calciteStepperItemSelect on keyboard interaction", async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent(stepperPage); | ||
|
||
const item1 = await page.find("calcite-stepper-item#step-1"); | ||
expect(await item1.getProperty("selected")).toBe(true); | ||
expect(await getSelectedItemId(page)).toBe("step-1"); | ||
|
||
const item4 = await page.find("calcite-stepper-item#step-4"); | ||
const eventSpy = await item4.spyOnEvent("calciteStepperItemSelect"); | ||
expect(eventSpy).toHaveReceivedEventTimes(0); | ||
|
||
await page.keyboard.press("Tab"); | ||
await page.waitForChanges(); | ||
await page.keyboard.press("Tab"); | ||
await page.waitForChanges(); | ||
await page.keyboard.press("Tab"); | ||
await page.waitForChanges(); | ||
await page.keyboard.press("Enter"); | ||
await page.waitForChanges(); | ||
expect(eventSpy).toHaveReceivedEventTimes(1); | ||
expect(await getSelectedItemId(page)).toBe("step-4"); | ||
expect(await item4.getProperty("selected")).toBe(true); | ||
expect(await item1.getProperty("selected")).toBe(false); | ||
}); | ||
|
||
it("should not emit calciteStepperItemSelect on user interaction with content", async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent(stepperPage); | ||
|
||
const item1 = await page.find("calcite-stepper-item#step-1"); | ||
expect(await item1.getProperty("selected")).toBe(true); | ||
|
||
const eventSpy = await item1.spyOnEvent("calciteStepperItemSelect"); | ||
expect(eventSpy).toHaveReceivedEventTimes(0); | ||
|
||
await clickStepperItemContent(page, "#step-1"); | ||
expect(eventSpy).toHaveReceivedEventTimes(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { E2EPage } from "@stencil/core/testing"; | ||
|
||
export const getItemPosition = ( | ||
stepperEl: HTMLCalciteStepperElement, | ||
stepperItemEl: HTMLCalciteStepperItemElement | ||
): number => { | ||
return Array.from(stepperEl.querySelectorAll("calcite-stepper-item")).indexOf(stepperItemEl); | ||
}; | ||
|
||
export const getSelectedItemId = async (page: E2EPage): Promise<string> => { | ||
return await page.evaluate((): string => { | ||
return document.querySelector("calcite-stepper")?.selectedItem?.id || ""; | ||
}); | ||
}; | ||
|
||
export const clickStepperItemContent = async (page: E2EPage, selector: string): Promise<void> => { | ||
await page.$eval(selector, (item: HTMLCalciteStepperItemElement) => | ||
item.shadowRoot.querySelector<HTMLElement>(".stepper-item-content").click() | ||
); | ||
}; | ||
|
||
// we use browser-context function to click on items to workaround `E2EElement#click` error | ||
export const itemClicker = async (item: HTMLCalciteStepperItemElement): Promise<void> => { | ||
item.click(); | ||
}; |