mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
add new test for placeholder noop
This commit is contained in:
parent
a3a576bd6d
commit
9ff8cb0292
@ -5,15 +5,13 @@ import { assert, test } from "vitest";
|
|||||||
import { newLayoutNode } from "../lib/layoutNode.js";
|
import { newLayoutNode } from "../lib/layoutNode.js";
|
||||||
import { layoutTreeStateReducer, newLayoutTreeState } from "../lib/layoutState.js";
|
import { layoutTreeStateReducer, newLayoutTreeState } from "../lib/layoutState.js";
|
||||||
import { LayoutTreeActionType, LayoutTreeComputeMoveNodeAction, LayoutTreeMoveNodeAction } from "../lib/model.js";
|
import { LayoutTreeActionType, LayoutTreeComputeMoveNodeAction, LayoutTreeMoveNodeAction } from "../lib/model.js";
|
||||||
import { DropDirection, FlexDirection } from "../lib/utils.js";
|
import { DropDirection } from "../lib/utils.js";
|
||||||
import { TestData } from "./model.js";
|
import { TestData } from "./model.js";
|
||||||
|
|
||||||
test("layoutTreeStateReducer - compute move", () => {
|
test("layoutTreeStateReducer - compute move", () => {
|
||||||
let treeState = newLayoutTreeState<TestData>(
|
let treeState = newLayoutTreeState<TestData>(newLayoutNode(undefined, undefined, undefined, { name: "root" }));
|
||||||
newLayoutNode(FlexDirection.Row, undefined, undefined, { name: "root" })
|
|
||||||
);
|
|
||||||
assert(treeState.rootNode.data!.name === "root", "root should have no children and should have data");
|
assert(treeState.rootNode.data!.name === "root", "root should have no children and should have data");
|
||||||
let node1 = newLayoutNode(FlexDirection.Column, undefined, undefined, { name: "node1" });
|
let node1 = newLayoutNode(undefined, undefined, undefined, { name: "node1" });
|
||||||
treeState = layoutTreeStateReducer(treeState, {
|
treeState = layoutTreeStateReducer(treeState, {
|
||||||
type: LayoutTreeActionType.ComputeMove,
|
type: LayoutTreeActionType.ComputeMove,
|
||||||
node: treeState.rootNode,
|
node: treeState.rootNode,
|
||||||
@ -34,7 +32,7 @@ test("layoutTreeStateReducer - compute move", () => {
|
|||||||
);
|
);
|
||||||
assert(treeState.rootNode.children![1].data!.name === "node1", "root's second child should be node1");
|
assert(treeState.rootNode.children![1].data!.name === "node1", "root's second child should be node1");
|
||||||
|
|
||||||
let node2 = newLayoutNode(FlexDirection.Column, undefined, undefined, { name: "node2" });
|
let node2 = newLayoutNode(undefined, undefined, undefined, { name: "node2" });
|
||||||
treeState = layoutTreeStateReducer(treeState, {
|
treeState = layoutTreeStateReducer(treeState, {
|
||||||
type: LayoutTreeActionType.ComputeMove,
|
type: LayoutTreeActionType.ComputeMove,
|
||||||
node: node1,
|
node: node1,
|
||||||
@ -55,3 +53,37 @@ test("layoutTreeStateReducer - compute move", () => {
|
|||||||
);
|
);
|
||||||
assert(treeState.rootNode.children![1].children!.length === 2, "root's second child should now have two children");
|
assert(treeState.rootNode.children![1].children!.length === 2, "root's second child should now have two children");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("computeMove - noop action", () => {
|
||||||
|
let nodeToMove = newLayoutNode<TestData>(undefined, undefined, undefined, { name: "nodeToMove" });
|
||||||
|
let treeState = newLayoutTreeState<TestData>(
|
||||||
|
newLayoutNode(undefined, undefined, [
|
||||||
|
nodeToMove,
|
||||||
|
newLayoutNode<TestData>(undefined, undefined, undefined, { name: "otherNode" }),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
let moveAction: LayoutTreeComputeMoveNodeAction<TestData> = {
|
||||||
|
type: LayoutTreeActionType.ComputeMove,
|
||||||
|
node: treeState.rootNode,
|
||||||
|
nodeToMove,
|
||||||
|
direction: DropDirection.Left,
|
||||||
|
};
|
||||||
|
treeState = layoutTreeStateReducer(treeState, moveAction);
|
||||||
|
assert(
|
||||||
|
treeState.pendingAction === undefined,
|
||||||
|
"inserting a node to the left of itself should not produce a pendingAction"
|
||||||
|
);
|
||||||
|
|
||||||
|
moveAction = {
|
||||||
|
type: LayoutTreeActionType.ComputeMove,
|
||||||
|
node: treeState.rootNode,
|
||||||
|
nodeToMove,
|
||||||
|
direction: DropDirection.Right,
|
||||||
|
};
|
||||||
|
|
||||||
|
treeState = layoutTreeStateReducer(treeState, moveAction);
|
||||||
|
assert(
|
||||||
|
treeState.pendingAction === undefined,
|
||||||
|
"inserting a node to the right of itself should not produce a pendingAction"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user