@peter.naydenov/cuts 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +2 -1
- package/Migration.guide.md +93 -0
- package/README.md +30 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/findInstructions.js.html +352 -0
- package/coverage/lcov-report/src/index.html +146 -0
- package/coverage/lcov-report/src/main.js.html +610 -0
- package/coverage/lcov-report/src/methods/hide.js.html +244 -0
- package/coverage/lcov-report/src/methods/index.html +206 -0
- package/coverage/lcov-report/src/methods/jump.js.html +148 -0
- package/coverage/lcov-report/src/methods/jumpBack.js.html +157 -0
- package/coverage/lcov-report/src/methods/jumpsReset.js.html +133 -0
- package/coverage/lcov-report/src/methods/listShortcuts.js.html +148 -0
- package/coverage/lcov-report/src/methods/setScenes.js.html +313 -0
- package/coverage/lcov-report/src/methods/show.js.html +466 -0
- package/coverage/lcov-report/src/setInstruction.js.html +157 -0
- package/coverage/lcov.info +461 -0
- package/cypress/support/component-index.html +11 -0
- package/dist/cuts.cjs +1 -1
- package/dist/cuts.esm.mjs +1 -1
- package/dist/cuts.umd.js +1 -1
- package/package.json +12 -12
- package/src/main.js +6 -4
- package/test/01-general.cy.js +348 -0
- package/test/blue.vue +13 -0
- package/test/dummy.vue +34 -0
- package/test/gray.vue +12 -0
- package/test/red.vue +11 -0
- package/tsconfig.json +13 -10
- package/types/main.d.ts +2 -2
- package/types/main.d.ts.map +1 -1
- package/test-vitest/01-findPosition.test.js +0 -119
- package/test-vitest/02-cuts.test.js +0 -412
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import findInstructions from "../src/findInstructions.js"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe ( 'Find a Position', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
it ( 'Switch top level scenes', () => {
|
|
11
|
-
let result = []
|
|
12
|
-
let g = findInstructions ( 'old', [], 'new', [] )
|
|
13
|
-
|
|
14
|
-
for (const n of g) { result.push(n) }
|
|
15
|
-
|
|
16
|
-
expect(result.length).toBe ( 2 )
|
|
17
|
-
expect(result[0][0]).toBe ( 'old' )
|
|
18
|
-
expect(result[0][1]).toBe ( 'hide' )
|
|
19
|
-
|
|
20
|
-
expect(result[1][0]).toBe ( 'new' )
|
|
21
|
-
expect(result[1][1]).toBe ( 'show' )
|
|
22
|
-
}) // it switch top level scenes
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
it ( 'Switch from child scene to top level scene', () => {
|
|
27
|
-
let result = []
|
|
28
|
-
let g = findInstructions ( 'old', ['one', 'two'], 'new', [] )
|
|
29
|
-
|
|
30
|
-
for (const n of g) { result.push(n) }
|
|
31
|
-
|
|
32
|
-
expect(result[0]).toEqual(['old', 'hide'])
|
|
33
|
-
expect(result[1]).toEqual(['two', 'hide'])
|
|
34
|
-
expect(result[2]).toEqual(['one', 'hide'])
|
|
35
|
-
expect(result[3]).toEqual(['new', 'show'])
|
|
36
|
-
}) // it switch from child scene to top level scene
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
it ( 'Switch to child scene', () => {
|
|
41
|
-
let result = []
|
|
42
|
-
let g = findInstructions ( 'old', ['bla'], 'new', ['old', 'two', 'three'])
|
|
43
|
-
for (const n of g) { result.push(n) }
|
|
44
|
-
|
|
45
|
-
expect(result).toHaveLength(3)
|
|
46
|
-
expect(result[0]).toEqual(['two', 'show'])
|
|
47
|
-
expect(result[1]).toEqual(['three', 'show'])
|
|
48
|
-
expect(result[2]).toEqual(['new', 'show'])
|
|
49
|
-
}) // it switch to child scene
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
it ( 'From child scene to other siblings scene', () => {
|
|
54
|
-
let result = []
|
|
55
|
-
let g = findInstructions('old', ['two', 'three'], 'new', ['two', 'three'])
|
|
56
|
-
for (const n of g) { result.push(n) }
|
|
57
|
-
|
|
58
|
-
expect(result).toHaveLength ( 2 )
|
|
59
|
-
expect(result[0]).toEqual(['old', 'hide'])
|
|
60
|
-
expect(result[1]).toEqual(['new', 'show'])
|
|
61
|
-
}) // it from top level scene to not own child scene
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
it ( 'From top level scene to not own child scene', () => {
|
|
66
|
-
let result = []
|
|
67
|
-
let g = findInstructions('old', undefined, 'new', ['two', 'three'])
|
|
68
|
-
for (const n of g) { result.push(n) }
|
|
69
|
-
|
|
70
|
-
expect(result).toHaveLength(3)
|
|
71
|
-
expect(result[0]).toEqual(['old', 'hide'])
|
|
72
|
-
expect(result[1]).toEqual(['two', 'show'])
|
|
73
|
-
expect(result[2]).toEqual(['three', 'show'])
|
|
74
|
-
}) // it from top level scene to not own child scene
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
it ( 'Long chain of parents', () => {
|
|
79
|
-
let result = []
|
|
80
|
-
let g = findInstructions('old', ['one', 'branch'], 'new', ['one', 'two', 'three'])
|
|
81
|
-
for (const n of g) { result.push(n) }
|
|
82
|
-
|
|
83
|
-
expect(result).toHaveLength(5)
|
|
84
|
-
expect(result[0]).toEqual(['old', 'hide'])
|
|
85
|
-
expect(result[1]).toEqual(['branch', 'hide'])
|
|
86
|
-
expect(result[2]).toEqual(['two', 'show'])
|
|
87
|
-
expect(result[3]).toEqual(['three', 'show'])
|
|
88
|
-
expect(result[4]).toEqual(['new', 'show'])
|
|
89
|
-
}) // it long chain of parents
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
it ( 'Different branches', () => {
|
|
94
|
-
let result = []
|
|
95
|
-
let g = findInstructions('old', ['something', 'branch'], 'new', ['one', 'two', 'three'])
|
|
96
|
-
for (const n of g) { result.push(n) }
|
|
97
|
-
|
|
98
|
-
expect(result).toHaveLength(7)
|
|
99
|
-
expect(result[0]).toEqual(['old', 'hide'])
|
|
100
|
-
expect(result[1]).toEqual(['branch', 'hide'])
|
|
101
|
-
expect(result[2]).toEqual(['something', 'hide'])
|
|
102
|
-
expect(result[3]).toEqual(['one', 'show'])
|
|
103
|
-
expect(result[4]).toEqual(['two', 'show'])
|
|
104
|
-
expect(result[5]).toEqual(['three', 'show'])
|
|
105
|
-
expect(result[6]).toEqual(['new', 'show'])
|
|
106
|
-
}) // it long chain of parents
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
it ( 'Target scene is in the list of parents of the current scene', () => {
|
|
111
|
-
let result = []
|
|
112
|
-
let g = findInstructions ( 'token-get-role', ['tokens', 'token-pop'], 'tokens', [] )
|
|
113
|
-
for (const n of g) { result.push(n) }
|
|
114
|
-
expect ( result ).toHaveLength ( 2 )
|
|
115
|
-
expect ( result[0] ).toEqual ( [ 'token-get-role', 'hide' ])
|
|
116
|
-
expect ( result[1] ).toEqual ( [ 'token-pop', 'hide' ])
|
|
117
|
-
}) // it Target scene is in the list of parents of the current scene
|
|
118
|
-
|
|
119
|
-
}) // describe
|
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import cuts from "../src/main.js"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe ( 'Cuts integration', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
it ( 'Open a scene, and 2 levels deep child', async () => {
|
|
11
|
-
const calls = [];
|
|
12
|
-
|
|
13
|
-
const scenes = [
|
|
14
|
-
{ name: 'top', scene: { show: ({task}) => { calls.push('show top'); task.done() }, hide: ({task}) => { calls.push('hide top'); task.done() } } },
|
|
15
|
-
{ name: 'mid', scene: { show: ({task}) => { calls.push('show mid'); task.done() }, hide: ({task}) => { calls.push('hide mid'); task.done() }, parents: ['top'] } },
|
|
16
|
-
{ name: 'deep', scene: { show: ({task}) => { calls.push('show deep'); task.done() }, hide: ({task}) => { calls.push('hide deep'); task.done() }, parents: ['top', 'mid'] } }
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
const script = cuts();
|
|
20
|
-
script.setScenes ( scenes )
|
|
21
|
-
|
|
22
|
-
await script.show ({ scene: 'top' })
|
|
23
|
-
expect ( calls ).toEqual ([ 'show top' ])
|
|
24
|
-
|
|
25
|
-
await script.show ({ scene: 'deep' })
|
|
26
|
-
expect ( calls ).toEqual ([
|
|
27
|
-
'show top',
|
|
28
|
-
'show mid',
|
|
29
|
-
'show deep'
|
|
30
|
-
])
|
|
31
|
-
|
|
32
|
-
await script.show ({ scene: 'top' })
|
|
33
|
-
expect ( calls ).toEqual ([
|
|
34
|
-
'show top',
|
|
35
|
-
'show mid',
|
|
36
|
-
'show deep',
|
|
37
|
-
'hide deep',
|
|
38
|
-
'hide mid'
|
|
39
|
-
])
|
|
40
|
-
|
|
41
|
-
await script.show ({ scene: 'deep' })
|
|
42
|
-
expect ( calls ).toEqual ([
|
|
43
|
-
'show top',
|
|
44
|
-
'show mid',
|
|
45
|
-
'show deep',
|
|
46
|
-
'hide deep',
|
|
47
|
-
'hide mid',
|
|
48
|
-
'show mid',
|
|
49
|
-
'show deep'
|
|
50
|
-
])
|
|
51
|
-
}) // it Open a scene, and 2 levels deep child
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
it ( 'Load plugins', async () => {
|
|
56
|
-
const script = cuts()
|
|
57
|
-
const plugins = await script.loadPlugins ( ['Key', 'Click'] )
|
|
58
|
-
expect ( plugins ).toHaveLength ( 2 )
|
|
59
|
-
}) // it Load plugins
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
it ( 'beforeHide', async () => {
|
|
68
|
-
const script = cuts ();
|
|
69
|
-
const calls = [];
|
|
70
|
-
const scenes = [
|
|
71
|
-
{
|
|
72
|
-
name: 'top'
|
|
73
|
-
, scene: {
|
|
74
|
-
show: ({task}) => { calls.push('show top'); task.done() },
|
|
75
|
-
hide: ({task}) => { calls.push('hide top'); task.done() } ,
|
|
76
|
-
// Prevent unload event:
|
|
77
|
-
'beforeHide': ({ done }) => done ( false ) ,
|
|
78
|
-
'click: left-1': () => calls.push('click left-1')
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'other'
|
|
83
|
-
, scene: {
|
|
84
|
-
show: ({task}) => { calls.push('show other'); task.done() },
|
|
85
|
-
hide: ({task}) => { calls.push('hide other'); task.done() }
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
script.setScenes ( scenes )
|
|
91
|
-
await script.show ({ scene: 'top' })
|
|
92
|
-
expect ( calls ).toEqual (['show top'])
|
|
93
|
-
|
|
94
|
-
await script.show ({ scene: 'other' })
|
|
95
|
-
expect ( calls ).toEqual (['show top'])
|
|
96
|
-
expect ( script.getState().scene ).toEqual ( 'top' )
|
|
97
|
-
}) // it beforeHide
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
it ( 'Call no existing scene', async () => {
|
|
102
|
-
const script = cuts ({ logLevel : 1 });
|
|
103
|
-
const calls = [];
|
|
104
|
-
const scenes = [
|
|
105
|
-
{
|
|
106
|
-
name: 'top'
|
|
107
|
-
, scene: {
|
|
108
|
-
show: ({task}) => { calls.push('show top'); task.done() },
|
|
109
|
-
hide: ({task}) => { calls.push('hide top'); task.done() } ,
|
|
110
|
-
'click: left-1': () => calls.push ( 'click left-1' ),
|
|
111
|
-
'@app-error': ( arg ) => {
|
|
112
|
-
calls.push ( 'app-error' )
|
|
113
|
-
expect ( arg.type ).toBe ( 'error' )
|
|
114
|
-
expect ( arg.message ).toBe ( 'Scene "any" is not available.' )
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: 'other'
|
|
120
|
-
, scene: {
|
|
121
|
-
show: ({task}) => { calls.push('show other'); task.done() },
|
|
122
|
-
hide: ({task}) => { calls.push('hide other'); task.done() }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
script.setScenes ( scenes )
|
|
128
|
-
await script.show ({ scene: 'top' })
|
|
129
|
-
expect ( calls ).toEqual (['show top'])
|
|
130
|
-
|
|
131
|
-
await script.show ({ scene: 'any' })
|
|
132
|
-
expect ( calls ).toEqual (['show top', 'app-error'])
|
|
133
|
-
expect ( script.getState().scene ).toEqual ( 'top' )
|
|
134
|
-
}) // it Call no existing scene
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
it ( 'Server side rendering (SSR)', async () => {
|
|
139
|
-
const script = cuts ();
|
|
140
|
-
const calls = [];
|
|
141
|
-
const scenes = [
|
|
142
|
-
{
|
|
143
|
-
name: 'home',
|
|
144
|
-
scene: {
|
|
145
|
-
show: ({task}) => { calls.push('show home'); task.done() },
|
|
146
|
-
hide: ({task}) => { calls.push('hide home'); task.done() }
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
];
|
|
150
|
-
|
|
151
|
-
script.setScenes ( scenes )
|
|
152
|
-
|
|
153
|
-
// SSR mode: show without executing the scene's show function
|
|
154
|
-
await script.show({ scene: 'home', options: { ssr: true } })
|
|
155
|
-
|
|
156
|
-
expect(calls).toEqual([]); // show function should not be called
|
|
157
|
-
expect(script.getState().scene ).toBe ( 'home' )
|
|
158
|
-
expect(script.getState().opened ).toBe ( true )
|
|
159
|
-
|
|
160
|
-
// Subsequent show should execute normally
|
|
161
|
-
await script.show ({ scene: 'home' })
|
|
162
|
-
expect( calls ).toEqual(['hide home', 'show home'])
|
|
163
|
-
}) // it Server side rendering (SSR)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
it ( 'Non existing parents error', async () => {
|
|
168
|
-
const script = cuts ();
|
|
169
|
-
const calls = [];
|
|
170
|
-
const scenes = [
|
|
171
|
-
{
|
|
172
|
-
name: 'child'
|
|
173
|
-
, scene: {
|
|
174
|
-
show: ({task}) => { calls.push('show child'); task.done() },
|
|
175
|
-
hide: ({task}) => { calls.push('hide child'); task.done() },
|
|
176
|
-
parents: [ 'nonexistent' ]
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
];
|
|
180
|
-
script.setScenes ( scenes )
|
|
181
|
-
await script.show ({ scene: 'child' })
|
|
182
|
-
expect ( calls ).toEqual ([])
|
|
183
|
-
expect ( script.getState().scene ).toBe ( null )
|
|
184
|
-
}) // it Non existing parents error
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
it ( 'No name scene', async () => {
|
|
189
|
-
const script = cuts({ logLevel : 0 });
|
|
190
|
-
const scenes = [
|
|
191
|
-
{
|
|
192
|
-
scene: {
|
|
193
|
-
show: ({task}) => task.done(),
|
|
194
|
-
hide: ({task}) => task.done()
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
];
|
|
198
|
-
script.setScenes ( scenes );
|
|
199
|
-
expect ( script.listScenes() ).toEqual ( [] );
|
|
200
|
-
}) // it No name scene
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
it ( 'No scene in definition', async () => {
|
|
205
|
-
const script = cuts({ logLevel : 0 });
|
|
206
|
-
const scenes = [ {name: 'top'} ];
|
|
207
|
-
script.setScenes ( scenes );
|
|
208
|
-
expect ( script.listScenes() ).toEqual ( [] );
|
|
209
|
-
}) // it No scene in definition
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
it ( 'List shortcuts', async () => {
|
|
214
|
-
const script = cuts ()
|
|
215
|
-
const calls = [];
|
|
216
|
-
|
|
217
|
-
const scenes = [
|
|
218
|
-
{
|
|
219
|
-
name: 'top'
|
|
220
|
-
, scene: {
|
|
221
|
-
show: ({task}) => { calls.push('show top'); task.done() },
|
|
222
|
-
hide: ({task}) => { calls.push('hide top'); task.done() } ,
|
|
223
|
-
'click: left-1': () => calls.push('click left-1')
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
];
|
|
227
|
-
|
|
228
|
-
script.setScenes ( scenes )
|
|
229
|
-
expect ( script.listShortcuts( 'top' ) ).toEqual ( ['click: left-1'] )
|
|
230
|
-
}) // it List shortcuts
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
it ( 'List shortcuts', async () => {
|
|
235
|
-
const script = cuts ()
|
|
236
|
-
const calls = [];
|
|
237
|
-
|
|
238
|
-
const scenes = [
|
|
239
|
-
{
|
|
240
|
-
name: 'top'
|
|
241
|
-
, scene: {
|
|
242
|
-
show: ({task}) => { calls.push('show top'); task.done() },
|
|
243
|
-
hide: ({task}) => { calls.push('hide top'); task.done() } ,
|
|
244
|
-
'click: left-1': () => calls.push('click left-1')
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
];
|
|
248
|
-
|
|
249
|
-
script.setScenes ( scenes )
|
|
250
|
-
expect ( script.listShortcuts( 'none' ) ).toEqual ( null )
|
|
251
|
-
}) // it List shortcuts
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
it ( 'Jump functionality', async () => {
|
|
256
|
-
const script = cuts({ logLevel : 0 });
|
|
257
|
-
const calls = [];
|
|
258
|
-
const scenes = [
|
|
259
|
-
{
|
|
260
|
-
name: 'home'
|
|
261
|
-
, scene: {
|
|
262
|
-
show: ({task}) => { calls.push('show home'); task.done() },
|
|
263
|
-
hide: ({task}) => { calls.push('hide home'); task.done() }
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
name: 'settings'
|
|
268
|
-
, scene: {
|
|
269
|
-
show: ({task}) => { calls.push('show settings'); task.done() },
|
|
270
|
-
hide: ({task}) => { calls.push('hide settings'); task.done() }
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
];
|
|
274
|
-
|
|
275
|
-
script.setScenes ( scenes );
|
|
276
|
-
|
|
277
|
-
await script.show ({ scene: 'home' });
|
|
278
|
-
expect ( calls ).toEqual (['show home']);
|
|
279
|
-
expect ( script.getState().scene ).toEqual ( 'home' );
|
|
280
|
-
|
|
281
|
-
await script.jump ({ scene: 'settings' });
|
|
282
|
-
expect ( calls ).toEqual (['show home', 'hide home', 'show settings']);
|
|
283
|
-
expect ( script.getState().scene ).toEqual ( 'settings' );
|
|
284
|
-
|
|
285
|
-
await script.jumpBack ();
|
|
286
|
-
expect ( calls ).toEqual (['show home', 'hide home', 'show settings', 'hide settings', 'show home']);
|
|
287
|
-
expect ( script.getState().scene ).toEqual ( 'home' );
|
|
288
|
-
}) // it Jump functionality
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
it ( 'Jump with hops', async () => {
|
|
293
|
-
const script = cuts();
|
|
294
|
-
const calls = [];
|
|
295
|
-
const scenes = [
|
|
296
|
-
{
|
|
297
|
-
name: 'scene1'
|
|
298
|
-
, scene: {
|
|
299
|
-
show: ({task}) => { calls.push('show scene1'); task.done() },
|
|
300
|
-
hide: ({task}) => { calls.push('hide scene1'); task.done() }
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
name: 'scene2'
|
|
305
|
-
, scene: {
|
|
306
|
-
show: ({task}) => { calls.push('show scene2'); task.done() },
|
|
307
|
-
hide: ({task}) => { calls.push('hide scene2'); task.done() }
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
name: 'scene3'
|
|
312
|
-
, scene: {
|
|
313
|
-
show: ({task}) => { calls.push('show scene3'); task.done() },
|
|
314
|
-
hide: ({task}) => { calls.push('hide scene3'); task.done() }
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
];
|
|
318
|
-
|
|
319
|
-
script.setScenes ( scenes );
|
|
320
|
-
|
|
321
|
-
await script.show ({ scene: 'scene1' });
|
|
322
|
-
expect ( script.getState().scene ).toEqual ( 'scene1' );
|
|
323
|
-
|
|
324
|
-
await script.jump ({ scene: 'scene2' });
|
|
325
|
-
expect ( script.getState().scene ).toEqual ( 'scene2' );
|
|
326
|
-
|
|
327
|
-
await script.jump ({ scene: 'scene3' });
|
|
328
|
-
expect ( script.getState().scene ).toEqual ( 'scene3' );
|
|
329
|
-
|
|
330
|
-
await script.jumpBack ({ hops: 2 });
|
|
331
|
-
expect ( script.getState().scene ).toEqual ( 'scene1' );
|
|
332
|
-
}) // it Jump with hops
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
it ( 'Jumps reset and jump back on empty stack', async () => {
|
|
337
|
-
const script = cuts();
|
|
338
|
-
const scenes = [
|
|
339
|
-
{
|
|
340
|
-
name: 'scene1'
|
|
341
|
-
, scene: {
|
|
342
|
-
show: ({task}) => task.done(),
|
|
343
|
-
hide: ({task}) => task.done()
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
name: 'scene2'
|
|
348
|
-
, scene: {
|
|
349
|
-
show: ({task}) => task.done(),
|
|
350
|
-
hide: ({task}) => task.done()
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
];
|
|
354
|
-
|
|
355
|
-
script.setScenes ( scenes );
|
|
356
|
-
|
|
357
|
-
await script.show ({ scene: 'scene1' });
|
|
358
|
-
await script.jump ({ scene: 'scene2' });
|
|
359
|
-
expect ( script.getState().scene ).toEqual ( 'scene2' );
|
|
360
|
-
|
|
361
|
-
script.jumpsReset();
|
|
362
|
-
|
|
363
|
-
const result = await script.jumpBack();
|
|
364
|
-
expect ( result ).toBeUndefined();
|
|
365
|
-
expect ( script.getState().scene ).toEqual ( 'scene2' ); // scene should not change
|
|
366
|
-
}) // it Jumps reset and jump back on empty stack
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
it ( 'Show scene with wildcard parent', async () => {
|
|
371
|
-
// Test for scenes with parents: ['*']
|
|
372
|
-
// The '*' wildcard allows the scene to be shown as an overlay over any current scene
|
|
373
|
-
// without hiding the underlying scene. The previous scene is preserved in currentParents.
|
|
374
|
-
const script = cuts();
|
|
375
|
-
const calls = [];
|
|
376
|
-
const scenes = [
|
|
377
|
-
{
|
|
378
|
-
name: 'base'
|
|
379
|
-
, scene: {
|
|
380
|
-
show: ({task}) => { calls.push('show base'); task.done() },
|
|
381
|
-
hide: ({task}) => { calls.push('hide base'); task.done() }
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
name: 'overlay' // This scene uses '*' to indicate it can overlay any scene
|
|
386
|
-
, scene: {
|
|
387
|
-
show: ({task}) => {
|
|
388
|
-
calls.push ( 'show overlay' )
|
|
389
|
-
task.done ()
|
|
390
|
-
},
|
|
391
|
-
hide: ({task}) => { calls.push('hide overlay'); task.done() },
|
|
392
|
-
parents: ['*'] // '*' means this scene can be shown over any current scene
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
];
|
|
396
|
-
|
|
397
|
-
script.setScenes ( scenes );
|
|
398
|
-
|
|
399
|
-
await script.show ({ scene: 'base' });
|
|
400
|
-
expect ( calls ).toEqual (['show base']);
|
|
401
|
-
expect ( script.getState().scene ).toEqual ( 'base' );
|
|
402
|
-
expect ( script.getState().parents ).toEqual ( [] );
|
|
403
|
-
|
|
404
|
-
await script.show ({ scene: 'overlay' });
|
|
405
|
-
expect ( calls ).toEqual (['show base', 'show overlay']); // Note: 'hide base' is not called
|
|
406
|
-
expect ( script.getState().scene ).toEqual ( 'overlay' );
|
|
407
|
-
expect ( script.getState().parents ).toEqual ( ['base'] ); // Previous scene is saved
|
|
408
|
-
}) // it Show scene with wildcard parent
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}) // describe
|