/
history-state.js
56 lines (50 loc) 路 1.89 KB
/
history-state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const bsStatus = require('../browserstack-send-status')
module.exports = {
...bsStatus(),
'@tags': ['history'],
'history state': function (browser) {
browser
.url('http://localhost:8080/scroll-behavior/')
.waitForElementVisible('#app', 1000)
.execute(function () {
window.scrollTo(0, 100)
const key = window.history.state.key
window.history.replaceState({ key, foo: 'foo' }, '', window.location.pathname)
})
.url('http://localhost:8080/scroll-behavior/')
.waitForElementVisible('#app', 1000)
.assert.evaluate(function () {
return window.history.state.foo === 'foo'
}, null, 'keeps existing state when reloading')
// check on navigation
.url('http://localhost:8080/basic/')
.click('li:nth-child(2) a')
.assert.urlEquals('http://localhost:8080/basic/foo')
.execute(function () {
window.scrollTo(0, 100)
const key = window.history.state.key
window.history.replaceState({ key, foo: 'foo' }, '', window.location.pathname)
})
.click('li:nth-child(3) a')
.assert.urlEquals('http://localhost:8080/basic/bar')
.execute(function () {
window.history.back()
})
.assert.evaluate(function () {
return window.history.state.foo === 'foo'
}, null, 'keeps existing state when navigating back')
.click('li:nth-child(3) a')
.assert.urlEquals('http://localhost:8080/basic/bar')
.execute(function () {
window.scrollTo(0, 100)
const key = window.history.state.key
window.history.replaceState({ key, bar: 'bar' }, '', window.location.pathname)
})
.click('li:nth-child(9) a')
.assert.urlEquals('http://localhost:8080/basic/foo')
.assert.evaluate(function () {
return window.history.state.bar === 'bar'
}, null, 'keeps existing state when replacing')
.end()
}
}