Files

25 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

const {chromium}=require('playwright');
const assert=require('node:assert/strict');
(async()=>{
const browser=await chromium.launch({executablePath:process.env.HCR_TEST_CHROME||'C:/Program Files/Google/Chrome/Application/chrome.exe',headless:true});
const page=await browser.newPage(),errors=[];let checks=0;
page.on('pageerror',e=>errors.push(e.message));
const pass=message=>{checks++;console.log('PASS: '+message);};
const base=process.env.HCR_TEST_URL,ids=JSON.parse(process.env.HCR_TENANT_IDS);
const click=async locator=>Promise.all([page.waitForNavigation({waitUntil:'load'}),locator.click()]);
try{
await page.goto(base+'/main.php');await page.locator('#user_email').fill('membera@example.test');await page.locator('#user_password').fill('Tenant test password 123!');await click(page.locator('#login button[type=submit]'));
await page.goto(base+'/main.php?Xaction=Roster.tickets&club_serial='+ids.clubA);
assert.equal(await page.locator('.ticket-list li').count(),25);assert((await page.locator('.ticket-page-status').innerText()).includes('of 102.'));pass('Browser shows a bounded personal ticket page with its own total');
await click(page.getByRole('link',{name:'Last page',exact:true}));assert.equal(await page.locator('.ticket-list li').count(),2);await page.getByRole('link',{name:/Archive ticket 001$/}).waitFor();pass('Last-page navigation exposes tickets older than the former 100-ticket limit');
const search=page.locator('form').filter({has:page.getByRole('button',{name:'Search tickets',exact:true})});await search.getByLabel('Search ticket subjects',{exact:true}).fill('Archive ticket 001');await click(search.getByRole('button',{name:'Search tickets',exact:true}));assert.equal(await page.locator('.ticket-list li').count(),1);assert((await page.locator('.ticket-page-status').innerText()).includes('Page 1 of 1.'));pass('Browser search resets paging and locates an older authorized ticket');
await click(page.getByRole('link',{name:/Archive ticket 001$/}));await page.getByRole('heading',{name:'Archive ticket 001',exact:true}).waitFor();pass('An old ticket opens from its filtered list');
const form=page.locator('form').filter({has:page.getByRole('button',{name:'Submit ticket',exact:true})}),body=form.getByLabel('Message',{exact:true}),subject=form.getByLabel('Subject',{exact:true});
await subject.fill('😀'.repeat(200));assert(await subject.evaluate(e=>e.checkValidity()));await subject.fill('x'.repeat(201));assert(!await subject.evaluate(e=>e.checkValidity()));pass('Subject validation counts Unicode characters rather than UTF-16 units');
await subject.fill('Unicode browser ticket');await body.fill('界'.repeat(8001));assert(!await body.evaluate(e=>e.checkValidity()));assert((await body.evaluate(e=>e.validationMessage)).includes('8000'));pass('Browser rejects an overlong Unicode message with a specific limit');
await body.fill('😀'.repeat(8000));assert.equal(await body.getAttribute('maxlength'),'16000');assert(await body.evaluate(e=>e.checkValidity()));await click(form.getByRole('button',{name:'Submit ticket',exact:true}));await page.getByRole('heading',{name:'Unicode browser ticket',exact:true}).waitFor();assert((await page.locator('article.card').first().innerText()).includes('😀'.repeat(8000)));pass('An 8,000-character emoji message is accepted and preserved through the browser');
assert.deepEqual(errors,[]);pass('Ticket paging, search and Unicode controls produce no browser script errors');
}finally{await browser.close();}
console.log(checks+' ticket repair browser checks passed.');
})().catch(e=>{console.error(e);process.exitCode=1;});