Skip to content

Commit

Permalink
test(combobox): avoid emitting change event for value property update (
Browse files Browse the repository at this point in the history
…#11281)

**Related Issue:** #8970 

## Summary

Adds the following E2E tests for combobox:

- should not emit calciteComboboxChange event when value attribute is
updated
- should not emit calciteComboboxItemChange event when selected
attribute is toggled
  • Loading branch information
anveshmekala authored Jan 22, 2025
1 parent 943b66e commit 42ec590
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,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 @@ -2743,4 +2764,25 @@ describe("calcite-combobox", () => {

expect(await combobox.getProperty("value")).toBe("three");
});

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);
});
});

0 comments on commit 42ec590

Please sign in to comment.