Files
privacy.sexy/tests/unit/shared/Stubs/TreeNodeStub.ts
undergroundwires 8f188acd3c Fix loss of tree node state when switching views
This commit fixes an issue where the check state of categories was lost
when toggling between card and tree views. This is solved by immediately
emitting node state changes for all nodes. This ensures consistent view
transitions without any loss of node state information.

Furthermore, this commit includes added unit tests for the modified code
sections.
2023-09-24 20:34:47 +02:00

47 lines
1.4 KiB
TypeScript

import { HierarchyAccess } from '@/presentation/components/Scripts/View/Tree/TreeView/Node/Hierarchy/HierarchyAccess';
import { TreeNodeStateAccess } from '@/presentation/components/Scripts/View/Tree/TreeView/Node/State/StateAccess';
import { TreeNode } from '@/presentation/components/Scripts/View/Tree/TreeView/Node/TreeNode';
import { NodeMetadataStub } from './NodeMetadataStub';
import { HierarchyAccessStub } from './HierarchyAccessStub';
import { TreeNodeStateAccessStub } from './TreeNodeStateAccessStub';
export class TreeNodeStub implements TreeNode {
public static fromStates(
states: readonly TreeNodeStateAccess[],
): TreeNodeStub[] {
return states.map(
(state) => new TreeNodeStub()
.withId(`[${TreeNodeStub.fromStates.name}] node-stub`)
.withState(state),
);
}
public state: TreeNodeStateAccess = new TreeNodeStateAccessStub();
public hierarchy: HierarchyAccess = new HierarchyAccessStub();
public id = 'tree-node-stub-id';
public metadata?: object = new NodeMetadataStub();
public withMetadata(metadata: object): this {
this.metadata = metadata;
return this;
}
public withHierarchy(hierarchy: HierarchyAccess): this {
this.hierarchy = hierarchy;
return this;
}
public withState(state: TreeNodeStateAccess): this {
this.state = state;
return this;
}
public withId(id: string): this {
this.id = id;
return this;
}
}