Skip to content
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

test(combobox): avoid emitting change event for value property update #11281

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,27 @@ describe("calcite-combobox", () => {
expect(eventSpy).toHaveReceivedEventTimes(1);
expect((await element.getProperty("selectedItems")).length).toBe(2);
});

it("should not emit calciteComboboxChange event when value attribute is updated", async () => {
const page = await newE2EPage();
await page.setContent(
html`<calcite-combobox selection-mode="single">
<calcite-combobox-item id="one" value="one" text-label="one" selected></calcite-combobox-item>
<calcite-combobox-item id="two" value="two" text-label="two"></calcite-combobox-item>
<calcite-combobox-item id="three" value="three" text-label="three"></calcite-combobox-item>
</calcite-combobox>`,
);
await page.waitForChanges();

const eventSpy = await page.spyOnEvent("calciteComboboxChange");
const combobox = await page.find("calcite-combobox");
expect(await combobox.getProperty("value")).toBe("one");

combobox.setProperty("value", "two");
await page.waitForChanges();
expect(eventSpy).toHaveReceivedEventTimes(0);
expect(await combobox.getProperty("value")).toBe("two");
});
});

describe("calciteComboboxItemChange event correctly updates active item index", () => {
Expand Down Expand Up @@ -1945,6 +1966,27 @@ describe("calcite-combobox", () => {
await element.press("Tab");
expect(await page.evaluate(() => document.activeElement.id)).not.toBe("calcite-combobox");
});

it("should not emit calciteComboboxItemChange event when selected attribute is toggled", async () => {
const page = await newE2EPage();
await page.setContent(
html`<calcite-combobox selection-mode="single">
<calcite-combobox-item id="one" value="one" text-label="one" selected></calcite-combobox-item>
<calcite-combobox-item id="two" value="two" text-label="two"></calcite-combobox-item>
<calcite-combobox-item id="three" value="three" text-label="three"></calcite-combobox-item>
</calcite-combobox>`,
);
await page.waitForChanges();

const eventSpy = await page.spyOnEvent("calciteComboboxItemChange");
const two = await page.find("#two");
two.setProperty("selected", "true");
await page.waitForChanges();
expect(eventSpy).toHaveReceivedEventTimes(0);

const combobox = await page.find("calcite-combobox");
expect((await combobox.getProperty("selectedItems")).length).toBe(1);
});
});

describe("allows free entry of text", () => {
Expand Down
Loading