Files
Robot-Clash/tests/e2e/offline.spec.js

29 lines
1.4 KiB
JavaScript

// The offline campaign must keep working without any server (double-click on game/index.html = file://).
'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;
test('campaign runs from file:// : training fight with the AI pilot, layout check passes', async ({ page }) => {
const errors = [];
page.on('pageerror', e => errors.push(e.message));
await page.goto(file + '?play&fight=2&auto&ff=20&uicheck');
await expect(page.locator('body')).toHaveAttribute('data-gmode', 'campaign');
await expect(page.locator('body')).toHaveAttribute('data-mode', /fight|result/);
await expect(page.locator('#uicheck')).toContainText('UI ok');
expect(errors).toEqual([]);
});
test('campaign workshop: buying a part works offline', async ({ page }) => {
await page.goto(file + '?play');
await expect(page.locator('body')).toHaveAttribute('data-mode', 'garage');
const money = async () => Number((await page.locator('#hMoney').textContent()).replace(/[^\d]/g, ''));
const before = await money();
await page.locator('.tab[data-slot="armour"]').click();
await page.locator('#cards .item:not(:has(.badge)):not(:has(.pr.no))').first().click();
await page.locator('#detail button[data-act="buy"]').click();
expect(await money()).toBeLessThan(before);
});