90 lines
4.4 KiB
JavaScript
90 lines
4.4 KiB
JavaScript
|
|
// Every menu page and workshop tool once, in the real browser, offline (file://) - guards the game.js split:
|
||
|
|
// a missing reference between the modules shows up here as a JavaScript error.
|
||
|
|
'use strict';
|
||
|
|
const { test, expect } = require('@playwright/test');
|
||
|
|
const path = require('path');
|
||
|
|
const { pathToFileURL } = require('url');
|
||
|
|
|
||
|
|
const file = pathToFileURL(path.join(__dirname, '..', '..', 'game', 'index.html')).href;
|
||
|
|
const { credits: money } = require('./helpers');
|
||
|
|
|
||
|
|
test.beforeEach(async ({ page }) => {
|
||
|
|
page.errors = [];
|
||
|
|
page.on('pageerror', e => page.errors.push(e.message));
|
||
|
|
await page.goto(file + '?play');
|
||
|
|
await expect(page.locator('body')).toHaveAttribute('data-mode', 'garage');
|
||
|
|
});
|
||
|
|
test.afterEach(async ({ page }) => { expect(page.errors, 'no JavaScript errors').toEqual([]); });
|
||
|
|
|
||
|
|
test('menu pages: settings, controls, legal, achievements, missions', async ({ page }) => {
|
||
|
|
await page.locator('#bSettings').click();
|
||
|
|
await expect(page.locator('#sKeys')).toBeVisible();
|
||
|
|
await page.locator('#sKeys').click(); // controls page from settings
|
||
|
|
await page.locator('#bOk').click();
|
||
|
|
await expect(page.locator('#sLegal')).toBeVisible(); // back in settings
|
||
|
|
await page.locator('#sLegal').click();
|
||
|
|
await page.locator('#bOk').click();
|
||
|
|
await page.locator('#bBack').click();
|
||
|
|
await expect(page.locator('body')).toHaveAttribute('data-mode', 'garage');
|
||
|
|
|
||
|
|
await page.locator('#chipFame').click(); // achievements
|
||
|
|
await expect(page.locator('.achlist')).toBeVisible();
|
||
|
|
await page.locator('#bBack').click();
|
||
|
|
|
||
|
|
await page.locator('#bMissions').click(); // campaign missions
|
||
|
|
await expect(page.locator('.misslist').first()).toBeVisible();
|
||
|
|
await page.locator('#bBack').click();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('guest via the title: country, tutorial, then dev coins go through the economy', async ({ page }) => {
|
||
|
|
await page.goto(file + '?title');
|
||
|
|
await page.locator('#bGuest').click();
|
||
|
|
await page.locator('#cfGo').click(); // country card
|
||
|
|
await page.locator('#tSkip').click(); // tutorial cards
|
||
|
|
await expect(page.locator('body')).toHaveAttribute('data-mode', 'garage');
|
||
|
|
await page.locator('#bSettings').click();
|
||
|
|
await page.locator('[data-coin="10000"]').click();
|
||
|
|
await page.locator('#bBack').click();
|
||
|
|
expect(await money(page)).toBeGreaterThanOrEqual(10800);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('weapon editor: buy, place, sell a weapon', async ({ page }) => {
|
||
|
|
const start = await money(page);
|
||
|
|
await page.locator('.tab[data-slot="weapon"]').click();
|
||
|
|
await expect(page.locator('#wplace')).toBeVisible();
|
||
|
|
const before = await page.locator('.wphead').first().textContent();
|
||
|
|
await page.locator('#cards .item:not(:has(.pr.no))').first().click();
|
||
|
|
await page.locator('#detail button[data-wact="add"]').click();
|
||
|
|
expect(await money(page)).toBeLessThan(start);
|
||
|
|
await expect(page.locator('.wphead').first()).not.toHaveText(before); // weapon count went up
|
||
|
|
await page.locator('[data-side="left"]').click();
|
||
|
|
await expect(page.locator('[data-side="left"]')).toHaveClass(/on/);
|
||
|
|
await page.locator('#detail button[data-wact="rem"]').click();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('paint tab: colour, scheme, paint slots', async ({ page }) => {
|
||
|
|
await page.locator('#shopTabs [data-tab="paint"]').click();
|
||
|
|
await expect(page.locator('#paintHdr')).toBeVisible();
|
||
|
|
await page.locator('#paintBody .sw:not(.locked)').nth(2).click();
|
||
|
|
await expect(page.locator('#paintBody .sw.on')).toHaveCount(1);
|
||
|
|
await page.locator('#paintSchemes .sw').nth(1).click();
|
||
|
|
await page.locator('[data-save="1"]').click(); // store into slot 2
|
||
|
|
await page.locator('[data-load="0"]').click(); // load slot 1
|
||
|
|
await expect(page.locator('.pslot.on')).toHaveCount(1);
|
||
|
|
await page.locator('#shopTabs [data-tab="build"]').click();
|
||
|
|
await expect(page.locator('#paintHdr')).toHaveCount(0);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('hangar: new robot, switch, delete', async ({ page }) => {
|
||
|
|
await page.locator('#shopTabs [data-tab="hangar"]').click();
|
||
|
|
await expect(page.locator('.hmrow')).toHaveCount(1);
|
||
|
|
await page.locator('#hAdd').click();
|
||
|
|
await page.locator('#shopTabs [data-tab="hangar"]').click();
|
||
|
|
await expect(page.locator('.hmrow')).toHaveCount(2);
|
||
|
|
await page.locator('[data-use="0"]').click();
|
||
|
|
await page.locator('#shopTabs [data-tab="hangar"]').click();
|
||
|
|
await expect(page.locator('.hmrow.on')).toHaveAttribute('data-i', '0');
|
||
|
|
await page.locator('[data-del="1"]').click();
|
||
|
|
await expect(page.locator('.hmrow')).toHaveCount(1);
|
||
|
|
});
|