Files
aeternalis/tests/catalog.spec.ts

64 lines
4.7 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('Control publishes title and equipment requirements, formulas and audit', async ({ page }) => {
const errors:string[]=[];page.on('pageerror',e=>errors.push(e.message));
const origin='http://127.0.0.1:18089';
expect((await page.request.get('/api/control/catalog')).status()).toBe(401);
await page.request.post('/auth/dev',{data:{},headers:{Origin:origin}});
const initial=(await (await page.request.get('/api/control/catalog')).json()).catalog.version;
await page.goto('/control');await page.getByRole('button',{name:'Content',exact:true}).click();
await page.getByRole('button',{name:'Create title',exact:true}).click();
const form=page.locator('.catalog-form');
await form.getByLabel('Name',{exact:true}).fill('Control Trial');
await form.getByLabel('Description',{exact:true}).fill('A test of authored requirements and effects.');
await form.getByLabel('Award scope').selectOption('global');
await form.getByLabel('At least').fill('9999');
await form.getByRole('button',{name:'Add modifier',exact:true}).click();
await form.getByRole('combobox',{name:'Stat',exact:true}).selectOption('strength');
await form.getByLabel('Flat change',{exact:true}).fill('3');
await form.getByLabel('Percent change (%)',{exact:true}).fill('-10');
await form.getByLabel('Reason for change').fill('Browser authoring verification');
await page.setViewportSize({width:390,height:844});
expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true);
await page.screenshot({path:'test-results/content-title-mobile.png',fullPage:true});
await form.getByRole('button',{name:'Publish changes'}).click();
await expect(page.locator('.catalog-heading')).toContainText(`Catalog version ${initial+1}`);
let catalog=(await (await page.request.get('/api/control/catalog')).json()).catalog;
const title=catalog.titles.find(t=>t.name==='Control Trial');
expect(title).toMatchObject({scope:'global',requirements:[{metric:'level',atLeast:9999}],effects:{modifiers:[{stat:'strength',flat:3,percent:-10}]}});
await page.locator('.catalog-tabs').getByRole('button',{name:'Equipment',exact:true}).click();
await page.getByRole('button',{name:'Create equipment',exact:true}).click();
await form.getByLabel('Name',{exact:true}).fill('Control Ring');
await form.getByLabel('Equipment slot').selectOption('ring');
await form.getByLabel('Required level').fill('2');
await form.getByRole('button',{name:'Add required stat'}).click();
await form.getByRole('combobox',{name:'Stat',exact:true}).selectOption('strength');
await form.getByLabel('Minimum value').fill('3');
await form.getByLabel('Control Trial',{exact:true}).check();
await form.getByRole('button',{name:'Add modifier',exact:true}).click();
const modifier=form.locator('fieldset').filter({has:page.locator('legend',{hasText:'Modifiers'})});
await modifier.getByRole('combobox',{name:'Stat',exact:true}).selectOption('luck');
await modifier.getByLabel('Flat change').fill('2');
await modifier.getByLabel('Percent change (%)').fill('25');
await form.getByLabel('Reason for change').fill('Equipment authoring verification');
await form.getByRole('button',{name:'Publish changes'}).click();
await expect(page.locator('.catalog-heading')).toContainText(`Catalog version ${initial+2}`);
catalog=(await (await page.request.get('/api/control/catalog')).json()).catalog;
const item=catalog.items.find(i=>i.name==='Control Ring');
expect(item).toMatchObject({slot:'ring',requirements:{level:2,stats:{strength:3},titles:[title.id]},modifiers:[{stat:'luck',flat:2,percent:25}]});
await page.locator('.catalog-tabs').getByRole('button',{name:'Stat formulas',exact:true}).click();
await page.getByRole('button',{name:'Edit stat formulas',exact:true}).click();
await form.getByLabel('Charisma base',{exact:true}).fill('1');
await form.getByLabel('Reason for change').fill('Formula editor verification');
await form.getByRole('button',{name:'Publish changes'}).click();
await expect(page.locator('.catalog-heading')).toContainText(`Catalog version ${initial+3}`);
await page.locator('.catalog-tabs').getByRole('button',{name:'Content audit',exact:true}).click();
await expect(page.locator('.catalog-list')).toContainText('Formula editor verification');
await expect(page.locator('.catalog-list')).toContainText(item.id);
await page.setViewportSize({width:1440,height:1000});
await page.screenshot({path:'test-results/content-audit-desktop.png',fullPage:true});
await expect.poll(async()=>((await (await page.request.get('/api/control')).json()).worlds[0].catalogVersion)).toBe(initial+3);
expect((await page.request.post('/api/control/catalog',{data:{},headers:{Origin:'https://evil.example'}})).status()).toBe(403);
expect(errors).toEqual([]);
});