This commit applies `strictNullChecks` to the entire codebase to improve maintainability and type safety. Key changes include: - Remove some explicit null-checks where unnecessary. - Add necessary null-checks. - Refactor static factory functions for a more functional approach. - Improve some test names and contexts for better debugging. - Add unit tests for any additional logic introduced. - Refactor `createPositionFromRegexFullMatch` to its own function as the logic is reused. - Prefer `find` prefix on functions that may return `undefined` and `get` prefix for those that always return a value.
47 lines
1.4 KiB
TypeScript
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 | undefined): 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;
|
|
}
|
|
}
|