|
1 | 1 | /// <reference types="cypress" />
|
| 2 | +import type { AppOptions } from '../../src/optionsStorage' |
2 | 3 |
|
3 |
| -const setLocalStorageSettings = () => { |
| 4 | +const cleanVisit = () => { |
| 5 | + window.localStorage.clear() |
| 6 | + visit() |
| 7 | +} |
| 8 | + |
| 9 | +const visit = (url = '/') => { |
4 | 10 | window.localStorage.cypress = 'true'
|
5 |
| - window.localStorage.server = 'localhost' |
| 11 | + cy.visit(url) |
6 | 12 | }
|
7 | 13 |
|
8 | 14 | // todo use ssl
|
9 | 15 |
|
| 16 | +const compareRenderedFlatWorld = () => { |
| 17 | + // wait for render |
| 18 | + // cy.wait(6000) |
| 19 | + // cy.get('body').toMatchImageSnapshot({ |
| 20 | + // name: 'superflat-world', |
| 21 | + // }) |
| 22 | +} |
| 23 | + |
| 24 | +const testWorldLoad = () => { |
| 25 | + cy.document().then({ timeout: 20_000, }, doc => { |
| 26 | + return new Cypress.Promise(resolve => { |
| 27 | + doc.addEventListener('cypress-world-ready', resolve) |
| 28 | + }) |
| 29 | + }).then(() => { |
| 30 | + compareRenderedFlatWorld() |
| 31 | + }) |
| 32 | +} |
| 33 | + |
| 34 | +const setOptions = (options: Partial<AppOptions>) => { |
| 35 | + cy.window().then(win => { |
| 36 | + Object.assign(win['options'], options) |
| 37 | + }) |
| 38 | +} |
| 39 | + |
10 | 40 | it('Loads & renders singleplayer', () => {
|
11 |
| - cy.visit('/') |
12 |
| - window.localStorage.clear() |
13 |
| - window.localStorage.setItem('renderDistance', '2') |
14 |
| - window.localStorage.setItem('options', JSON.stringify({ |
| 41 | + cleanVisit() |
| 42 | + setOptions({ |
15 | 43 | localServerOptions: {
|
16 | 44 | generation: {
|
17 | 45 | name: 'superflat',
|
18 | 46 | options: { seed: 250869072 }
|
19 |
| - } |
20 |
| - } |
21 |
| - })) |
22 |
| - setLocalStorageSettings() |
23 |
| - cy.get('#title-screen').find('[data-test-id="singleplayer-button"]', { includeShadowDom: true, }).click() |
24 |
| - // todo implement load event |
25 |
| - cy.wait(12000) |
26 |
| - cy.get('body').toMatchImageSnapshot({ |
27 |
| - name: 'superflat-world', |
| 47 | + }, |
| 48 | + }, |
| 49 | + renderDistance: 2 |
28 | 50 | })
|
| 51 | + cy.get('#title-screen').find('[data-test-id="singleplayer-button"]', { includeShadowDom: true, }).click() |
| 52 | + testWorldLoad() |
29 | 53 | })
|
30 | 54 |
|
31 | 55 | it('Joins to server', () => {
|
32 |
| - cy.visit('/') |
33 |
| - setLocalStorageSettings() |
| 56 | + // visit('/?version=1.16.1') |
| 57 | + window.localStorage.version = '1.16.1' |
| 58 | + visit() |
34 | 59 | // todo replace with data-test
|
35 | 60 | cy.get('#title-screen').find('[data-test-id="connect-screen-button"]', { includeShadowDom: true, }).click()
|
36 | 61 | cy.get('input#serverip', { includeShadowDom: true, }).clear().focus().type('localhost')
|
37 | 62 | cy.get('[data-test-id="connect-to-server"]', { includeShadowDom: true, }).click()
|
38 |
| - // todo implement load event |
39 |
| - cy.wait(12000) |
40 |
| - cy.get('body').toMatchImageSnapshot({ |
41 |
| - name: 'superflat-world', |
42 |
| - }) |
| 63 | + testWorldLoad() |
43 | 64 | })
|
44 | 65 |
|
45 | 66 | it('Loads & renders zip world', () => {
|
46 |
| - cy.visit('/') |
47 |
| - setLocalStorageSettings() |
| 67 | + cleanVisit() |
48 | 68 | cy.get('#title-screen').find('[data-test-id="select-file-folder"]', { includeShadowDom: true, }).click({ shiftKey: true })
|
49 | 69 | cy.get('input[type="file"]').selectFile('cypress/superflat.zip', { force: true })
|
50 |
| - // todo implement load event |
51 |
| - cy.wait(12000) |
52 |
| - cy.get('body').toMatchImageSnapshot({ |
53 |
| - name: 'superflat-world', |
54 |
| - }) |
| 70 | + testWorldLoad() |
55 | 71 | })
|
56 | 72 |
|
57 | 73 | it.skip('Performance test', () => {
|
58 |
| - cy.visit('/') |
59 |
| - window.localStorage.cypress = 'true' |
60 |
| - window.localStorage.setItem('renderDistance', '6') |
61 |
| - cy.get('#title-screen').find('.menu > div:nth-child(2) > pmui-button:nth-child(1)', { includeShadowDom: true, }).selectFile('worlds') |
62 |
| - // -2 85 24 |
| 74 | + // select that world |
| 75 | + // from -2 85 24 |
63 | 76 | // await bot.loadPlugin(pathfinder.pathfinder)
|
64 | 77 | // bot.pathfinder.goto(new pathfinder.goals.GoalXZ(28, -28))
|
65 | 78 | })
|
0 commit comments