aorecomp

Anarchy Online classic in the browser

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


tools/client/test_admin_lists.mjs (2577B)


      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 
     10   await page.goto(url + 'admin/players');
     11   await page.getByRole('columnheader', {name: 'ID', exact: true}).getByRole('link').click();
     12   await page.getByRole('columnheader', {name: 'ID [asc]', exact: true}).getByRole('link').click();
     13   await page.getByRole('link', {name: 'Next', exact: true}).first().click();
     14 
     15   assert.equal(new URL(page.url()).pathname, '/share/test/admin/players');
     16   assert.equal(await page.locator('tbody tr').count(), 2);
     17   assert.equal(await page.locator('tbody tr td').first().textContent(), '2');
     18 
     19   // Filtering resets the page while keeping the selected sort direction.
     20   await page.getByLabel('Filter', {exact: true}).fill('player');
     21   await page.getByRole('button', {name: 'Filter', exact: true}).click();
     22   assert.equal(await page.locator('tbody tr').count(), 1000);
     23   assert.equal(await page.locator('tbody tr td').first().textContent(), '1000');
     24   assert.equal(new URL(page.url()).searchParams.get('dir'), 'desc');
     25   assert.equal(new URL(page.url()).searchParams.get('page'), null);
     26   await page.getByLabel('Filter', {exact: true}).fill('(empty)');
     27   await page.getByRole('button', {name: 'Filter', exact: true}).click();
     28   assert.equal(await page.getByRole('link', {name: '(empty)', exact: true}).getAttribute('href'), 'admin/players/1002');
     29 
     30   // Item names occupy their own cells, and unnamed catalog records can be opened.
     31   await page.goto(url + 'admin/items?sort=Count&dir=desc');
     32   assert.equal(await page.locator('tbody tr').count(), 1000);
     33   assert.equal(await page.locator('tbody tr td').first().textContent(), '1002');
     34   assert.equal(await page.locator('tbody tr').first().locator('td').nth(1).locator('.item-icon').count(), 1);
     35   assert.equal(await page.locator('tbody tr').first().locator('td').nth(2).textContent(), '(empty)');
     36   await page.goto(url + 'admin/items/catalog?catalog=4000000000');
     37   await page.getByRole('link', {name: '(empty)', exact: true}).click();
     38   assert.equal(new URL(page.url()).pathname, '/share/test/admin/items/catalog/4000000000');
     39   await page.getByRole('heading', {name: 'Possible sources (QL family)'}).waitFor();
     40   console.log('Admin list pagination, numeric sorting, filtering, prefixed links and empty-name navigation passed.');
     41 } finally {
     42   await browser.close();
     43 }