1
1
import global from '../../../../src/shim/global' ;
2
- const { it } = intern . getInterface ( 'bdd' ) ;
2
+ const { it, beforeEach } = intern . getInterface ( 'bdd' ) ;
3
3
const { describe : jsdomDescribe } = intern . getPlugin ( 'jsdom' ) ;
4
4
const { assert } = intern . getPlugin ( 'chai' ) ;
5
- import { sandbox } from 'sinon' ;
5
+ import { stub } from 'sinon' ;
6
6
7
+ import icacheMiddleware from '../../../../src/core/middleware/icache' ;
7
8
import inertMiddleware from '../../../../src/core/middleware/inert' ;
8
9
9
- const sb = sandbox . create ( ) ;
10
+ let invalidatorStub = stub ( ) ;
10
11
11
12
jsdomDescribe ( 'inert middleware' , ( ) => {
13
+ let icache = icacheMiddleware ( ) . callback ( {
14
+ properties : ( ) => ( { } ) ,
15
+ children : ( ) => [ ] ,
16
+ id : 'test-cache' ,
17
+ middleware : { invalidator : invalidatorStub , destroy : stub ( ) }
18
+ } ) ;
19
+ beforeEach ( ( ) => {
20
+ icache = icacheMiddleware ( ) . callback ( {
21
+ properties : ( ) => ( { } ) ,
22
+ children : ( ) => [ ] ,
23
+ id : 'test-cache' ,
24
+ middleware : { invalidator : invalidatorStub , destroy : stub ( ) }
25
+ } ) ;
26
+ } ) ;
12
27
it ( 'should set node inert property' , ( ) => {
13
28
const node = global . document . createElement ( 'div' ) ;
14
29
15
30
const inert = inertMiddleware ( ) . callback ( {
16
31
id : 'test' ,
17
32
middleware : {
18
- destroy : sb . stub ( ) ,
33
+ icache,
34
+ destroy : stub ( ) ,
19
35
node : {
20
36
get ( ) {
21
37
return node ;
@@ -45,7 +61,8 @@ jsdomDescribe('inert middleware', () => {
45
61
const inert = inertMiddleware ( ) . callback ( {
46
62
id : 'test' ,
47
63
middleware : {
48
- destroy : sb . stub ( ) ,
64
+ icache,
65
+ destroy : stub ( ) ,
49
66
node : {
50
67
get ( ) {
51
68
return node ;
@@ -77,11 +94,12 @@ jsdomDescribe('inert middleware', () => {
77
94
parent . appendChild ( childTwo ) ;
78
95
parent . appendChild ( childThree ) ;
79
96
parent . appendChild ( node ) ;
80
- const destroyStub = sb . stub ( ) ;
97
+ const destroyStub = stub ( ) ;
81
98
82
99
const inert = inertMiddleware ( ) . callback ( {
83
100
id : 'test' ,
84
101
middleware : {
102
+ icache,
85
103
destroy : destroyStub ,
86
104
node : {
87
105
get ( ) {
@@ -103,4 +121,56 @@ jsdomDescribe('inert middleware', () => {
103
121
assert . strictEqual ( childTwo . inert , false ) ;
104
122
assert . strictEqual ( childThree . inert , false ) ;
105
123
} ) ;
124
+
125
+ it ( 'should only set inert state when properties change' , ( ) => {
126
+ const parent = global . document . createElement ( 'div' ) ;
127
+ const childOne = global . document . createElement ( 'div' ) ;
128
+ const childTwo = global . document . createElement ( 'div' ) ;
129
+ const childThree = global . document . createElement ( 'div' ) ;
130
+ const childFour = global . document . createElement ( 'div' ) ;
131
+ const node = global . document . createElement ( 'div' ) ;
132
+ parent . appendChild ( childOne ) ;
133
+ parent . appendChild ( childTwo ) ;
134
+ parent . appendChild ( childThree ) ;
135
+ parent . appendChild ( node ) ;
136
+ let _inert = false ;
137
+ const inertStub = stub ( ) ;
138
+ Object . defineProperty ( childFour , 'inert' , {
139
+ get ( ) {
140
+ return _inert ;
141
+ } ,
142
+ set ( value : boolean ) {
143
+ _inert = value ;
144
+ inertStub ( ) ;
145
+ }
146
+ } ) ;
147
+ const destroyStub = stub ( ) ;
148
+ const inert = inertMiddleware ( ) . callback ( {
149
+ id : 'test' ,
150
+ middleware : {
151
+ icache,
152
+ destroy : destroyStub ,
153
+ node : {
154
+ get ( ) {
155
+ return node ;
156
+ }
157
+ }
158
+ } ,
159
+ properties : ( ) => ( { } ) ,
160
+ children : ( ) => [ ]
161
+ } ) ;
162
+ inert . set ( 'key' , true , true ) ;
163
+ assert . strictEqual ( node . inert , false ) ;
164
+ assert . strictEqual ( childOne . inert , true ) ;
165
+ assert . strictEqual ( childTwo . inert , true ) ;
166
+ assert . strictEqual ( childThree . inert , true ) ;
167
+ assert . strictEqual ( inertStub . callCount , 0 ) ;
168
+ parent . appendChild ( childFour ) ;
169
+ inert . set ( 'key' , true , true ) ;
170
+ assert . strictEqual ( node . inert , false ) ;
171
+ assert . strictEqual ( childOne . inert , true ) ;
172
+ assert . strictEqual ( childTwo . inert , true ) ;
173
+ assert . strictEqual ( childThree . inert , true ) ;
174
+ assert . strictEqual ( inertStub . callCount , 0 ) ;
175
+ } ) ;
106
176
} ) ;
0 commit comments