test: compare old-URL landings without building patterns from text (#668)
Code scanning flagged two test lines: a regular expression built from a hash with only / and # escaped, and a regular expression used to cut <noscript> and <script> out of the redirect page. The address is now compared by its parts, and the page's inline script is found by plain string search.
This commit is contained in:
@@ -8,7 +8,8 @@ const card=(page,text)=>cards(page).filter({has:page.getByText(text,{exact:true}
|
||||
const filtersButton=page=>page.locator('#workspace-main search.toolbar').getByRole('button',{name:/^Filters(?: · \d)?$/});
|
||||
const caption=page=>page.locator('#workspace-main .section-caption > span').first();
|
||||
const heading=page=>page.locator('#workspace-main h1').first();
|
||||
const at=hash=>new RegExp(`/prompt_manager/workspace${hash.replace(/[/#]/g,'\\$&')}$`);
|
||||
/** The workspace at exactly this hash (the filter of a link is gone from the address by then). */
|
||||
const at=hash=>url=>url.pathname.endsWith('/prompt_manager/workspace')&&url.search===''&&url.hash===hash;
|
||||
|
||||
test.beforeEach(async({page,request,browserName})=>{
|
||||
await startCoverage(page,browserName);await expect(await request.post('/__test__/reset',{data:{native_library:true}})).toBeOK();
|
||||
|
||||
@@ -73,12 +73,15 @@ test("every target is relative and resolves in the workspace router to the filte
|
||||
|
||||
test("the redirect page loads the module, replaces the address and always offers the Library link", () => {
|
||||
const html = fs.readFileSync(path.join(__dirname, "../../web/admin-redirect.html"), "utf8");
|
||||
assert.match(html, /<script src="js\/legacy-links\.js"><\/script>/);
|
||||
assert.match(html, /location\.replace\(/);
|
||||
// Visible without scripts and when the script fails: not inside <noscript>.
|
||||
assert.match(html.replace(/<noscript>[\s\S]*?<\/noscript>/g, ""), /<a href="workspace#\/library">/);
|
||||
// The inline script on a page where the module failed to load still leaves for the Library.
|
||||
const inline = html.match(/<script>([\s\S]*?)<\/script>/)[1];
|
||||
const moduleTag = '<script src="js/legacy-links.js"></script>';
|
||||
assert.ok(html.includes(moduleTag), "the page loads the mapping module");
|
||||
// The link is plain markup, visible without scripts and when the script fails: the page has no <noscript> at all.
|
||||
assert.ok(html.includes('<a href="workspace#/library">'));
|
||||
assert.equal(html.toLowerCase().includes("<noscript"), false);
|
||||
// The inline script follows the module tag; on a page where the module failed to load it still leaves for the Library.
|
||||
const open = html.indexOf("<script>", html.indexOf(moduleTag));
|
||||
const inline = html.slice(open + "<script>".length, html.indexOf("</script>", open));
|
||||
assert.ok(open > 0 && inline.includes("location.replace("));
|
||||
for (const [globals, expected] of [
|
||||
[{}, "workspace#/library"],
|
||||
[{ LegacyLinks: { adminTarget() { throw new Error("broken"); } } }, "workspace#/library"],
|
||||
|
||||
Reference in New Issue
Block a user