Hi,
I need to feed mock data into my treeview component for performance testing.
My treeview expects a FLAT item list - Item[]
- where Item
is a TypeScript interface
interface Item {
name: string;
id: string;
parentID?: string;
}
Now, how do I randomly create a data set where the parentID
will be using a random ID from within the same set AND no circular dependency be created (an item should not have a parentID
referring to one of its descendants’ id
).
So for example this should not be allowed:
[
{name: 'ABC', id: 'abc', parentID: 'def'},
{name: 'DEF', id: 'def', parentID: 'abc'},
{name: 'ROOT', id: 'root'},
]
Please note that I am use the term data set in a general meaning, not necessarily matching the mockaroo concept of dataset.