-
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.
fix(tree): fix item selection when multi + input-enabled (#2555)
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -187,6 +187,47 @@ describe("calcite-tree", () => { | |
expect(selectEventSpy).toHaveReceivedEventTimes(3); | ||
}); | ||
|
||
describe("has selected items in the selection event payload", () => | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jcfranco
Author
Member
|
||
it("contains current selection when selection=multi + input-enabled", async () => { | ||
const page = await newE2EPage({ | ||
html: html` <calcite-tree selection-mode="multi" input-enabled> | ||
<calcite-tree-item id="1">1</calcite-tree-item> | ||
<calcite-tree-item id="2">2</calcite-tree-item> | ||
</calcite-tree>` | ||
}); | ||
|
||
const [item1, item2] = await page.findAll("calcite-tree-item"); | ||
|
||
type TestWindow = { | ||
selectedIds: string[]; | ||
} & Window & | ||
typeof globalThis; | ||
|
||
await page.evaluateHandle(() => | ||
document.addEventListener("calciteTreeSelect", ({ detail }: CustomEvent) => { | ||
(window as TestWindow).selectedIds = detail.selected.map((item) => item.id); | ||
}) | ||
); | ||
|
||
const getSelectedIds = async (): Promise<any> => page.evaluate(() => (window as TestWindow).selectedIds); | ||
|
||
await item1.click(); | ||
|
||
expect(await getSelectedIds()).toEqual(["1"]); | ||
|
||
await item2.click(); | ||
|
||
expect(await getSelectedIds()).toEqual(["1", "2"]); | ||
|
||
await item2.click(); | ||
|
||
expect(await getSelectedIds()).toEqual(["1"]); | ||
|
||
await item1.click(); | ||
|
||
expect(await getSelectedIds()).toEqual([]); | ||
})); | ||
|
||
it("emits once when the tree item checkbox label is clicked", async () => { | ||
const page = await newE2EPage({ | ||
html: html`<calcite-tree input-enabled selection-mode="ancestors"> | ||
|
@jcfranco FYI this is throwing a test warning because
describe
can't return a value.I think this is why we should clean up our warnings in the build so we can spot these easier and prevent necessary fixes in the future.