aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/test_item_sources.mjs (9375B)


      1 import assert from 'node:assert/strict';
      2 import {createRequire} from 'node:module';
      3 
      4 const {chromium} = createRequire(import.meta.url)('playwright');
      5 const url = process.argv[2];
      6 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: ['--no-sandbox']});
      7 try {
      8   const page = await browser.newPage();
      9   const errors = [];
     10   const liveFeeds = [];
     11   page.on('pageerror', error => errors.push(error.message));
     12   page.on('request', request => {
     13     if (/admin\/map-(players|entities)/.test(request.url())) liveFeeds.push(request.url());
     14   });
     15 
     16   // The catalog exposes configured odds and the distinction between observations and inference.
     17   await page.goto(url + 'admin/items/catalog?source=loot&catalog=136627');
     18   const ruby = page.locator('tr').filter({has: page.locator("button[value='136627']")});
     19   assert.match(await ruby.textContent(), /Loot: \d+.*35%.*Inferred/);
     20   await ruby.locator("a[href='admin/items/catalog/136627']").click();
     21   await page.waitForLoadState('domcontentloaded');
     22   assert(await page.locator('main').textContent().then(text => text.includes('AORebirth') && text.includes('Ruby on Writhetongue')));
     23   assert.equal(await page.locator('[data-world-map][data-map-overview]').count(), 1);
     24   const nestedScrollers = await page.locator('main *').evaluateAll(elements => elements.filter(element => {
     25     const style = getComputedStyle(element);
     26     return /(auto|scroll)/.test(style.overflowY) && element.scrollHeight > element.clientHeight;
     27   }).length);
     28   assert.equal(nestedScrollers, 0, 'item detail must use ordinary page scrolling');
     29 
     30   await page.goto(url + 'admin/items/catalog/147073');
     31   assert.match(await page.locator('main').textContent(), /Pool selection.*eligible families.*Item probability varies with NPC level/);
     32   assert.equal(await page.locator('[data-world-map][data-map-overview]').count(), 1);
     33   assert.equal(await page.locator('main *').evaluateAll(elements => elements.filter(element => {
     34     const style = getComputedStyle(element);
     35     return /(auto|scroll)/.test(style.overflowY) && element.scrollHeight > element.clientHeight;
     36   }).length), 0, 'pooled source locations must use ordinary page scrolling');
     37 
     38   for (const path of ['admin/items/catalog/95577', 'admin/shops/99491']) {
     39     await page.goto(url + path);
     40     if (path === 'admin/items/catalog/95577') {
     41       assert.equal(await page.locator('[data-world-map], [data-item-sources]').count(), 2);
     42       assert(JSON.parse(await page.locator('[data-item-sources]').textContent()).some(source => source.vending));
     43       const link = page.locator('a[href^="admin/map?playfield=705&"]').filter({hasText: 'entrance'}).first();
     44       const destination = new URL(await link.getAttribute('href'), url);
     45       await link.click();
     46       assert.equal(page.url(), destination.href);
     47       await page.waitForFunction(({x, z}) => document.querySelector('[data-map-location]').textContent.includes(
     48         `(705), X ${Number(x).toFixed(1)}, Z ${Number(z).toFixed(1)}.`), Object.fromEntries(destination.searchParams));
     49       await page.waitForFunction(() => {
     50         const canvas = document.querySelector('canvas');
     51         const pixel = canvas.getContext('2d').getImageData(canvas.width / 2, canvas.height / 2, 1, 1).data;
     52         return pixel[0] === 33 && pixel[1] === 219 && pixel[2] === 135;
     53       });
     54       continue;
     55     }
     56     liveFeeds.length = 0;
     57     await page.waitForFunction(() => document.querySelector('[data-map-status]').textContent.startsWith('Drag to pan.'));
     58     const sources = JSON.parse(await page.locator('[data-item-sources]').textContent());
     59     const trade = sources.findIndex(source => source.playfield === 705 && source.name.includes('entrance'));
     60     const other = sources.findIndex(source => source.playfield !== 705 && source.name.includes('entrance'));
     61     assert(trade >= 0 && other >= 0, 'shared shop interiors must list entrances in multiple cities');
     62 
     63     for (const index of [other, trade]) {
     64       await page.locator(`[data-map-source='${index}']`).click();
     65 
     66       const source = sources[index];
     67       await page.waitForFunction(({name, playfield, position}) => {
     68         const label = document.querySelector('[data-map-location]').textContent;
     69         return label.startsWith(name) && label.includes(`(${playfield}), X ${position[0].toFixed(1)}, Z ${position[2].toFixed(1)}.`);
     70       }, source);
     71       // The selected entrance must render at the canvas center, not just update its label.
     72       await page.waitForFunction(() => {
     73         const canvas = document.querySelector('canvas');
     74         const pixel = canvas.getContext('2d').getImageData(canvas.width / 2, canvas.height / 2, 1, 1).data;
     75         return pixel[0] === 85 && pixel[1] === 184 && pixel[2] === 255;
     76       });
     77       assert.equal(page.url(), url + path);
     78     }
     79     assert.equal(await page.locator('[data-world-map] select, [data-world-map] button, [data-world-map] input').count(), 0);
     80     assert.equal(await page.locator('[data-map-source]').count(), sources.length);
     81   }
     82   assert.deepEqual(liveFeeds, []);
     83   assert.deepEqual(errors, []);
     84 
     85   // Interior loot links must focus the outdoor entrance on the Rubi-Ka map.
     86   await page.goto(url + 'admin/items/catalog/200199');
     87   await page.waitForFunction(() => document.querySelector('[data-map-status]').textContent.startsWith('Drag to pan.'));
     88   const overview = JSON.parse(await page.locator('[data-item-sources]').textContent());
     89   const manifest = await page.evaluate(async () => (await fetch('admin/map-assets/manifest.json')).json());
     90   const outdoor = new Set(manifest.zones.filter(zone => zone.origin).map(zone => zone.id));
     91   const links = await page.locator('a[href^="admin/map?playfield="]').evaluateAll(elements => elements.map(link => link.href));
     92   const expected = links.map(link => new URL(link).searchParams).filter(query => outdoor.has(Number(query.get('playfield'))))
     93     .map(query => `${query.get('playfield')}:${Number(query.get('x'))}:${Number(query.get('z'))}`);
     94   const markers = overview.map(source => `${source.playfield}:${source.position[0]}:${source.position[2]}`);
     95   assert.deepEqual(markers.toSorted(), [...new Set(expected)].toSorted());
     96   assert.equal(markers.filter(point => point === '505:2092.2458:3821.6997').length, 1);
     97   assert.equal(overview.find(source => source.playfield === 505 && source.position[0] === 2092.2458).loot, true);
     98   assert.match(await page.getByLabel('Map legend', {exact: true}).textContent(), /Loot.*Vending/);
     99   assert.equal(await page.locator('[data-world-map]').count(), 1);
    100   assert.equal(await page.locator('[data-map-source]').count(), 0, 'overview must not repeat the source list');
    101   assert.equal(await page.locator('[data-map-overview] canvas').evaluate(canvas => canvas.clientHeight), 240);
    102   await page.setViewportSize({width: 390, height: 844});
    103   assert.equal(await page.locator('[data-map-overview] canvas').evaluate(canvas => canvas.clientHeight), 240);
    104   await page.setViewportSize({width: 1280, height: 720});
    105 
    106   const tarasque = page.getByRole('link', {name: 'Tarasque (levels 200-200) - Camelot entrance - Avalon (505), X 2092.2 Z 3821.7', exact: true}).first();
    107   const viewportRequest = page.waitForRequest(request => request.url().includes('admin/map-entities?view=world&'));
    108 
    109   await tarasque.click();
    110   const viewport = new URL((await viewportRequest).url()).searchParams;
    111   await page.waitForFunction(() => {
    112     const canvas = document.querySelector('canvas');
    113     const pixel = canvas.getContext('2d').getImageData(canvas.width / 2, canvas.height / 2, 1, 1).data;
    114     return pixel[0] === 33 && pixel[1] === 219 && pixel[2] === 135;
    115   });
    116   await page.waitForFunction(() => {
    117     const canvas = document.querySelector('canvas');
    118     const pixel = canvas.getContext('2d').getImageData(canvas.width / 2 + 100, canvas.height / 2 + 100, 1, 1).data;
    119     return pixel[0] !== 34 || pixel[1] !== 34 || pixel[2] !== 34;
    120   });
    121 
    122   assert.equal(page.url(), url + 'admin/map?playfield=505&x=2092.2458&z=3821.6997');
    123   assert.equal(await page.locator('[data-map-view]').inputValue(), 'world');
    124   assert.doesNotMatch(await page.locator('[data-map-status]').textContent(), /No extracted imagery/);
    125   assert.match(await page.locator('[data-map-location]').textContent(), /Avalon \(505\), X 2092.2, Z 3821.7/);
    126   assert(Math.abs((Number(viewport.get('left')) + Number(viewport.get('right'))) / 2 - 37306.2458) < 0.00001);
    127   assert(Math.abs((Number(viewport.get('bottom')) + Number(viewport.get('top'))) / 2 - 48387.6997) < 0.00001);
    128   assert.equal(Number(viewport.get('right')) - Number(viewport.get('left')),
    129     await page.locator('canvas').evaluate(canvas => canvas.clientWidth));
    130   assert.deepEqual(errors, []);
    131 
    132   // General map controls still select and render standalone outdoor playfields.
    133   await page.goto(url + 'admin/map');
    134   await page.locator('[data-map-view] option[value="950"]').waitFor({state: 'attached'});
    135   await page.locator('[data-map-view]').selectOption('950');
    136   await page.waitForRequest(request => request.url().includes('admin/map-entities?view=950&'));
    137   await page.locator('[data-map-find]').selectOption('705');
    138   await page.waitForFunction(() => document.querySelector('[data-map-view]').value === 'world');
    139   assert.deepEqual(errors, []);
    140   console.log('Item overviews deduplicate overworld locations; source links, shop maps and general map controls still work.');
    141 } finally {
    142   await browser.close();
    143 }