-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplyStateChangeRequests.test.ts
More file actions
109 lines (100 loc) · 2.78 KB
/
Copy pathapplyStateChangeRequests.test.ts
File metadata and controls
109 lines (100 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { describe, it, expect } from "vitest";
import { type ContribPoint } from "@/lib/types/model/extension";
import { type StateChangeRequest } from "@/lib/types/model/callback";
import {
type ComponentState,
type PlotState,
} from "@/lib/types/state/component";
import { type ContributionState } from "@/lib/types/state/contribution";
import {
applyComponentStateChange,
applyContributionChangeRequests,
} from "./applyStateChangeRequests";
const componentTree: ComponentState = {
type: "Box",
id: "b1",
components: [
{ type: "Plot", id: "p1", chart: null } as PlotState,
{
type: "Box",
id: "b2",
components: [
{ type: "Checkbox", id: "cb1", value: true },
{ type: "Dropdown", id: "dd1", value: 13 },
],
},
],
};
describe("Test that applyContributionChangeRequests()", () => {
const contributionsRecord: Record<ContribPoint, ContributionState[]> = {
panels: [
{
name: "",
extension: "",
componentResult: { status: "ok" },
container: { visible: true },
component: componentTree,
},
],
};
const stateChangeRequest1: StateChangeRequest = {
contribPoint: "panels",
contribIndex: 0,
stateChanges: [
{
link: "component",
id: "dd1",
property: "value",
value: 14,
},
],
};
const stateChangeRequest2: StateChangeRequest = {
contribPoint: "panels",
contribIndex: 0,
stateChanges: [
{
link: "component",
id: "dd1",
property: "value",
value: 13,
},
],
};
it("changes state if values are different", () => {
const newState = applyContributionChangeRequests(contributionsRecord, [
stateChangeRequest1,
]);
expect(newState).not.toBe(contributionsRecord);
expect(
newState["panels"][0].component!.components![1].components![1].value,
).toEqual(14);
});
it("doesn't change the state if value stays the same", () => {
const newState = applyContributionChangeRequests(contributionsRecord, [
stateChangeRequest2,
]);
expect(newState).toBe(contributionsRecord);
});
});
describe("Test that applyComponentStateChange()", () => {
it("changes state if values are different", () => {
const newState = applyComponentStateChange(componentTree, {
link: "component",
id: "cb1",
property: "value",
value: false,
});
expect(newState).not.toBe(componentTree);
expect(newState.components![1].components![0].value).toEqual(false);
});
it("doesn't change the state if value stays the same", () => {
const newState = applyComponentStateChange(componentTree, {
link: "component",
id: "cb1",
property: "value",
value: true,
});
expect(newState).toBe(componentTree);
});
});