Skip to content

Commit 2eb6aaa

Browse files
Add a jumping test to the in-browser test suite
1 parent d195337 commit 2eb6aaa

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

packages/library/test/core.js

+43
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,49 @@ describe('Core', () => {
12181218
)
12191219
})
12201220
})
1221+
1222+
describe('jumping', () => {
1223+
let demoElement
1224+
beforeEach(() => {
1225+
demoElement = document.createElement('div')
1226+
demoElement.dataset.labjsSection = 'main'
1227+
document.body.appendChild(demoElement)
1228+
})
1229+
1230+
afterEach(() => {
1231+
document.body.removeChild(demoElement)
1232+
})
1233+
1234+
it('can jump around', async () => {
1235+
const a = new lab.html.Screen({ content: 'a', id: 'a' })
1236+
const b = new lab.html.Screen({ content: 'b', id: 'b' })
1237+
const c = new lab.html.Screen({ content: 'c', id: 'c' })
1238+
const d = new lab.html.Screen({ content: 'd', id: 'd' })
1239+
1240+
const s_nested = new lab.flow.Sequence({ content: [a, b, c, d], id: 's_nested' })
1241+
const t = new lab.html.Screen({ content: 't', id: 't' })
1242+
const s = new lab.flow.Sequence({ content: [s_nested, t], el: demoElement, id: 's' })
1243+
1244+
const jumpTo = async (targetStack) => {
1245+
await s.internals.controller.jump('jump', { targetStack })
1246+
}
1247+
1248+
await s.run()
1249+
assert.equal(demoElement.innerText, 'a')
1250+
1251+
await jumpTo(['s_nested', 'b'])
1252+
assert.equal(demoElement.innerText, 'b')
1253+
1254+
await b.end()
1255+
assert.equal(demoElement.innerText, 'c')
1256+
1257+
await jumpTo(['t'])
1258+
assert.equal(demoElement.innerText, 't')
1259+
1260+
await jumpTo(['s_nested', 'b'])
1261+
assert.equal(demoElement.innerText, 'b')
1262+
})
1263+
})
12211264
})
12221265

12231266
})

0 commit comments

Comments
 (0)