tools/client/test_options_resize.mjs (2431B)
1 import assert from 'node:assert/strict'; 2 import fs from 'node:fs/promises'; 3 import {createRequire} from 'node:module'; 4 import {GameTest} from './game_test.mjs'; 5 6 const {chromium} = createRequire(import.meta.url)('playwright'); 7 const [url, output] = process.argv.slice(2); 8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ 9 '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage']}); 10 let game; 11 const observations = []; 12 try { 13 const page = await browser.newPage({viewport: {width: 1280, height: 900}}); 14 game = await GameTest.attach(page); 15 await page.goto(url); 16 await game.ready(); 17 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 18 for (const [width, height] of [[1280, 900], [800, 600], [640, 480], [390, 500], [320, 480], [1600, 900], [1024, 768]]) { 19 await page.setViewportSize({width, height}); 20 await game.wait('native viewport resized', state => state.screen[0] === width && state.screen[1] === height); 21 const bounds = await page.locator('#menu-button').boundingBox(); 22 const observation = {width, height, bounds, layout: await page.evaluate(() => ({ 23 hidden: document.querySelector('#game-toolbar').hidden, 24 right: document.querySelector('#game-toolbar').style.right, touchRegions}))}; 25 observations.push(observation); 26 console.log('RESIZE', width, height, bounds, observation.layout.right); 27 assert(bounds && bounds.x >= 0 && bounds.x + bounds.width <= width && bounds.y >= 0 && bounds.y + bounds.height <= height); 28 // The original top strip is 192 native pixels wide in CSS-pixel mode. 29 assert.equal(bounds.x + bounds.width, width - 192 - 6); 30 await page.mouse.move(width - 210, 12); 31 await page.waitForFunction(() => getComputedStyle(document.querySelector('#menu-button')).opacity === '1'); 32 await page.locator('#menu-button').click(); 33 assert(await page.locator('#player-menu').evaluate(menu => menu.open)); 34 await page.locator('#player-menu').getByRole('button', {name: 'Close', exact: true}).click(); 35 await game.save(output + '/' + width + 'x' + height); 36 } 37 assert.deepEqual(game.errors, []); 38 } finally { 39 try { 40 await fs.mkdir(output, {recursive: true}); 41 await fs.writeFile(output + '/observations.json', JSON.stringify(observations, null, 2) + '\n'); 42 if (game) await game.save(output + '/final'); 43 } finally { await browser.close(); } 44 }