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