1
- import { nodeOps } from '../src/nodeOps'
1
+ import { nodeOps , svgNS } from '../src/nodeOps'
2
2
3
3
describe ( 'runtime-dom: node-ops' , ( ) => {
4
4
test ( 'the _value property should be cloned' , ( ) => {
@@ -25,4 +25,101 @@ describe('runtime-dom: node-ops', () => {
25
25
expect ( option1 . selected ) . toBe ( true )
26
26
expect ( option2 . selected ) . toBe ( true )
27
27
} )
28
+
29
+ describe ( 'insertStaticContent' , ( ) => {
30
+ test ( 'fresh insertion' , ( ) => {
31
+ const content = `<div>one</div><div>two</div>three`
32
+ const parent = document . createElement ( 'div' )
33
+ const [ first , last ] = nodeOps . insertStaticContent ! (
34
+ content ,
35
+ parent ,
36
+ null ,
37
+ false
38
+ )
39
+ expect ( parent . innerHTML ) . toBe ( content )
40
+ expect ( first ) . toBe ( parent . firstChild )
41
+ expect ( last ) . toBe ( parent . lastChild )
42
+ } )
43
+
44
+ test ( 'fresh insertion with anchor' , ( ) => {
45
+ const content = `<div>one</div><div>two</div>three`
46
+ const existing = `<div>existing</div>`
47
+ const parent = document . createElement ( 'div' )
48
+ parent . innerHTML = existing
49
+ const anchor = parent . firstChild
50
+ const [ first , last ] = nodeOps . insertStaticContent ! (
51
+ content ,
52
+ parent ,
53
+ anchor ,
54
+ false
55
+ )
56
+ expect ( parent . innerHTML ) . toBe ( content + existing )
57
+ expect ( first ) . toBe ( parent . firstChild )
58
+ expect ( last ) . toBe ( parent . childNodes [ parent . childNodes . length - 2 ] )
59
+ } )
60
+
61
+ test ( 'fresh insertion as svg' , ( ) => {
62
+ const content = `<text>hello</text><circle cx="100" cy="100" r="80"></circle>`
63
+ const parent = document . createElementNS ( svgNS , 'svg' )
64
+ const [ first , last ] = nodeOps . insertStaticContent ! (
65
+ content ,
66
+ parent ,
67
+ null ,
68
+ true
69
+ )
70
+ expect ( parent . innerHTML ) . toBe ( content )
71
+ expect ( first ) . toBe ( parent . firstChild )
72
+ expect ( last ) . toBe ( parent . lastChild )
73
+ expect ( first . namespaceURI ) . toMatch ( 'svg' )
74
+ expect ( last . namespaceURI ) . toMatch ( 'svg' )
75
+ } )
76
+
77
+ test ( 'fresh insertion as svg, with anchor' , ( ) => {
78
+ const content = `<text>hello</text><circle cx="100" cy="100" r="80"></circle>`
79
+ const existing = `<path></path>`
80
+ const parent = document . createElementNS ( svgNS , 'svg' )
81
+ parent . innerHTML = existing
82
+ const anchor = parent . firstChild
83
+ const [ first , last ] = nodeOps . insertStaticContent ! (
84
+ content ,
85
+ parent ,
86
+ anchor ,
87
+ true
88
+ )
89
+ expect ( parent . innerHTML ) . toBe ( content + existing )
90
+ expect ( first ) . toBe ( parent . firstChild )
91
+ expect ( last ) . toBe ( parent . childNodes [ parent . childNodes . length - 2 ] )
92
+ expect ( first . namespaceURI ) . toMatch ( 'svg' )
93
+ expect ( last . namespaceURI ) . toMatch ( 'svg' )
94
+ } )
95
+
96
+ test ( 'cached' , ( ) => {
97
+ const content = `<div>one</div><div>two</div>three`
98
+
99
+ const cacheParent = document . createElement ( 'div' )
100
+ const [ cachedFirst , cachedLast ] = nodeOps . insertStaticContent ! (
101
+ content ,
102
+ cacheParent ,
103
+ null ,
104
+ false
105
+ )
106
+
107
+ const parent = document . createElement ( 'div' )
108
+
109
+ const [ first , last ] = nodeOps . insertStaticContent ! (
110
+ `` ,
111
+ parent ,
112
+ null ,
113
+ false ,
114
+ [ cachedFirst , cachedLast ]
115
+ )
116
+
117
+ expect ( parent . innerHTML ) . toBe ( content )
118
+ expect ( first ) . toBe ( parent . firstChild )
119
+ expect ( last ) . toBe ( parent . lastChild )
120
+
121
+ expect ( first ) . not . toBe ( cachedFirst )
122
+ expect ( last ) . not . toBe ( cachedLast )
123
+ } )
124
+ } )
28
125
} )
0 commit comments