tangled
alpha
login
or
join now
yippee.fun
/
morphlex
0
fork
atom
Precise DOM morphing
morphing
typescript
dom
0
fork
atom
overview
issues
pulls
pipelines
More tests
joel.drapper.me
4 months ago
ece220c3
a0abbba9
+46
-5
3 changed files
expand all
collapse all
unified
split
src
morphlex.ts
test
new
document.test.ts
inputs.browser.test.ts
+2
-2
src/morphlex.ts
···
166
166
167
167
function flagDirtyInputs(node: ParentNode): void {
168
168
for (const input of node.querySelectorAll("input")) {
169
169
-
if (input.name === "") continue
169
169
+
if (!input.name) continue
170
170
171
171
if (input.value !== input.defaultValue) {
172
172
input.setAttribute("morphlex-dirty", "")
···
178
178
}
179
179
180
180
for (const element of node.querySelectorAll("option")) {
181
181
-
if (element.value === "") continue
181
181
+
if (!element.value) continue
182
182
183
183
if (element.selected !== element.defaultSelected) {
184
184
element.setAttribute("morphlex-dirty", "")
+3
-3
test/new/document.ts
test/new/document.test.ts
···
33
33
`,
34
34
)
35
35
36
36
-
expect(document.title).toBe("New Title")
37
37
-
expect(document.querySelector('meta[name="description"]')?.getAttribute("content")).toBe("new")
38
38
-
expect(document.querySelector("#content")?.textContent).toBe("New Content")
36
36
+
expect(originalDocument.querySelector("title")?.textContent).toBe("New Title")
37
37
+
expect(originalDocument.querySelector('meta[name="description"]')?.getAttribute("content")).toBe("new")
38
38
+
expect(originalDocument.querySelector("#content")?.textContent).toBe("New Content")
39
39
})
+41
test/new/inputs.browser.test.ts
···
69
69
expect(a.checked).toBe(true)
70
70
})
71
71
72
72
+
test("morphing an unmodified checkbox checked with preserveChanges enabled", () => {
73
73
+
const a = dom(`<input type="checkbox" checked>`) as HTMLInputElement
74
74
+
const b = dom(`<input type="checkbox">`) as HTMLInputElement
75
75
+
76
76
+
morph(a, b, { preserveChanges: true })
77
77
+
78
78
+
expect(a.hasAttribute("checked")).toBe(false)
79
79
+
expect(a.checked).toBe(false)
80
80
+
})
81
81
+
72
82
test("morphing a modified checkbox unchecked with preserveChanges enabled", () => {
73
83
const a = dom(`<input type="checkbox" checked>`) as HTMLInputElement
74
84
const b = dom(`<input type="checkbox">`) as HTMLInputElement
···
150
160
expect(a.options[1].hasAttribute("selected")).toBe(false)
151
161
expect(a.value).toBe("a")
152
162
expect(a.options[0].selected).toBe(true)
163
163
+
})
164
164
+
165
165
+
test("morphing a select option with no value", () => {
166
166
+
const a = dom(
167
167
+
`
168
168
+
<select>
169
169
+
<option></option>
170
170
+
<option></option>
171
171
+
</select>
172
172
+
`,
173
173
+
)
174
174
+
175
175
+
const b = dom(
176
176
+
`
177
177
+
<select>
178
178
+
<option value="1">A</option>
179
179
+
<option value="2">B</option>
180
180
+
</select>
181
181
+
`,
182
182
+
)
183
183
+
184
184
+
morph(a, b)
185
185
+
186
186
+
expect(a.outerHTML).toBe(
187
187
+
`
188
188
+
<select>
189
189
+
<option value="1">A</option>
190
190
+
<option value="2">B</option>
191
191
+
</select>
192
192
+
`.trim(),
193
193
+
)
153
194
})
154
195
})
155
196