mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
Re-work toHierarchy
utility
Refactor `toHiearchy` to be more generic, performant - Use callback to "pick" generic parent ID property instead of requiring that `pid` be hardcoded` - Account for edge cases of an invalid parent ID - Use Map to store node children for lookups - Use one pass instead of removing empty nodes at the very end - DX: use generics to type `toHierarchy` - Make `toHierarchy` even more generic (reusable with `RecursiveList`) Co-Authored-By: Bram <bramhavers@gmail.com>
This commit is contained in:
parent
651779d602
commit
5f1e8de1e1
29 changed files with 414 additions and 273 deletions
|
@ -1,8 +1,14 @@
|
|||
import { render, screen } from "@testing-library/svelte";
|
||||
import { user } from "../setup-tests";
|
||||
import TreeViewHierarchy from "./TreeView.hierarchy.test.svelte";
|
||||
import TreeView from "./TreeView.test.svelte";
|
||||
|
||||
describe("TreeView", () => {
|
||||
const testCases = [
|
||||
{ name: "TreeView", component: TreeView },
|
||||
{ name: "TreeView hierarchy", component: TreeViewHierarchy },
|
||||
];
|
||||
|
||||
describe.each(testCases)("$name", ({ component }) => {
|
||||
const getItemByName = (name: RegExp) => {
|
||||
return screen.getByRole("treeitem", {
|
||||
name,
|
||||
|
@ -30,7 +36,7 @@ describe("TreeView", () => {
|
|||
it("can select a node", async () => {
|
||||
const consoleLog = vi.spyOn(console, "log");
|
||||
|
||||
render(TreeView);
|
||||
render(component);
|
||||
|
||||
const firstItem = getItemByName(/AI \/ Machine learning/);
|
||||
expect(firstItem).toBeInTheDocument();
|
||||
|
@ -49,7 +55,7 @@ describe("TreeView", () => {
|
|||
});
|
||||
|
||||
it("can expand all nodes", async () => {
|
||||
render(TreeView);
|
||||
render(component);
|
||||
|
||||
noExpandedItems();
|
||||
|
||||
|
@ -60,7 +66,7 @@ describe("TreeView", () => {
|
|||
});
|
||||
|
||||
it("can expand some nodes", async () => {
|
||||
render(TreeView);
|
||||
render(component);
|
||||
|
||||
noExpandedItems();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue