-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stepper-item): emits calciteStepperItemSelect
event when selected.
#6521
Merged
anveshmekala
merged 5 commits into
master
from
anveshmekala/6330-add-stepper-item-select-event
Mar 3, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2e56612
feat(stepper-item): emit event when selection changes
anveshmekala 762a159
event no longer is emitted twice on select
anveshmekala 589b0f6
add e2e tests
anveshmekala 0d4219a
cleanup
anveshmekala cd2e24f
Merge branch 'master' into anveshmekala/6330-add-stepper-item-select-…
anveshmekala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍