tools/client/test_token_board_wear.mjs (4471B)
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 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 11 let game; 12 const evidence = {}; 13 try { 14 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 15 await context.addCookies([{name: 'ao_client', value: 'token-board-wear', url}]); 16 const page = await context.newPage(); 17 game = await GameTest.attach(page); 18 const server = async () => (await page.request.get(url + '/test-state')).json(); 19 const carried = state => state.grids.flatMap(grid => grid.cells).find(cell => 20 cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy); 21 await page.goto(url); 22 await game.ready(); 23 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 24 await game.snapshot(); 25 await game.key('i'); 26 await page.keyboard.press('Control+1'); 27 await game.click(953, 53); 28 await game.snapshot(); 29 evidence.before = await server(); 30 evidence.foundations = [game.local().stats[1], game.local().stats[221]]; 31 assert.deepEqual([game.local().stats[62], game.local().stats[75]], 32 [evidence.before.Inventory.ClanTokens, evidence.before.Inventory.OmniTokens]); 33 34 for (const slot of [17, 64, 17]) { 35 const sequence = game.sequence; 36 if (slot === 17) { 37 const cell = carried(game.state); 38 assert(cell, 'the original board source must remain usable'); 39 await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); 40 await game.wait('carried board picked', state => state.dragged[0] === 104 && state.dragged[1] === 48); 41 await game.click(867, 94); 42 } else { 43 await game.click(867, 94); 44 await game.wait('worn board picked', state => state.dragged[0] === 102 && state.dragged[1] === 17); 45 const cell = game.state.grids.find(grid => grid.totalCells === 30).cells.find(cell => cell.identity[0] === 0); 46 await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); 47 } 48 await game.wait('actual board wear/removal request', () => game.events.some(event => 49 event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24')); 50 await game.wait('board placement completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === (slot === 64 ? 48 : 17))); 51 const state = await server(); 52 assert.deepEqual(state.Inventory.Items.map(item => [item.ID, item.Template, item.Quality, item.Slot]), 53 [[1, evidence.before.Inventory.Items[0].Template, evidence.before.Inventory.Items[0].Quality, slot]]); 54 assert.deepEqual([state.Inventory.ClanTokens, state.Inventory.OmniTokens], 55 [evidence.before.Inventory.ClanTokens, evidence.before.Inventory.OmniTokens]); 56 assert.deepEqual([game.local().stats[1], game.local().stats[221]], evidence.foundations); 57 evidence[slot === 64 ? 'removed' : evidence.worn ? 'reworn' : 'worn'] = state; 58 await page.keyboard.press('Control+9'); 59 const statsOpen = current => current.regions.some(([left, top, right, bottom]) => 60 left === 832 && top === 380 && right === 1024 && bottom === 606); 61 await game.wait('native Stats panel opens', statsOpen); 62 await game.save(output + '/' + (slot === 64 ? 'removed' : evidence.reworn ? 'reworn' : 'worn')); 63 await page.keyboard.press('Control+9'); 64 await game.wait('native Stats panel closes', current => !statsOpen(current)); 65 } 66 67 await page.reload(); 68 await game.ready(); 69 assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[1, 17]]); 70 assert.deepEqual([game.local().stats[1], game.local().stats[221]], evidence.foundations); 71 assert.equal(game.errors.length, 0); 72 console.log('PASS: exact token-board wear/remove/rewear, raw foundations, counters and page/cold ownership'); 73 } finally { 74 try { 75 await fs.mkdir(output, {recursive: true}); 76 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 77 if (game) await game.save(output + '/final'); 78 } finally { await browser.close(); } 79 }