2025-04-10 22:54:59 +02:00
|
|
|
import crypto from 'crypto';
|
|
|
|
|
|
2024-07-05 14:14:43 +02:00
|
|
|
import { expect, test } from '@playwright/test';
|
|
|
|
|
|
2025-03-18 11:28:35 +01:00
|
|
|
import {
|
|
|
|
|
createDoc,
|
|
|
|
|
expectLoginPage,
|
|
|
|
|
keyCloakSignIn,
|
|
|
|
|
mockedDocument,
|
|
|
|
|
verifyDocName,
|
2025-07-16 13:56:18 +02:00
|
|
|
} from './utils-common';
|
2025-07-24 11:45:09 +02:00
|
|
|
import { createRootSubPage } from './utils-sub-pages';
|
2024-07-05 14:14:43 +02:00
|
|
|
|
|
|
|
|
test.describe('Doc Routing', () => {
|
2024-08-16 14:51:42 +02:00
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-23 17:40:27 +02:00
|
|
|
test('Check the presence of the meta tag noindex', async ({
|
|
|
|
|
page,
|
|
|
|
|
browserName,
|
|
|
|
|
}) => {
|
|
|
|
|
await createDoc(page, 'doc-routing-test', browserName, 1);
|
2024-10-24 10:33:14 +02:00
|
|
|
const metaDescription = page.locator('meta[name="robots"]');
|
|
|
|
|
await expect(metaDescription).toHaveAttribute('content', 'noindex');
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-05 14:14:43 +02:00
|
|
|
test('checks alias docs url with homepage', async ({ page }) => {
|
|
|
|
|
await expect(page).toHaveURL('/');
|
|
|
|
|
|
|
|
|
|
const buttonCreateHomepage = page.getByRole('button', {
|
2024-11-13 15:11:10 +01:00
|
|
|
name: 'New doc',
|
2024-07-05 14:14:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await expect(buttonCreateHomepage).toBeVisible();
|
|
|
|
|
|
2024-08-16 14:51:42 +02:00
|
|
|
await page.goto('/docs/');
|
2024-07-05 14:14:43 +02:00
|
|
|
await expect(buttonCreateHomepage).toBeVisible();
|
2024-08-16 14:51:42 +02:00
|
|
|
await expect(page).toHaveURL(/\/docs\/$/);
|
2024-07-05 14:14:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('checks 404 on docs/[id] page', async ({ page }) => {
|
|
|
|
|
await page.waitForTimeout(300);
|
|
|
|
|
|
|
|
|
|
await page.goto('/docs/some-unknown-doc');
|
|
|
|
|
await expect(
|
|
|
|
|
page.getByText(
|
|
|
|
|
'It seems that the page you are looking for does not exist or cannot be displayed correctly.',
|
|
|
|
|
),
|
|
|
|
|
).toBeVisible({
|
|
|
|
|
timeout: 15000,
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-03-18 11:28:35 +01:00
|
|
|
|
|
|
|
|
test('checks 401 on docs/[id] page', async ({ page, browserName }) => {
|
2025-07-24 11:45:09 +02:00
|
|
|
const [docTitle] = await createDoc(page, '401-doc-parent', browserName, 1);
|
2025-03-18 11:28:35 +01:00
|
|
|
await verifyDocName(page, docTitle);
|
|
|
|
|
|
2025-07-24 11:45:09 +02:00
|
|
|
await createRootSubPage(page, browserName, '401-doc-child');
|
|
|
|
|
|
|
|
|
|
await page.locator('.ProseMirror.bn-editor').fill('Hello World');
|
|
|
|
|
|
2025-08-07 09:55:28 +02:00
|
|
|
// Wait for the doc link (via its dynamic title) to be visible
|
|
|
|
|
const docLink = page.getByRole('link', { name: docTitle });
|
|
|
|
|
await expect(docLink).toBeVisible();
|
|
|
|
|
|
|
|
|
|
// Intercept GET/PATCH requests to return 401
|
|
|
|
|
await page.route(/.*\/documents\/.*\/$|users\/me\/$/, async (route) => {
|
|
|
|
|
const request = route.request();
|
|
|
|
|
if (
|
|
|
|
|
request.method().includes('PATCH') ||
|
|
|
|
|
request.method().includes('GET')
|
|
|
|
|
) {
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
status: 401,
|
|
|
|
|
json: { detail: 'Log in to access the document' },
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await route.continue();
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-03-18 11:28:35 +01:00
|
|
|
|
2025-08-07 09:55:28 +02:00
|
|
|
// Explicitly wait for a 401 response after clicking
|
|
|
|
|
const wait401 = page.waitForResponse(
|
|
|
|
|
(resp) =>
|
|
|
|
|
resp.status() === 401 &&
|
|
|
|
|
/\/(documents\/[^/]+\/|users\/me\/)$/.test(resp.url()),
|
|
|
|
|
);
|
2025-03-18 11:28:35 +01:00
|
|
|
|
2025-08-07 09:55:28 +02:00
|
|
|
await docLink.click();
|
|
|
|
|
await wait401;
|
2025-03-18 11:28:35 +01:00
|
|
|
|
2025-08-07 09:55:28 +02:00
|
|
|
await expect(page.getByText('Log in to access the document.')).toBeVisible({
|
2025-09-04 16:12:33 +02:00
|
|
|
timeout: 10000,
|
|
|
|
|
});
|
2025-09-17 14:53:21 +02:00
|
|
|
|
|
|
|
|
await expect(page.locator('meta[name="robots"]')).toHaveAttribute(
|
|
|
|
|
'content',
|
|
|
|
|
'noindex',
|
|
|
|
|
);
|
|
|
|
|
await expect(page).toHaveTitle(/401 Unauthorized - Docs/);
|
2025-03-18 11:28:35 +01:00
|
|
|
});
|
2024-07-05 14:14:43 +02:00
|
|
|
});
|
2024-08-16 14:51:42 +02:00
|
|
|
|
2025-05-26 10:27:17 +02:00
|
|
|
test.describe('Doc Routing: Not logged', () => {
|
2024-08-16 14:51:42 +02:00
|
|
|
test.use({ storageState: { cookies: [], origins: [] } });
|
|
|
|
|
|
|
|
|
|
test('checks redirect to a doc after login', async ({
|
|
|
|
|
page,
|
|
|
|
|
browserName,
|
|
|
|
|
}) => {
|
2025-04-10 22:54:59 +02:00
|
|
|
const uuid = crypto.randomUUID();
|
|
|
|
|
await mockedDocument(page, { link_reach: 'public', id: uuid });
|
|
|
|
|
await page.goto(`/docs/${uuid}/`);
|
2024-09-27 14:24:16 +02:00
|
|
|
await expect(page.locator('h2').getByText('Mocked document')).toBeVisible();
|
|
|
|
|
await page.getByRole('button', { name: 'Login' }).click();
|
2025-02-03 11:02:29 +01:00
|
|
|
await keyCloakSignIn(page, browserName, false);
|
2024-09-27 14:24:16 +02:00
|
|
|
await expect(page.locator('h2').getByText('Mocked document')).toBeVisible();
|
2024-08-16 14:51:42 +02:00
|
|
|
});
|
2024-09-06 14:23:22 +02:00
|
|
|
|
2025-02-03 11:02:29 +01:00
|
|
|
// eslint-disable-next-line playwright/expect-expect
|
2024-09-06 14:23:22 +02:00
|
|
|
test('The homepage redirects to login.', async ({ page }) => {
|
|
|
|
|
await page.goto('/');
|
2025-02-03 11:02:29 +01:00
|
|
|
await expectLoginPage(page);
|
2024-09-06 14:23:22 +02:00
|
|
|
});
|
2024-08-16 14:51:42 +02:00
|
|
|
});
|