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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
import { beforeEach, describe, expect, test } from "vitest";
import { setupDOM } from "./utils.js";
import { morph } from "@root/src/vdom.ffi.mjs";
// built via npm script "build:test:vdom"
import {
disabled_attr_test,
dynamic_content_test,
fragment_test,
keyed_test,
smoke_test,
} from "../test-apps/vdom-test-templates/build/dev/javascript/app/client_test.mjs";
let appEl;
beforeEach(() => {
setupDOM();
appEl = document.getElementById("app");
});
// TEST ------------------------------------------------------------------------
const singleMorphSnapshot = (name, template) => {
appEl = morph(appEl, template);
const currentState = document.toString();
expect(currentState).toMatchSnapshot(name);
};
describe("vdom morph", () => {
test(`should render smoke test with vdom morph`, () => {
const template = smoke_test();
singleMorphSnapshot("smoke_test", template);
});
test(`should render using vdom morph with fragments`, () => {
const template = fragment_test();
singleMorphSnapshot("fragment_test", template);
});
test(`should render using vdom morph with keys`, () => {
const template = keyed_test();
singleMorphSnapshot("fragment_test", template);
});
test(`should be stable when vdom morph is called multiple times with no changes using fragment`, () => {
const template = fragment_test();
appEl = morph(appEl, template);
const initialState = document.toString();
const states = [];
for (let i = 0; i < 5; i++) {
appEl = morph(appEl, template);
states.push(document.toString());
}
states.forEach((state) => {
expect(state).toEqual(initialState);
});
});
test(`should be stable when vdom morph is called multiple times with no changes using keys`, () => {
const template = keyed_test();
appEl = morph(appEl, template);
const initialState = document.toString();
const states = [];
for (let i = 0; i < 5; i++) {
appEl = morph(appEl, template);
states.push(document.toString());
}
states.forEach((state) => {
expect(state).toEqual(initialState);
});
});
test(`should render updated templates`, () => {
const initialTemplate = dynamic_content_test(0, "initial_name");
appEl = morph(appEl, initialTemplate);
const initialState = document.toString();
expect(initialState).toContain("0");
expect(initialState).toContain("initial_name");
const updatedtemplate = dynamic_content_test(56, "updated_name");
appEl = morph(appEl, updatedtemplate);
const updatedState = document.toString();
expect(updatedState).toContain("56");
expect(updatedState).toContain("updated_name");
});
});
describe("vdom morph attribute", () => {
describe("disabled", () => {
test("should not be disabled when is_disabled is false", () => {
const template = disabled_attr_test(false);
appEl = morph(appEl, template);
const domResult = document.toString();
expect(domResult).toContain("input");
expect(domResult).not.toContain("disabled");
});
test("should be disabled when is_disabled is true", () => {
const template = disabled_attr_test(true);
appEl = morph(appEl, template);
const domResult = document.toString();
expect(domResult).toContain("input");
expect(domResult).toContain("disabled");
});
// this fails today
test.skip("should be stable when disabled attribute does not change", () => {
const template = disabled_attr_test(true);
appEl = morph(appEl, template);
const initialState = document.toString();
const states = [];
for (let i = 0; i < 5; i++) {
appEl = morph(appEl, template);
states.push(document.toString());
}
states.forEach((state) => {
expect(state).toEqual(initialState);
});
});
});
});
|