2024-04-02 12:13:06 +02:00
|
|
|
import { expect, test } from '@playwright/test';
|
|
|
|
|
|
|
|
|
|
import { waitForElementCount } from '../helpers';
|
|
|
|
|
|
2024-06-06 22:13:18 +02:00
|
|
|
import { createPad } from './common';
|
2024-04-02 12:13:06 +02:00
|
|
|
|
2024-06-06 22:13:18 +02:00
|
|
|
test.beforeEach(async ({ page }) => {
|
2024-04-02 12:13:06 +02:00
|
|
|
await page.goto('/');
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-27 13:27:49 +02:00
|
|
|
test.describe('Documents Panel', () => {
|
2024-04-02 12:13:06 +02:00
|
|
|
test('checks all the elements are visible', async ({ page }) => {
|
2024-05-27 13:27:49 +02:00
|
|
|
const panel = page.getByLabel('Documents panel').first();
|
2024-04-02 12:13:06 +02:00
|
|
|
|
2024-05-14 10:10:26 +02:00
|
|
|
await expect(panel.getByText('Documents')).toBeVisible();
|
2024-04-02 12:13:06 +02:00
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
panel.getByRole('button', {
|
2024-05-27 13:27:49 +02:00
|
|
|
name: 'Sort the documents',
|
2024-04-02 12:13:06 +02:00
|
|
|
}),
|
|
|
|
|
).toBeVisible();
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
panel.getByRole('button', {
|
2024-05-27 13:27:49 +02:00
|
|
|
name: 'Add a document',
|
2024-04-02 12:13:06 +02:00
|
|
|
}),
|
|
|
|
|
).toBeVisible();
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-16 09:15:10 +02:00
|
|
|
test('checks the sort button', async ({ page }) => {
|
2024-04-02 12:13:06 +02:00
|
|
|
const responsePromiseSortDesc = page.waitForResponse(
|
|
|
|
|
(response) =>
|
2024-04-16 09:15:10 +02:00
|
|
|
response.url().includes('/documents/?page=1&ordering=-created_at') &&
|
2024-04-02 12:13:06 +02:00
|
|
|
response.status() === 200,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const responsePromiseSortAsc = page.waitForResponse(
|
|
|
|
|
(response) =>
|
2024-04-16 09:15:10 +02:00
|
|
|
response.url().includes('/documents/?page=1&ordering=created_at') &&
|
2024-04-02 12:13:06 +02:00
|
|
|
response.status() === 200,
|
|
|
|
|
);
|
|
|
|
|
|
2024-05-27 13:27:49 +02:00
|
|
|
const panel = page.getByLabel('Documents panel').first();
|
2024-04-02 12:13:06 +02:00
|
|
|
|
|
|
|
|
await panel
|
|
|
|
|
.getByRole('button', {
|
2024-05-27 13:27:49 +02:00
|
|
|
name: 'Sort the documents by creation date ascendent',
|
2024-04-02 12:13:06 +02:00
|
|
|
})
|
|
|
|
|
.click();
|
|
|
|
|
|
|
|
|
|
const responseSortAsc = await responsePromiseSortAsc;
|
|
|
|
|
expect(responseSortAsc.ok()).toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await panel
|
|
|
|
|
.getByRole('button', {
|
2024-05-27 13:27:49 +02:00
|
|
|
name: 'Sort the documents by creation date descendent',
|
2024-04-02 12:13:06 +02:00
|
|
|
})
|
|
|
|
|
.click();
|
|
|
|
|
|
|
|
|
|
const responseSortDesc = await responsePromiseSortDesc;
|
|
|
|
|
expect(responseSortDesc.ok()).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-06 22:13:18 +02:00
|
|
|
test('checks the infinite scroll', async ({ page }) => {
|
|
|
|
|
await page.route(
|
|
|
|
|
/.*\/documents\/\?page=.*&ordering=-created_at/,
|
|
|
|
|
async (route) => {
|
|
|
|
|
const request = route.request();
|
|
|
|
|
const url = new URL(request.url());
|
|
|
|
|
const pageId = url.searchParams.get('page');
|
|
|
|
|
const documents = {
|
|
|
|
|
count: 40,
|
|
|
|
|
next: 'http://localhost:3000/documents/?page=2&ordering=-created_at',
|
|
|
|
|
previous: null,
|
|
|
|
|
results: Array.from({ length: 20 }, (_, i) => ({
|
|
|
|
|
id: `2ff-${pageId}-${i}`,
|
|
|
|
|
title: `My document-${pageId}-${i}`,
|
|
|
|
|
accesses: [
|
|
|
|
|
{
|
|
|
|
|
id: 'b644e9b1-0517-4cfb-90ca-f7d6f2f6bb9a',
|
|
|
|
|
role: `owner`,
|
|
|
|
|
team: '',
|
|
|
|
|
user: {
|
|
|
|
|
id: 'a4743608-c9d8-4692-bef4-f795e25a3a88',
|
|
|
|
|
email: 'user@chromium.e2e',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
content: '',
|
|
|
|
|
is_public: true,
|
|
|
|
|
abilities: {},
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (request.method().includes('GET')) {
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
json: documents,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await route.continue();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-04-02 12:13:06 +02:00
|
|
|
|
2024-06-06 22:13:18 +02:00
|
|
|
await page.route(`**/documents/2ff-1-16/`, async (route) => {
|
|
|
|
|
const request = route.request();
|
|
|
|
|
|
|
|
|
|
if (request.method().includes('GET')) {
|
|
|
|
|
await route.fulfill({
|
|
|
|
|
json: {
|
|
|
|
|
id: '2ff-1-16',
|
|
|
|
|
title: 'My document-1-16',
|
|
|
|
|
content: '',
|
|
|
|
|
abilities: {
|
|
|
|
|
partial_update: true,
|
|
|
|
|
},
|
|
|
|
|
accesses: [
|
|
|
|
|
{
|
|
|
|
|
id: 'b644e9b1-0517-4cfb-90ca-f7d6f2f6bb9a',
|
|
|
|
|
role: `owner`,
|
|
|
|
|
team: '',
|
|
|
|
|
user: {
|
|
|
|
|
id: 'a4743608-c9d8-4692-bef4-f795e25a3a88',
|
|
|
|
|
email: '',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
await route.continue();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await page.goto('/');
|
2024-04-02 12:13:06 +02:00
|
|
|
|
2024-06-06 22:13:18 +02:00
|
|
|
const panel = page.getByLabel('Documents panel').first();
|
2024-04-02 12:13:06 +02:00
|
|
|
await expect(panel.locator('li')).toHaveCount(20);
|
2024-06-06 22:13:18 +02:00
|
|
|
await panel.getByText(`My document-1-16`).click();
|
2024-04-02 12:13:06 +02:00
|
|
|
|
|
|
|
|
await waitForElementCount(panel.locator('li'), 21, 10000);
|
|
|
|
|
expect(await panel.locator('li').count()).toBeGreaterThan(20);
|
2024-06-06 22:13:18 +02:00
|
|
|
await expect(panel.getByText(`My document-1-16`)).toBeVisible();
|
|
|
|
|
await expect(panel.getByText(`My document-2-15`)).toBeVisible();
|
2024-04-02 12:13:06 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-16 09:15:10 +02:00
|
|
|
test('checks the hover and selected state', async ({ page, browserName }) => {
|
2024-05-27 13:27:49 +02:00
|
|
|
const panel = page.getByLabel('Documents panel').first();
|
2024-04-16 09:15:10 +02:00
|
|
|
await createPad(page, 'pad-hover', browserName, 2);
|
2024-04-02 12:13:06 +02:00
|
|
|
|
2024-04-16 09:15:10 +02:00
|
|
|
const selectedPad = panel.locator('li').nth(0);
|
|
|
|
|
await expect(selectedPad).toHaveCSS(
|
2024-04-02 12:13:06 +02:00
|
|
|
'background-color',
|
|
|
|
|
'rgb(202, 202, 251)',
|
|
|
|
|
);
|
|
|
|
|
|
2024-04-16 09:15:10 +02:00
|
|
|
const hoverPad = panel.locator('li').nth(1);
|
|
|
|
|
await hoverPad.hover();
|
|
|
|
|
await expect(hoverPad).toHaveCSS('background-color', 'rgb(227, 227, 253)');
|
2024-04-02 12:13:06 +02:00
|
|
|
});
|
|
|
|
|
});
|