2024-04-02 12:13:06 +02:00
|
|
|
import { Page, expect } from '@playwright/test';
|
|
|
|
|
|
2025-06-24 17:42:41 +02:00
|
|
|
export const BROWSERS = ['chromium', 'webkit', 'firefox'];
|
|
|
|
|
|
2025-04-09 16:00:29 +02:00
|
|
|
export const CONFIG = {
|
|
|
|
|
AI_FEATURE_ENABLED: true,
|
|
|
|
|
CRISP_WEBSITE_ID: null,
|
|
|
|
|
COLLABORATION_WS_URL: 'ws://localhost:4444/collaboration/ws/',
|
2025-07-04 10:56:24 +02:00
|
|
|
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY: true,
|
2025-04-09 16:00:29 +02:00
|
|
|
ENVIRONMENT: 'development',
|
|
|
|
|
FRONTEND_CSS_URL: null,
|
|
|
|
|
FRONTEND_HOMEPAGE_FEATURE_ENABLED: true,
|
2025-03-25 13:01:48 +01:00
|
|
|
FRONTEND_THEME: null,
|
2025-04-09 16:00:29 +02:00
|
|
|
MEDIA_BASE_URL: 'http://localhost:8083',
|
|
|
|
|
LANGUAGES: [
|
|
|
|
|
['en-us', 'English'],
|
|
|
|
|
['fr-fr', 'Français'],
|
|
|
|
|
['de-de', 'Deutsch'],
|
|
|
|
|
['nl-nl', 'Nederlands'],
|
2025-05-02 16:00:45 +02:00
|
|
|
['es-es', 'Español'],
|
2025-04-09 16:00:29 +02:00
|
|
|
],
|
|
|
|
|
LANGUAGE_CODE: 'en-us',
|
|
|
|
|
POSTHOG_KEY: {},
|
|
|
|
|
SENTRY_DSN: null,
|
2025-05-07 12:06:16 +02:00
|
|
|
theme_customization: {},
|
2025-03-25 13:01:48 +01:00
|
|
|
} as const;
|
2025-04-09 16:00:29 +02:00
|
|
|
|
2025-05-13 11:24:02 +02:00
|
|
|
export const overrideConfig = async (
|
|
|
|
|
page: Page,
|
2025-08-07 16:59:08 +02:00
|
|
|
newConfig: { [_K in keyof typeof CONFIG]?: unknown },
|
2025-05-13 11:24:02 +02:00
|
|
|
) =>
|
|
|
|
|
await page.route('**/api/v1.0/config/', async (route) => {
|
|
|
|
|
const request = route.request();
|
|
|
|
|
if (request.method().includes('GET')) {
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
json: {
|
|
|
|
|
...CONFIG,
|
|
|
|
|
...newConfig,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await route.continue();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-03 11:02:29 +01:00
|
|
|
export const keyCloakSignIn = async (
|
|
|
|
|
page: Page,
|
|
|
|
|
browserName: string,
|
|
|
|
|
fromHome: boolean = true,
|
|
|
|
|
) => {
|
|
|
|
|
if (fromHome) {
|
2025-03-25 13:01:48 +01:00
|
|
|
await page.getByRole('button', { name: 'Start Writing' }).first().click();
|
2025-02-03 11:02:29 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-06 22:13:18 +02:00
|
|
|
const login = `user-e2e-${browserName}`;
|
|
|
|
|
const password = `password-e2e-${browserName}`;
|
|
|
|
|
|
2024-10-23 11:11:29 +02:00
|
|
|
await expect(
|
|
|
|
|
page.locator('.login-pf-page-header').getByText('impress'),
|
|
|
|
|
).toBeVisible();
|
2024-06-06 22:13:18 +02:00
|
|
|
|
2024-10-23 11:11:29 +02:00
|
|
|
if (await page.getByLabel('Restart login').isVisible()) {
|
|
|
|
|
await page.getByLabel('Restart login').click();
|
2024-04-02 12:13:06 +02:00
|
|
|
}
|
2024-10-23 11:11:29 +02:00
|
|
|
|
|
|
|
|
await page.getByRole('textbox', { name: 'username' }).fill(login);
|
|
|
|
|
await page.getByRole('textbox', { name: 'password' }).fill(password);
|
|
|
|
|
await page.click('input[type="submit"]', { force: true });
|
2024-04-02 12:13:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const randomName = (name: string, browserName: string, length: number) =>
|
|
|
|
|
Array.from({ length }, (_el, index) => {
|
|
|
|
|
return `${browserName}-${Math.floor(Math.random() * 10000)}-${index}-${name}`;
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-25 14:49:53 +02:00
|
|
|
export const createDoc = async (
|
2024-04-02 12:13:06 +02:00
|
|
|
page: Page,
|
2024-06-25 14:49:53 +02:00
|
|
|
docName: string,
|
2024-04-02 12:13:06 +02:00
|
|
|
browserName: string,
|
2025-01-29 14:06:38 +01:00
|
|
|
length: number = 1,
|
2025-07-30 12:14:32 +02:00
|
|
|
isMobile: boolean = false,
|
2024-04-02 12:13:06 +02:00
|
|
|
) => {
|
2024-06-25 14:49:53 +02:00
|
|
|
const randomDocs = randomName(docName, browserName, length);
|
2024-04-02 12:13:06 +02:00
|
|
|
|
2024-06-25 14:49:53 +02:00
|
|
|
for (let i = 0; i < randomDocs.length; i++) {
|
2025-07-30 12:14:32 +02:00
|
|
|
if (isMobile) {
|
|
|
|
|
await page
|
|
|
|
|
.getByRole('button', { name: 'Open the header menu' })
|
|
|
|
|
.getByText('menu')
|
|
|
|
|
.click();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 14:14:43 +02:00
|
|
|
await page
|
2024-10-01 15:55:19 +02:00
|
|
|
.getByRole('button', {
|
2025-07-02 14:33:57 +02:00
|
|
|
name: 'New doc',
|
2024-07-05 14:14:43 +02:00
|
|
|
})
|
2024-10-01 15:55:19 +02:00
|
|
|
.click();
|
2024-04-15 22:34:19 +02:00
|
|
|
|
2025-03-14 14:27:56 +01:00
|
|
|
await page.waitForURL('**/docs/**', {
|
|
|
|
|
timeout: 10000,
|
|
|
|
|
waitUntil: 'networkidle',
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-29 14:06:38 +01:00
|
|
|
const input = page.getByLabel('doc title input');
|
2025-04-23 11:43:50 +02:00
|
|
|
await expect(input).toBeVisible();
|
2025-01-29 14:06:38 +01:00
|
|
|
await expect(input).toHaveText('');
|
2024-11-25 12:10:16 +01:00
|
|
|
await input.click();
|
2025-03-14 14:27:56 +01:00
|
|
|
|
2024-11-25 12:10:16 +01:00
|
|
|
await input.fill(randomDocs[i]);
|
|
|
|
|
await input.blur();
|
2024-04-15 22:34:19 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-05 14:14:43 +02:00
|
|
|
return randomDocs;
|
2024-04-15 22:34:19 +02:00
|
|
|
};
|
|
|
|
|
|
2024-11-25 12:10:16 +01:00
|
|
|
export const verifyDocName = async (page: Page, docName: string) => {
|
2025-03-25 13:01:48 +01:00
|
|
|
await expect(
|
|
|
|
|
page.getByLabel('It is the card information about the document.'),
|
|
|
|
|
).toBeVisible({
|
|
|
|
|
timeout: 10000,
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-14 14:27:56 +01:00
|
|
|
try {
|
2025-03-25 13:01:48 +01:00
|
|
|
await expect(
|
|
|
|
|
page.getByRole('textbox', { name: 'doc title input' }),
|
|
|
|
|
).toHaveText(docName);
|
2025-03-14 14:27:56 +01:00
|
|
|
} catch {
|
|
|
|
|
await expect(page.getByRole('heading', { name: docName })).toBeVisible();
|
|
|
|
|
}
|
2024-11-25 12:10:16 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-29 14:06:38 +01:00
|
|
|
export const getGridRow = async (page: Page, title: string) => {
|
|
|
|
|
const docsGrid = page.getByRole('grid');
|
|
|
|
|
await expect(docsGrid).toBeVisible();
|
|
|
|
|
await expect(page.getByTestId('grid-loader')).toBeHidden();
|
|
|
|
|
|
|
|
|
|
const rows = docsGrid.getByRole('row');
|
|
|
|
|
|
2025-08-29 10:25:40 +02:00
|
|
|
const row = rows
|
|
|
|
|
.filter({
|
|
|
|
|
hasText: title,
|
|
|
|
|
})
|
|
|
|
|
.first();
|
2025-01-29 14:06:38 +01:00
|
|
|
|
|
|
|
|
await expect(row).toBeVisible();
|
|
|
|
|
|
|
|
|
|
return row;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-05 14:14:43 +02:00
|
|
|
interface GoToGridDocOptions {
|
|
|
|
|
nthRow?: number;
|
|
|
|
|
title?: string;
|
|
|
|
|
}
|
|
|
|
|
export const goToGridDoc = async (
|
|
|
|
|
page: Page,
|
|
|
|
|
{ nthRow = 1, title }: GoToGridDocOptions = {},
|
|
|
|
|
) => {
|
|
|
|
|
const header = page.locator('header').first();
|
2025-08-01 10:12:16 +02:00
|
|
|
await header.locator('h1').getByText('Docs').click();
|
2024-07-05 14:14:43 +02:00
|
|
|
|
2024-11-19 16:12:12 +01:00
|
|
|
const docsGrid = page.getByTestId('docs-grid');
|
|
|
|
|
await expect(docsGrid).toBeVisible();
|
2025-01-29 14:06:38 +01:00
|
|
|
await expect(page.getByTestId('grid-loader')).toBeHidden();
|
2024-07-05 14:14:43 +02:00
|
|
|
|
2024-11-19 16:12:12 +01:00
|
|
|
const rows = docsGrid.getByRole('row');
|
2025-01-09 09:15:21 +01:00
|
|
|
|
2024-07-05 14:14:43 +02:00
|
|
|
const row = title
|
|
|
|
|
? rows.filter({
|
|
|
|
|
hasText: title,
|
|
|
|
|
})
|
|
|
|
|
: rows.nth(nthRow);
|
|
|
|
|
|
2024-11-19 16:12:12 +01:00
|
|
|
await expect(row).toBeVisible();
|
2024-07-05 14:14:43 +02:00
|
|
|
|
2024-11-19 16:12:12 +01:00
|
|
|
const docTitleContent = row.locator('[aria-describedby="doc-title"]').first();
|
|
|
|
|
const docTitle = await docTitleContent.textContent();
|
2024-07-05 14:14:43 +02:00
|
|
|
expect(docTitle).toBeDefined();
|
|
|
|
|
|
2024-10-08 17:03:42 +02:00
|
|
|
await row.getByRole('link').first().click();
|
2024-07-05 14:14:43 +02:00
|
|
|
|
|
|
|
|
return docTitle as string;
|
|
|
|
|
};
|
2024-07-17 15:30:52 +02:00
|
|
|
|
2025-05-19 09:03:00 +02:00
|
|
|
export const updateDocTitle = async (page: Page, title: string) => {
|
|
|
|
|
const input = page.getByLabel('doc title input');
|
|
|
|
|
await expect(input).toBeVisible();
|
|
|
|
|
await expect(input).toHaveText('');
|
|
|
|
|
await input.click();
|
|
|
|
|
await input.fill(title);
|
|
|
|
|
await input.click();
|
2025-07-02 14:33:57 +02:00
|
|
|
await input.blur();
|
2025-05-19 09:03:00 +02:00
|
|
|
await verifyDocName(page, title);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const waitForResponseCreateDoc = (page: Page) => {
|
|
|
|
|
return page.waitForResponse(
|
|
|
|
|
(response) =>
|
|
|
|
|
response.url().includes('/documents/') &&
|
|
|
|
|
response.url().includes('/children/') &&
|
|
|
|
|
response.request().method() === 'POST',
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const mockedDocument = async (page: Page, data: object) => {
|
2024-07-17 15:30:52 +02:00
|
|
|
await page.route('**/documents/**/', async (route) => {
|
|
|
|
|
const request = route.request();
|
2024-10-03 17:21:04 +02:00
|
|
|
if (
|
|
|
|
|
request.method().includes('GET') &&
|
|
|
|
|
!request.url().includes('page=') &&
|
|
|
|
|
!request.url().includes('versions') &&
|
|
|
|
|
!request.url().includes('accesses') &&
|
|
|
|
|
!request.url().includes('invitations')
|
|
|
|
|
) {
|
2025-05-20 10:00:26 +02:00
|
|
|
const { abilities, ...doc } = data as unknown as {
|
|
|
|
|
abilities?: Record<string, unknown>;
|
|
|
|
|
};
|
2024-07-17 15:30:52 +02:00
|
|
|
await route.fulfill({
|
|
|
|
|
json: {
|
2024-08-16 14:51:42 +02:00
|
|
|
id: 'mocked-document-id',
|
2024-07-17 15:30:52 +02:00
|
|
|
content: '',
|
|
|
|
|
title: 'Mocked document',
|
2025-05-19 09:03:00 +02:00
|
|
|
path: '000000',
|
2024-07-17 15:30:52 +02:00
|
|
|
abilities: {
|
|
|
|
|
destroy: false, // Means not owner
|
2024-09-11 10:23:06 +02:00
|
|
|
link_configuration: false,
|
2024-07-17 15:30:52 +02:00
|
|
|
versions_destroy: false,
|
|
|
|
|
versions_list: true,
|
|
|
|
|
versions_retrieve: true,
|
2024-10-23 08:26:40 +02:00
|
|
|
accesses_manage: false, // Means not admin
|
2024-07-17 15:30:52 +02:00
|
|
|
update: false,
|
|
|
|
|
partial_update: false, // Means not editor
|
|
|
|
|
retrieve: true,
|
2025-05-19 09:03:00 +02:00
|
|
|
link_select_options: {
|
|
|
|
|
public: ['reader', 'editor'],
|
|
|
|
|
authenticated: ['reader', 'editor'],
|
|
|
|
|
restricted: null,
|
|
|
|
|
},
|
2025-05-20 10:00:26 +02:00
|
|
|
...abilities,
|
2024-07-17 15:30:52 +02:00
|
|
|
},
|
2024-09-11 10:23:06 +02:00
|
|
|
link_reach: 'restricted',
|
2025-05-19 09:03:00 +02:00
|
|
|
computed_link_reach: 'restricted',
|
|
|
|
|
computed_link_role: 'reader',
|
|
|
|
|
ancestors_link_reach: null,
|
|
|
|
|
ancestors_link_role: null,
|
2024-07-17 15:30:52 +02:00
|
|
|
created_at: '2021-09-01T09:00:00Z',
|
2025-05-19 09:03:00 +02:00
|
|
|
user_role: 'owner',
|
2025-05-20 10:00:26 +02:00
|
|
|
...doc,
|
2024-07-17 15:30:52 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await route.continue();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2024-10-03 17:21:04 +02:00
|
|
|
|
2025-03-17 15:12:12 +01:00
|
|
|
export const mockedListDocs = async (page: Page, data: object[] = []) => {
|
|
|
|
|
await page.route('**/documents/**/', async (route) => {
|
|
|
|
|
const request = route.request();
|
|
|
|
|
if (request.method().includes('GET') && request.url().includes('page=')) {
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
json: {
|
|
|
|
|
count: data.length,
|
|
|
|
|
next: null,
|
|
|
|
|
previous: null,
|
|
|
|
|
results: data,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-03 11:02:29 +01:00
|
|
|
export const expectLoginPage = async (page: Page) =>
|
|
|
|
|
await expect(
|
|
|
|
|
page.getByRole('heading', { name: 'Collaborative writing' }),
|
2025-06-24 17:42:41 +02:00
|
|
|
).toBeVisible({
|
|
|
|
|
timeout: 10000,
|
|
|
|
|
});
|
2025-07-30 11:23:14 +02:00
|
|
|
// language helper
|
|
|
|
|
export const TestLanguage = {
|
|
|
|
|
English: {
|
|
|
|
|
label: 'English',
|
|
|
|
|
expectedLocale: ['en-us'],
|
|
|
|
|
},
|
|
|
|
|
French: {
|
|
|
|
|
label: 'Français',
|
|
|
|
|
expectedLocale: ['fr-fr'],
|
|
|
|
|
},
|
|
|
|
|
German: {
|
|
|
|
|
label: 'Deutsch',
|
|
|
|
|
expectedLocale: ['de-de'],
|
|
|
|
|
},
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
type TestLanguageKey = keyof typeof TestLanguage;
|
|
|
|
|
type TestLanguageValue = (typeof TestLanguage)[TestLanguageKey];
|
|
|
|
|
|
|
|
|
|
export async function waitForLanguageSwitch(
|
|
|
|
|
page: Page,
|
|
|
|
|
lang: TestLanguageValue,
|
|
|
|
|
) {
|
2025-08-05 10:59:49 +02:00
|
|
|
await page.route('**/api/v1.0/users/**', async (route, request) => {
|
|
|
|
|
if (request.method().includes('PATCH')) {
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
json: {
|
|
|
|
|
language: lang.expectedLocale[0],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await route.continue();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-30 11:23:14 +02:00
|
|
|
const header = page.locator('header').first();
|
|
|
|
|
const languagePicker = header.locator('.--docs--language-picker-text');
|
|
|
|
|
const isAlreadyTargetLanguage = await languagePicker
|
|
|
|
|
.innerText()
|
|
|
|
|
.then((text) => text.toLowerCase().includes(lang.label.toLowerCase()));
|
|
|
|
|
|
|
|
|
|
if (isAlreadyTargetLanguage) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await languagePicker.click();
|
|
|
|
|
|
2025-08-05 10:59:49 +02:00
|
|
|
await page.getByLabel(lang.label).click();
|
2025-07-30 11:23:14 +02:00
|
|
|
}
|