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
19919eb6
41905810
+108
1 changed file
expand all
collapse all
unified
split
test
new
partial-reorder.browser.test.ts
+108
test/new/partial-reorder.browser.test.ts
···
1
1
+
import { test, expect } from "vitest"
2
2
+
import { morph } from "../../src/morphlex"
3
3
+
import { dom, observeMutations } from "./utils"
4
4
+
5
5
+
test("partial reorder at the befinning", () => {
6
6
+
const from = dom(`
7
7
+
<ul>
8
8
+
<li>1</li>
9
9
+
<li>2</li>
10
10
+
<li>3</li>
11
11
+
<li>4</li>
12
12
+
<li>5</li>
13
13
+
<li>6</li>
14
14
+
</ul>
15
15
+
`)
16
16
+
17
17
+
const to = dom(`
18
18
+
<ul>
19
19
+
<li>2</li>
20
20
+
<li>1</li>
21
21
+
<li>3</li>
22
22
+
<li>4</li>
23
23
+
<li>5</li>
24
24
+
<li>6</li>
25
25
+
</ul>
26
26
+
`)
27
27
+
28
28
+
const expected = to.outerHTML
29
29
+
30
30
+
const mutations = observeMutations(from, () => {
31
31
+
morph(from, to)
32
32
+
})
33
33
+
34
34
+
expect(from.outerHTML).toBe(expected)
35
35
+
36
36
+
expect(mutations.elementsRemoved).toBe(1)
37
37
+
expect(mutations.elementsAdded).toBe(1)
38
38
+
})
39
39
+
40
40
+
test("partial reorder at the end", () => {
41
41
+
const from = dom(`
42
42
+
<ul>
43
43
+
<li>1</li>
44
44
+
<li>2</li>
45
45
+
<li>3</li>
46
46
+
<li>4</li>
47
47
+
<li>5</li>
48
48
+
<li>6</li>
49
49
+
</ul>
50
50
+
`)
51
51
+
52
52
+
const to = dom(`
53
53
+
<ul>
54
54
+
<li>1</li>
55
55
+
<li>2</li>
56
56
+
<li>3</li>
57
57
+
<li>4</li>
58
58
+
<li>6</li>
59
59
+
<li>5</li>
60
60
+
</ul>
61
61
+
`)
62
62
+
63
63
+
const expected = to.outerHTML
64
64
+
65
65
+
const mutations = observeMutations(from, () => {
66
66
+
morph(from, to)
67
67
+
})
68
68
+
69
69
+
expect(from.outerHTML).toBe(expected)
70
70
+
71
71
+
expect(mutations.elementsRemoved).toBe(1)
72
72
+
expect(mutations.elementsAdded).toBe(1)
73
73
+
})
74
74
+
75
75
+
test("partial reorder in the middle", () => {
76
76
+
const from = dom(`
77
77
+
<ul>
78
78
+
<li>1</li>
79
79
+
<li>2</li>
80
80
+
<li>3</li>
81
81
+
<li>4</li>
82
82
+
<li>5</li>
83
83
+
<li>6</li>
84
84
+
</ul>
85
85
+
`)
86
86
+
87
87
+
const to = dom(`
88
88
+
<ul>
89
89
+
<li>1</li>
90
90
+
<li>2</li>
91
91
+
<li>4</li>
92
92
+
<li>3</li>
93
93
+
<li>5</li>
94
94
+
<li>6</li>
95
95
+
</ul>
96
96
+
`)
97
97
+
98
98
+
const expected = to.outerHTML
99
99
+
100
100
+
const mutations = observeMutations(from, () => {
101
101
+
morph(from, to)
102
102
+
})
103
103
+
104
104
+
expect(from.outerHTML).toBe(expected)
105
105
+
106
106
+
expect(mutations.elementsRemoved).toBe(1)
107
107
+
expect(mutations.elementsAdded).toBe(1)
108
108
+
})