From 63b208027be03536aad2249d87999ef3aa3975d8 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 26 Sep 2024 12:12:36 +0200 Subject: [PATCH] playwright: verify that the 404 page is styled The 404 page is not only a place to tell the user that what they were looking for cannot be found, but also to guide them to what _can_ be found, including the search box and the navigation box. Signed-off-by: Johannes Schindelin --- script/serve-public.js | 5 ++--- tests/git-scm.spec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/script/serve-public.js b/script/serve-public.js index c5b2d7e1e5..6f0486fa01 100755 --- a/script/serve-public.js +++ b/script/serve-public.js @@ -41,9 +41,8 @@ const handler = (request, response) => { fileStream.pipe(response); } catch(e) { console.log(`Could not read ${filename}`); - response.writeHead(404, {'Content-Type': 'text/plain'}); - response.write('404 Not Found\n'); - response.end(); + response.writeHead(404, {'Content-Type': 'text/html'}); + fs.createReadStream(path.join(basePath, '404.html')).pipe(response); return; } }; diff --git a/tests/git-scm.spec.js b/tests/git-scm.spec.js index e8674a84bb..7d3dde39f0 100644 --- a/tests/git-scm.spec.js +++ b/tests/git-scm.spec.js @@ -230,3 +230,18 @@ test('book', async ({ page }) => { } await expect(page.getByRole('document')).toHaveText(/Snapshot’lar, Fərqlər Yox/) }) + +test('404', async ({ page }) => { + await page.goto(`${url}does-not.exist`) + + await expect(page.locator('.inner h1')).toHaveText(`That page doesn't exist.`) + + // the 404 page should be styled + await expect(page.locator('link[rel="stylesheet"]')).toHaveAttribute('href', /application(\.min)?\.css$/) + + // the search box is shown + await expect(page.locator('#search-text')).toBeVisible() + + // the usual navbar is shown + await expect(page.getByRole('link', { name: 'Community' })).toBeVisible() +})