@peter.naydenov/cuts 1.5.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 +53 -7
- 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/findInstructions.js +0 -6
- package/src/main.js +13 -6
- package/src/methods/setScenes.js +27 -11
- package/src/methods/show.js +26 -27
- 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/findInstructions.d.ts.map +1 -1
- package/types/main.d.ts +2 -2
- package/types/main.d.ts.map +1 -1
- package/types/methods/setScenes.d.ts +20 -4
- package/types/methods/setScenes.d.ts.map +1 -1
- package/types/methods/show.d.ts.map +1 -1
- package/test-vitest/01-findPosition.test.js +0 -119
- package/test-vitest/02-cuts.test.js +0 -56
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/cuts",
|
|
3
3
|
"description": "SPA scene manager",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Peter Naydenov",
|
|
7
7
|
"main": "./src/main.js",
|
|
@@ -31,24 +31,24 @@
|
|
|
31
31
|
"url": "git+https://github.com/PeterNaydenov/cuts.git"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@peter.naydenov/visual-controller-for-vue3": "^2.1.
|
|
35
|
-
"@rollup/plugin-commonjs": "^
|
|
34
|
+
"@peter.naydenov/visual-controller-for-vue3": "^2.1.7",
|
|
35
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
36
36
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
37
37
|
"@rollup/plugin-terser": "^0.4.4",
|
|
38
|
-
"@types/node": "^24.
|
|
38
|
+
"@types/node": "^24.10.0",
|
|
39
39
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
40
|
-
"@vitest/coverage-v8": "^4.0.
|
|
41
|
-
"cypress": "^15.
|
|
42
|
-
"rollup": "^4.
|
|
40
|
+
"@vitest/coverage-v8": "^4.0.8",
|
|
41
|
+
"cypress": "^15.6.0",
|
|
42
|
+
"rollup": "^4.53.1",
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
|
-
"vite": "^7.
|
|
45
|
-
"vitest": "^4.0.
|
|
46
|
-
"vue": "^3.5.
|
|
44
|
+
"vite": "^7.2.2",
|
|
45
|
+
"vitest": "^4.0.8",
|
|
46
|
+
"vue": "^3.5.24"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@peter.naydenov/log": "^1.1.1",
|
|
50
|
-
"@peter.naydenov/shortcuts": "^
|
|
51
|
-
"ask-for-promise": "^3.0
|
|
50
|
+
"@peter.naydenov/shortcuts": "^4.0.0",
|
|
51
|
+
"ask-for-promise": "^3.1.0"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
54
54
|
"script",
|
package/src/findInstructions.js
CHANGED
|
@@ -20,13 +20,7 @@ function* findInstructions ( currentName, currentParents, targetName, targetPare
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if ( targetParents.length === 0 ) { // Need to close all current parents, then open the target
|
|
23
|
-
if ( !currentParents ) {
|
|
24
|
-
yield [ currentName, 'hide' ]
|
|
25
|
-
yield [ targetName, 'show' ]
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
23
|
yield [ currentName, 'hide' ]
|
|
29
|
-
|
|
30
24
|
if ( currentParents.includes ( targetName ) ) {
|
|
31
25
|
let index = currentParents.indexOf ( targetName );
|
|
32
26
|
let filtered = currentParents.filter ( (x,i) => i > index )
|
package/src/main.js
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
* History notes:
|
|
9
9
|
* - Started as @peter.naydenov/screen-writer on gitHub for the first time on 2023-11-24;
|
|
10
10
|
* - Version 2.0.0 of screen-writer. Works with shortcuts@3.0.1. Published on March 6th, 2024;
|
|
11
|
+
* - Version 2.0.0 of cuts. Works with shortcuts@4.0.0. Published on November 9th, 2025;
|
|
11
12
|
* - Rename to @peter.naydenov/cuts
|
|
12
13
|
* Changes in documentation and some methods were renamed accordingly.
|
|
13
14
|
* Version 1.0.0.
|
|
14
15
|
* Published for first time as package '@peter.naydenov/cuts' on May 8th, 2024;
|
|
15
16
|
* Extend 'scene' with optional 'afterShow' and 'beforeHide' methods. December 21st, 2024;
|
|
16
17
|
* - Shortcuts@3.2.x. Plugin 'form' is available. August 15th, 2025;
|
|
18
|
+
* - Shortcuts@4.0.0. New plugins 'scroll' and 'hover' are available. November 9th, 2025;
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
|
|
@@ -37,8 +39,13 @@ import jumpsReset from './methods/jumpsReset.js'
|
|
|
37
39
|
function main ( cfg= {logLevel:0} ) {
|
|
38
40
|
const
|
|
39
41
|
shortcutMngr = shortcuts ({ errorEventName: '@app-error' })
|
|
40
|
-
, logLevel = cfg.logLevel ||
|
|
41
|
-
, log = createLog ({ level:logLevel })
|
|
42
|
+
, logLevel = cfg.logLevel || 1
|
|
43
|
+
, log = createLog ({ level:logLevel }, (arg) => {
|
|
44
|
+
const { type } = arg;
|
|
45
|
+
if ( type === 'error' ) {
|
|
46
|
+
shortcutMngr.emit ( '@app-error', arg )
|
|
47
|
+
}
|
|
48
|
+
})
|
|
42
49
|
, state = {
|
|
43
50
|
currentScene : null // Current scene name;
|
|
44
51
|
, currentParents : null // Current scene parents if any;
|
|
@@ -69,10 +76,10 @@ function main ( cfg= {logLevel:0} ) {
|
|
|
69
76
|
API.jumpsReset = jumpsReset ( state )
|
|
70
77
|
|
|
71
78
|
/**
|
|
72
|
-
* @typedef {'Key'|'Click'|'Form' } pluginNames
|
|
73
|
-
* @description List of possible plugin names: 'Key', 'Click', 'Form'
|
|
79
|
+
* @typedef {'Key'|'Click'|'Form'|'Hover'|'Scroll' } pluginNames
|
|
80
|
+
* @description List of possible plugin names: 'Key', 'Click', 'Form', 'Hover', 'Scroll'
|
|
74
81
|
*
|
|
75
|
-
* Load a needed shortcut plugins - 'Key', 'Click', 'Form' and so on.
|
|
82
|
+
* Load a needed shortcut plugins - 'Key', 'Click', 'Form', 'Hover', 'Scroll' and so on.
|
|
76
83
|
* It's a async function. Don't forget to 'await' it.
|
|
77
84
|
* @function loadPlugins
|
|
78
85
|
* @param {Array.<pluginNames>} plugins - list of plugins to load
|
|
@@ -109,7 +116,7 @@ function main ( cfg= {logLevel:0} ) {
|
|
|
109
116
|
* @param {string} note - note, provided to action functions
|
|
110
117
|
* @returns void
|
|
111
118
|
*/
|
|
112
|
-
|
|
119
|
+
API.setNote = note => shortcutMngr.setNote ( note )
|
|
113
120
|
|
|
114
121
|
/**
|
|
115
122
|
* @function listScenes
|
package/src/methods/setScenes.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} AskObject
|
|
6
|
+
* @property {function} done - Mark the task as done
|
|
7
|
+
*/
|
|
4
8
|
/**
|
|
5
9
|
* @typedef {Object} SceneObject
|
|
6
|
-
* @property {function} show - load interface and prerequisites for the scene;
|
|
10
|
+
* @property {function({task: AskObject, dependencies: *}): void} show - load interface and prerequisites for the scene;
|
|
7
11
|
* @property {function():boolean} [afterShow] - run after scene is loaded. Optional. Returns true to continue loading, false to cancel;
|
|
8
|
-
* @property {function():void} hide - Reverse the settings from 'show';
|
|
12
|
+
* @property {function({task: AskObject, dependencies: *}): void} hide - Reverse the settings from 'show';
|
|
9
13
|
* @property {function():void} [beforeHide] - Run before scene is hidden. Optional;
|
|
10
14
|
* @property {Array.<string>} [parents] - list of parent scene names.
|
|
11
15
|
* @property {*} ... - shortcut descriptions
|
|
@@ -30,15 +34,27 @@ function setScenes ( dependencies, state ) {
|
|
|
30
34
|
* @description Screen Description is an object with fields 'name' and 'scene'
|
|
31
35
|
*/
|
|
32
36
|
return function setScenes ( list ) {
|
|
33
|
-
const { shortcutMngr } = dependencies;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const { shortcutMngr, log } = dependencies;
|
|
38
|
+
list.forEach ( item => {
|
|
39
|
+
if ( item == null ) return
|
|
40
|
+
const {name, scene } = item;
|
|
41
|
+
if ( !name ) {
|
|
42
|
+
log ({
|
|
43
|
+
message: `Scene name is not defined`
|
|
44
|
+
, level : 1
|
|
45
|
+
, type : 'error'
|
|
46
|
+
})
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if ( scene == null ) {
|
|
50
|
+
log ({
|
|
51
|
+
message: `Scene ${name} is not defined`
|
|
52
|
+
, level : 1
|
|
53
|
+
, type : 'error'
|
|
54
|
+
})
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
if ( ! scene.parents ) scene.parents = []
|
|
42
58
|
state.scenes[name] = scene
|
|
43
59
|
state.sceneNames.add ( name )
|
|
44
60
|
|
package/src/methods/show.js
CHANGED
|
@@ -24,8 +24,10 @@ function show ( dependencies, state ) {
|
|
|
24
24
|
|
|
25
25
|
if ( hasBeforeHide ) { // Execute 'beforeUnload' function if exists
|
|
26
26
|
const closingFn = scenes[currentScene].beforeHide;
|
|
27
|
+
// TODO: If async elements in beforeUnload, we will
|
|
28
|
+
// need full unloadTask and function should return a promise
|
|
27
29
|
closingFn ({ done:unloadTask.done, dependencies: shortcutMngr.getDependencies() })
|
|
28
|
-
} // if
|
|
30
|
+
} // if currentScene
|
|
29
31
|
else unloadTask.done ( true )
|
|
30
32
|
|
|
31
33
|
|
|
@@ -38,21 +40,19 @@ function show ( dependencies, state ) {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
if ( !sceneNames.has ( requestedScene ) ) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return showTask.promise
|
|
49
|
-
}
|
|
43
|
+
log ({
|
|
44
|
+
message: `Scene "${requestedScene}" is not available.`
|
|
45
|
+
, level : 1
|
|
46
|
+
, type : 'error'
|
|
47
|
+
})
|
|
48
|
+
showTask.done ()
|
|
49
|
+
return showTask.promise
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if ( !opened && options.ssr ) { // Check for Server side rendering on first scene load only
|
|
53
53
|
// Executes only once when the scene manager is started
|
|
54
54
|
state.opened = true
|
|
55
|
-
state.
|
|
55
|
+
state.currentScene = requestedScene
|
|
56
56
|
shortcutMngr.changeContext ( requestedScene )
|
|
57
57
|
showTask.done ()
|
|
58
58
|
return showTask.promise
|
|
@@ -60,23 +60,22 @@ function show ( dependencies, state ) {
|
|
|
60
60
|
|
|
61
61
|
const { show, parents=[] } = scenes[requestedScene];
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
if ( parents[0] === '*' ) {
|
|
64
|
+
const overlayTask = setInstruction(show, ...args)()
|
|
65
|
+
overlayTask.then ( () => showTask.done () )
|
|
66
|
+
state.currentParents.push ( state.currentScene )
|
|
67
|
+
state.currentScene = requestedScene
|
|
68
|
+
return showTask.promise
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let checkParents = ( parents.length === 0 ) ? true : parents.every ( name => sceneNames.has ( name ) )
|
|
71
72
|
|
|
72
73
|
if ( !checkParents ) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
79
|
-
}
|
|
74
|
+
log ({
|
|
75
|
+
message: `Some of '${requestedScene}' parent scenes are not set.`
|
|
76
|
+
, level : 1
|
|
77
|
+
, type : 'error'
|
|
78
|
+
})
|
|
80
79
|
showTask.done ()
|
|
81
80
|
return showTask.promise
|
|
82
81
|
}
|
|
@@ -109,7 +108,7 @@ function show ( dependencies, state ) {
|
|
|
109
108
|
|
|
110
109
|
goingTask.onComplete ( () => {
|
|
111
110
|
state.opened = true
|
|
112
|
-
state.
|
|
111
|
+
state.currentScene = requestedScene
|
|
113
112
|
state.currentParents = scenes[requestedScene].parents || null
|
|
114
113
|
shortcutMngr.changeContext ( requestedScene )
|
|
115
114
|
if ( typeof scenes[requestedScene].afterShow === 'function' ) scenes[requestedScene].afterShow ({ dependencies: shortcutMngr.getDependencies(), done: () => {} })
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import VisualController from '@peter.naydenov/visual-controller-for-vue3' // Docs : https://github.com/PeterNaydenov/visual-controller-for-vue3
|
|
4
|
+
import { expect } from 'chai'
|
|
5
|
+
import cuts from '../src/main.js'
|
|
6
|
+
import { pluginClick } from '@peter.naydenov/shortcuts'
|
|
7
|
+
|
|
8
|
+
import Dummy from './dummy.vue'
|
|
9
|
+
import Red from './red.vue'
|
|
10
|
+
import Blue from './blue.vue'
|
|
11
|
+
import Gray from './gray.vue'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
describe ( 'General', () => {
|
|
16
|
+
|
|
17
|
+
it ( 'Start a sreenWriter. ScreenWriter API', () => {
|
|
18
|
+
const script = cuts ();
|
|
19
|
+
expect ( script ).to.have.property ( 'show' )
|
|
20
|
+
expect ( script ).to.have.property ( 'hide' )
|
|
21
|
+
expect ( script ).to.have.property ( 'setScenes' )
|
|
22
|
+
expect ( script ).to.have.property ( 'setNote' )
|
|
23
|
+
expect ( script ).to.have.property ( 'listScenes' )
|
|
24
|
+
expect ( script ).to.have.property ( 'listShortcuts' )
|
|
25
|
+
expect ( script ).to.have.property ( 'setDependencies' )
|
|
26
|
+
expect ( script ).to.have.property ( 'getDependencies' )
|
|
27
|
+
}) // it start a director
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
it ( 'Load a top level page', done => {
|
|
32
|
+
let
|
|
33
|
+
render = false
|
|
34
|
+
, click = false
|
|
35
|
+
, html = new VisualController ()
|
|
36
|
+
;
|
|
37
|
+
const
|
|
38
|
+
script = cuts ()
|
|
39
|
+
, d = document.querySelector ('[data-cy-root]')
|
|
40
|
+
, testScene = {
|
|
41
|
+
show : ({ task, dependencies }) => {
|
|
42
|
+
const { html } = dependencies;
|
|
43
|
+
html.publish ( Red, {}, 'container' )
|
|
44
|
+
render = true
|
|
45
|
+
task.done ()
|
|
46
|
+
}
|
|
47
|
+
, hide : ({task, dependencies}) => {
|
|
48
|
+
const { html } = dependencies;
|
|
49
|
+
html.destroy ( 'container' )
|
|
50
|
+
task.done ()
|
|
51
|
+
}
|
|
52
|
+
, 'click: left-1' : ({dependencies,target}) => {
|
|
53
|
+
click = true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
;
|
|
57
|
+
script.enablePlugin ( pluginClick )
|
|
58
|
+
d.id = 'root'
|
|
59
|
+
html.publish ( Dummy, {}, 'root' )
|
|
60
|
+
|
|
61
|
+
cy.wait ( 0 )
|
|
62
|
+
.then ( () => {
|
|
63
|
+
script.setDependencies ({ html })
|
|
64
|
+
script.setScenes ([
|
|
65
|
+
{ name:'test', scene:testScene }
|
|
66
|
+
])
|
|
67
|
+
script.show ({ scene : 'test' })
|
|
68
|
+
// cy.get ( '#target' ).click ()
|
|
69
|
+
})
|
|
70
|
+
.then ( () => {
|
|
71
|
+
expect ( render ).to.be.true
|
|
72
|
+
// expect ( click ).to.be.true
|
|
73
|
+
return cy.wait ( 0 )
|
|
74
|
+
})
|
|
75
|
+
.then ( () => {
|
|
76
|
+
return script.hide ()
|
|
77
|
+
})
|
|
78
|
+
.then ( () => {
|
|
79
|
+
const pageContent = document.getElementById('container').innerHTML
|
|
80
|
+
expect ( pageContent ).to.be.empty
|
|
81
|
+
done ()
|
|
82
|
+
})
|
|
83
|
+
}) // it load a top level page
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
it ( 'Load a deep level page', done => {
|
|
88
|
+
let
|
|
89
|
+
render = false
|
|
90
|
+
, click = false
|
|
91
|
+
, html = new VisualController ()
|
|
92
|
+
;
|
|
93
|
+
const
|
|
94
|
+
script = cuts ()
|
|
95
|
+
, d = document.querySelector ('[data-cy-root]' )
|
|
96
|
+
, testScene = {
|
|
97
|
+
show : ({ task, dependencies }) => {
|
|
98
|
+
const { html } = dependencies;
|
|
99
|
+
html.publish ( Red, {}, 'container' )
|
|
100
|
+
render = true
|
|
101
|
+
task.done ()
|
|
102
|
+
}
|
|
103
|
+
, hide : ({task, dependencies}) => {
|
|
104
|
+
const { html } = dependencies;
|
|
105
|
+
html.destroy ( 'container' )
|
|
106
|
+
task.done ()
|
|
107
|
+
}
|
|
108
|
+
, parents : [ 'blue' ]
|
|
109
|
+
, 'click: 1-left' : ({dependencies,target}) => { // Order in the event name after the prefix is not important
|
|
110
|
+
click = true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
, bluePage = {
|
|
114
|
+
show : ({ task, dependencies }) => {
|
|
115
|
+
const { html } = dependencies;
|
|
116
|
+
html.publish ( Blue, {}, 'blue' )
|
|
117
|
+
task.done ()
|
|
118
|
+
}
|
|
119
|
+
, hide : ({task, dependencies}) => {
|
|
120
|
+
const { html } = dependencies;
|
|
121
|
+
html.destroy ( 'blue' )
|
|
122
|
+
task.done ()
|
|
123
|
+
}
|
|
124
|
+
, 'click: left-1' : ({dependencies,target}) => {}
|
|
125
|
+
}
|
|
126
|
+
;
|
|
127
|
+
script.enablePlugin ( pluginClick )
|
|
128
|
+
d.id = 'root'
|
|
129
|
+
html.publish ( Dummy, {}, 'root' )
|
|
130
|
+
|
|
131
|
+
cy.wait ( 0 )
|
|
132
|
+
.then ( () => {
|
|
133
|
+
script.setDependencies ({ html })
|
|
134
|
+
script.setScenes ([
|
|
135
|
+
{ name:'test' , scene : testScene }
|
|
136
|
+
, { name: 'blue', scene : bluePage }
|
|
137
|
+
])
|
|
138
|
+
script.show ({ scene: 'test' })
|
|
139
|
+
cy.get ( '#target' ).click ()
|
|
140
|
+
})
|
|
141
|
+
.then ( () => {
|
|
142
|
+
expect ( render ).to.be.true
|
|
143
|
+
expect ( click ).to.be.true
|
|
144
|
+
return cy.wait ( 0 )
|
|
145
|
+
})
|
|
146
|
+
.then ( () => {
|
|
147
|
+
return script.hide ( '*' )
|
|
148
|
+
})
|
|
149
|
+
.then ( () => {
|
|
150
|
+
const pageContent = document.getElementById('container').innerHTML
|
|
151
|
+
expect ( pageContent ).to.be.empty
|
|
152
|
+
done ()
|
|
153
|
+
})
|
|
154
|
+
}) // it load a deep level page
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
it ( 'Turn to other branch', done => {
|
|
159
|
+
let
|
|
160
|
+
render = false
|
|
161
|
+
, click = false
|
|
162
|
+
, html = new VisualController ()
|
|
163
|
+
;
|
|
164
|
+
const
|
|
165
|
+
script = cuts ()
|
|
166
|
+
, d = document.querySelector ('[data-cy-root]' )
|
|
167
|
+
, testScene = {
|
|
168
|
+
show : ({ task, dependencies }) => {
|
|
169
|
+
const { html } = dependencies;
|
|
170
|
+
html.publish ( Red, {}, 'subgray' ) // subgray is inside 'blue' component
|
|
171
|
+
render = true
|
|
172
|
+
task.done ()
|
|
173
|
+
}
|
|
174
|
+
, hide : ({task, dependencies}) => {
|
|
175
|
+
const { html } = dependencies;
|
|
176
|
+
html.destroy ( 'subgray' )
|
|
177
|
+
task.done ()
|
|
178
|
+
}
|
|
179
|
+
, parents : [ 'blue' ]
|
|
180
|
+
, 'click: left-1' : ({dependencies,target}) => {
|
|
181
|
+
click = true
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
, bluePage = {
|
|
185
|
+
show : ({ task, dependencies }) => {
|
|
186
|
+
const { html } = dependencies;
|
|
187
|
+
html.publish ( Blue, {}, 'blue' )
|
|
188
|
+
task.done ()
|
|
189
|
+
}
|
|
190
|
+
, hide : ({task, dependencies}) => {
|
|
191
|
+
const { html } = dependencies;
|
|
192
|
+
html.destroy ( 'blue' )
|
|
193
|
+
task.done ()
|
|
194
|
+
}
|
|
195
|
+
, 'click: left-1' : ({dependencies,target}) => {}
|
|
196
|
+
}
|
|
197
|
+
, grayPage = {
|
|
198
|
+
show : ({ task, dependencies }) => {
|
|
199
|
+
const { html } = dependencies;
|
|
200
|
+
html.publish ( Gray, {}, 'subgray' )
|
|
201
|
+
task.done ()
|
|
202
|
+
}
|
|
203
|
+
, hide : ({task, dependencies}) => {
|
|
204
|
+
const { html } = dependencies;
|
|
205
|
+
html.destroy ( 'subgray' )
|
|
206
|
+
task.done ()
|
|
207
|
+
}
|
|
208
|
+
, parents : [ 'blue' ]
|
|
209
|
+
, 'click: left-1' : ({dependencies,target}) => {}
|
|
210
|
+
}
|
|
211
|
+
;
|
|
212
|
+
script.enablePlugin ( pluginClick )
|
|
213
|
+
d.id = 'root'
|
|
214
|
+
html.publish ( Dummy, {}, 'root' )
|
|
215
|
+
|
|
216
|
+
cy.wait ( 0 )
|
|
217
|
+
.then ( () => {
|
|
218
|
+
script.setDependencies ({ html })
|
|
219
|
+
script.setScenes ([
|
|
220
|
+
{ name:'test', scene : testScene }
|
|
221
|
+
, { name: 'blue', scene : bluePage }
|
|
222
|
+
, { name: 'gray', scene : grayPage }
|
|
223
|
+
])
|
|
224
|
+
script.show ({ scene : 'test' })
|
|
225
|
+
cy.get ( '#target' ).click ()
|
|
226
|
+
})
|
|
227
|
+
.then ( () => {
|
|
228
|
+
expect ( render ).to.be.true
|
|
229
|
+
expect ( click ).to.be.true
|
|
230
|
+
return cy.wait ( 0 )
|
|
231
|
+
})
|
|
232
|
+
.then ( () => script.show ({ scene : 'gray' } ))
|
|
233
|
+
.then ( () => {
|
|
234
|
+
const
|
|
235
|
+
red = document.querySelectorAll ( '.red' )
|
|
236
|
+
, blue = document.querySelectorAll ( '.gray' )
|
|
237
|
+
;
|
|
238
|
+
expect ( blue.length ).to.be.equal ( 1 )
|
|
239
|
+
expect ( red.length ).to.be.equal ( 0 )
|
|
240
|
+
done ()
|
|
241
|
+
})
|
|
242
|
+
}) // it turn to other branch
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
it ( 'Jump and jumpBack', done => {
|
|
247
|
+
const
|
|
248
|
+
script = cuts ()
|
|
249
|
+
, myLocations = []
|
|
250
|
+
, testScene = {
|
|
251
|
+
show : ({ task, dependencies }) => {
|
|
252
|
+
myLocations.push ( 'test scene' )
|
|
253
|
+
task.done ()
|
|
254
|
+
}
|
|
255
|
+
, hide : ({task, dependencies}) => task.done ()
|
|
256
|
+
}
|
|
257
|
+
, bluePage = {
|
|
258
|
+
show : ({ task, dependencies }) => {
|
|
259
|
+
myLocations.push ( 'blue scene' )
|
|
260
|
+
task.done ()
|
|
261
|
+
}
|
|
262
|
+
, hide : ({task, dependencies}) => task.done ()
|
|
263
|
+
, 'click: left-1' : ({dependencies,target}) => {}
|
|
264
|
+
}
|
|
265
|
+
, grayPage = {
|
|
266
|
+
show : ({ task, dependencies }) => {
|
|
267
|
+
myLocations.push ( 'gray scene' )
|
|
268
|
+
task.done ()
|
|
269
|
+
}
|
|
270
|
+
, hide : ({task, dependencies}) => task.done ()
|
|
271
|
+
}
|
|
272
|
+
;
|
|
273
|
+
|
|
274
|
+
script.setScenes ([
|
|
275
|
+
{ name:'test', scene : testScene }
|
|
276
|
+
, { name: 'blue', scene : bluePage }
|
|
277
|
+
, { name: 'gray', scene : grayPage }
|
|
278
|
+
])
|
|
279
|
+
|
|
280
|
+
script.show ({ scene : 'test' })
|
|
281
|
+
.then ( () => script.jump ({ scene : 'blue' })) // Go from test to blue. Remember 'test'
|
|
282
|
+
.then ( () => script.jump ({ scene : 'gray' })) // Go from blue to gray. Remember 'blue'
|
|
283
|
+
.then ( () => script.jumpBack ()) // Go back to blue. Taken from the stack
|
|
284
|
+
.then ( () => script.jumpBack ()) // Go back to test. Taken from the stack
|
|
285
|
+
.then ( () => script.jumpBack ()) // this should do nothing - no more back hops in stack
|
|
286
|
+
.then ( () => {
|
|
287
|
+
expect ( myLocations ).to.be.deep.equal ([
|
|
288
|
+
'test scene',
|
|
289
|
+
'blue scene',
|
|
290
|
+
'gray scene',
|
|
291
|
+
'blue scene',
|
|
292
|
+
'test scene'
|
|
293
|
+
])
|
|
294
|
+
done ()
|
|
295
|
+
})
|
|
296
|
+
}) // it jump
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
it ( 'Jump and jumpsReset', done => {
|
|
301
|
+
const
|
|
302
|
+
script = cuts ()
|
|
303
|
+
, myLocations = []
|
|
304
|
+
, testScene = {
|
|
305
|
+
show : ({ task, dependencies }) => {
|
|
306
|
+
myLocations.push ( 'test scene' )
|
|
307
|
+
task.done ()
|
|
308
|
+
}
|
|
309
|
+
, hide : ({task, dependencies}) => task.done ()
|
|
310
|
+
}
|
|
311
|
+
, bluePage = {
|
|
312
|
+
show : ({ task, dependencies }) => {
|
|
313
|
+
myLocations.push ( 'blue scene' )
|
|
314
|
+
task.done ()
|
|
315
|
+
}
|
|
316
|
+
, hide : ({task, dependencies}) => task.done ()
|
|
317
|
+
, 'click: left-1' : ({dependencies,target}) => {}
|
|
318
|
+
}
|
|
319
|
+
, grayPage = {
|
|
320
|
+
show : ({ task, dependencies }) => {
|
|
321
|
+
myLocations.push ( 'gray scene' )
|
|
322
|
+
task.done ()
|
|
323
|
+
}
|
|
324
|
+
, hide : ({task, dependencies}) => task.done ()
|
|
325
|
+
}
|
|
326
|
+
;
|
|
327
|
+
|
|
328
|
+
script.setScenes ([
|
|
329
|
+
{ name:'test', scene : testScene }
|
|
330
|
+
, { name: 'blue', scene : bluePage }
|
|
331
|
+
, { name: 'gray', scene : grayPage }
|
|
332
|
+
])
|
|
333
|
+
|
|
334
|
+
script.show ({ scene : 'test' })
|
|
335
|
+
.then ( () => script.jump ({ scene : 'blue' })) // Go from test to blue. Remember 'test'
|
|
336
|
+
.then ( () => script.jump ({ scene : 'gray' })) // Go from blue to gray. Remember 'blue'
|
|
337
|
+
.then ( () => script.jumpsReset () ) // Clear the jump stack
|
|
338
|
+
.then ( () => script.jumpBack ()) // This should do nothing - no back hops
|
|
339
|
+
.then ( () => {
|
|
340
|
+
expect ( myLocations ).to.be.deep.equal ([
|
|
341
|
+
'test scene',
|
|
342
|
+
'blue scene',
|
|
343
|
+
'gray scene',
|
|
344
|
+
])
|
|
345
|
+
done ()
|
|
346
|
+
})
|
|
347
|
+
}) // it jump
|
|
348
|
+
}) // describe
|
package/test/blue.vue
ADDED
package/test/dummy.vue
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<h1>Test</h1>
|
|
4
|
+
<p id="target">Test <a href="#">lorem ipsum</a></p>
|
|
5
|
+
<div id="container">
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
<div id="blue"></div>
|
|
9
|
+
<div id="gray"></div>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
:root {
|
|
15
|
+
--blue: #007bff;
|
|
16
|
+
--gray: #6c757d;
|
|
17
|
+
--link-color: rgb(204, 51, 10);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
body.dark {
|
|
21
|
+
--background-color: #000;
|
|
22
|
+
--link-color: rgb(249, 249, 249);
|
|
23
|
+
background-color: var(--background-color);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#target {
|
|
27
|
+
--blue: var(--link-color);
|
|
28
|
+
color: var(--blue);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#target a {
|
|
32
|
+
color: var(--link-color);
|
|
33
|
+
}
|
|
34
|
+
</style>
|