Files
archie/e2e/checks/loading-errors.cjs

37 lines
2.3 KiB
JavaScript

const assert=require('node:assert/strict');
module.exports=async({page,go,shot,tolerate})=>{
// The extension catalogue 502 is a stack-environment issue, not this check.
tolerate(/extensions\/catalogue/);
await page.route('**/api/access/policies',async route=>{await new Promise(r=>setTimeout(r,2200));await route.continue()});
await go('/access/policies');
assert.equal(await page.getByText('No policies yet.',{exact:true}).count(),0);
await page.getByText('Loading policies…',{exact:true}).waitFor({state:'hidden'});
await page.route('**/api/tasks?**',async route=>{
if(new URL(route.request().url()).searchParams.has('workflow')) await route.fulfill({status:200,contentType:'application/json',body:'unreadable response'});
else await route.continue();
});
await go('/workflows/implement');
await page.getByRole('alert').filter({hasText:'Could not load recent runs'}).waitFor();
await page.getByRole('tab',{name:/^Runs/}).click();
assert.equal(await page.getByText('No runs yet',{exact:true}).count(),0);
await page.unroute('**/api/tasks?**');
await page.getByRole('button',{name:'Retry runs',exact:true}).click();
await page.getByRole('alert').filter({hasText:'Could not load recent runs'}).waitFor({state:'hidden'});
await shot('recovered');
// A failed list read is an error, never the empty state (#1767): force each
// page's list API to 500 and check its empty-state copy stays hidden.
const failList = async (pattern,path,emptyTexts,errorSel='[role=alert]')=>{
await page.route(pattern,route=>route.fulfill({status:200,contentType:'application/json',body:'unreadable response'}));
await go(path);
await page.locator(errorSel).first().waitFor();
for(const text of emptyTexts) assert.equal(await page.getByText(text,{exact:true}).count(),0,`${path} shows its empty state ("${text}") while the list read fails`);
await page.unroute(pattern);
};
await failList('**/api/tasks*','/tasks',['No tasks yet'],'text=Archie is not responding');
await failList('**/api/captures*','/events',['No captures yet']);
await failList('**/api/event-types*','/events',['No event types yet']);
await failList('**/api/tokens*','/account',['No tokens yet']);
await failList('**/api/access/policies*','/org/policies',['No policies yet']);
await shot('failed-reads-show-errors');
};