Skip to content

Commit 67f4dde

Browse files
committed
✅(e2e) adapt e2e test without the panel
The datagrid replace the panel. Lot of tests need to be adapted to this new architecture.
1 parent 6f4b4bb commit 67f4dde

File tree

6 files changed

+150
-169
lines changed

6 files changed

+150
-169
lines changed

src/frontend/apps/e2e/__tests__/app-impress/common.ts

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,56 +33,39 @@ export const createDoc = async (
3333
length: number,
3434
isPublic: boolean = false,
3535
) => {
36-
const panel = page.getByLabel('Documents panel').first();
3736
const buttonCreate = page.getByRole('button', {
3837
name: 'Create the document',
3938
});
4039

4140
const randomDocs = randomName(docName, browserName, length);
4241

4342
for (let i = 0; i < randomDocs.length; i++) {
44-
await panel.getByRole('button', { name: 'Add a document' }).click();
45-
await page.getByText('Document name').fill(randomDocs[i]);
43+
const header = page.locator('header').first();
44+
await header.locator('h2').getByText('Docs').click();
45+
46+
const buttonCreateHomepage = page.getByRole('button', {
47+
name: 'Create a new document',
48+
});
49+
await buttonCreateHomepage.click();
50+
51+
// Fill input
52+
await page
53+
.getByRole('textbox', {
54+
name: 'Document name',
55+
})
56+
.fill(randomDocs[i]);
4657

4758
if (isPublic) {
4859
await page.getByText('Is it public ?').click();
4960
}
5061

5162
await expect(buttonCreate).toBeEnabled();
5263
await buttonCreate.click();
53-
await expect(panel.locator('li').getByText(randomDocs[i])).toBeVisible();
54-
}
55-
56-
return randomDocs;
57-
};
58-
59-
export const createTemplate = async (
60-
page: Page,
61-
templateName: string,
62-
browserName: string,
63-
length: number,
64-
) => {
65-
const menu = page.locator('menu').first();
66-
await menu.getByLabel(`Template button`).click();
67-
68-
const panel = page.getByLabel('Templates panel').first();
69-
const buttonCreate = page.getByRole('button', {
70-
name: 'Create the template',
71-
});
72-
73-
const randomTemplates = randomName(templateName, browserName, length);
7464

75-
for (let i = 0; i < randomTemplates.length; i++) {
76-
await panel.getByRole('button', { name: 'Add a template' }).click();
77-
await page.getByText('Template name').fill(randomTemplates[i]);
78-
await expect(buttonCreate).toBeEnabled();
79-
await buttonCreate.click();
80-
await expect(
81-
panel.locator('li').getByText(randomTemplates[i]),
82-
).toBeVisible();
65+
await expect(page.locator('h2').getByText(randomDocs[i])).toBeVisible();
8366
}
8467

85-
return randomTemplates;
68+
return randomDocs;
8669
};
8770

8871
export const addNewMember = async (
@@ -125,3 +108,36 @@ export const addNewMember = async (
125108

126109
return users[index].email;
127110
};
111+
112+
interface GoToGridDocOptions {
113+
nthRow?: number;
114+
title?: string;
115+
}
116+
export const goToGridDoc = async (
117+
page: Page,
118+
{ nthRow = 1, title }: GoToGridDocOptions = {},
119+
) => {
120+
const header = page.locator('header').first();
121+
await header.locator('h2').getByText('Docs').click();
122+
123+
const rows = page
124+
.getByLabel('Datagrid of the documents page 1')
125+
.getByRole('table')
126+
.getByRole('row');
127+
128+
const row = title
129+
? rows.filter({
130+
hasText: title,
131+
})
132+
: rows.nth(nthRow);
133+
134+
const docTitleCell = row.getByRole('cell').nth(1);
135+
136+
const docTitle = await docTitleCell.textContent();
137+
138+
expect(docTitle).toBeDefined();
139+
140+
await docTitleCell.click();
141+
142+
return docTitle as string;
143+
};
Lines changed: 21 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect, test } from '@playwright/test';
22

3+
import { createDoc } from './common';
4+
35
test.beforeEach(async ({ page }) => {
46
await page.goto('/');
57
});
@@ -38,6 +40,8 @@ test.describe('Doc Create', () => {
3840
name: 'Cancel',
3941
}),
4042
).toBeVisible();
43+
44+
await expect(page).toHaveURL('/docs/create/');
4145
});
4246

4347
test('checks the cancel button interaction', async ({ page }) => {
@@ -58,73 +62,28 @@ test.describe('Doc Create', () => {
5862
await expect(buttonCreateHomepage).toBeVisible();
5963
});
6064

61-
test('checks the routing on new doc created', async ({
62-
page,
63-
browserName,
64-
}) => {
65-
const panel = page.getByLabel('Documents panel').first();
66-
67-
await panel.getByRole('button', { name: 'Add a document' }).click();
68-
69-
const docName = `My routing doc ${browserName}-${Math.floor(Math.random() * 1000)}`;
70-
await page.getByText('Document name').fill(docName);
71-
await page.getByRole('button', { name: 'Create the document' }).click();
72-
73-
const elDoc = page.locator('h2').getByText(docName);
74-
await expect(elDoc).toBeVisible();
75-
76-
await panel.getByRole('button', { name: 'Add a document' }).click();
77-
await expect(elDoc).toBeHidden();
78-
79-
await panel.locator('li').getByText(docName).click();
80-
await expect(elDoc).toBeVisible();
81-
});
82-
83-
test('checks alias docs url with homepage', async ({ page }) => {
84-
await expect(page).toHaveURL('/');
85-
86-
const buttonCreateHomepage = page.getByRole('button', {
87-
name: 'Create a new document',
88-
});
65+
test('create a new public doc', async ({ page, browserName }) => {
66+
const [docTitle] = await createDoc(
67+
page,
68+
'My new doc',
69+
browserName,
70+
1,
71+
true,
72+
);
8973

90-
await expect(buttonCreateHomepage).toBeVisible();
74+
const header = page.locator('header').first();
75+
await header.locator('h2').getByText('Docs').click();
9176

92-
await page.goto('/docs');
93-
await expect(buttonCreateHomepage).toBeVisible();
94-
await expect(page).toHaveURL(/\/docs$/);
95-
});
77+
const datagrid = page
78+
.getByLabel('Datagrid of the documents page 1')
79+
.getByRole('table');
9680

97-
test('checks 404 on docs/[id] page', async ({ page }) => {
98-
// eslint-disable-next-line playwright/no-wait-for-timeout
99-
await page.waitForTimeout(300);
81+
await expect(datagrid.getByText(docTitle)).toBeVisible();
10082

101-
await page.goto('/docs/some-unknown-doc');
102-
await expect(
103-
page.getByText(
104-
'It seems that the page you are looking for does not exist or cannot be displayed correctly.',
105-
),
106-
).toBeVisible({
107-
timeout: 15000,
83+
const row = datagrid.getByRole('row').filter({
84+
hasText: docTitle,
10885
});
109-
});
110-
111-
test('checks that the doc is public', async ({ page, browserName }) => {
112-
const responsePromiseDoc = page.waitForResponse(
113-
(response) =>
114-
response.url().includes('/documents/') && response.status() === 201,
115-
);
116-
117-
const panel = page.getByLabel('Documents panel').first();
118-
119-
await panel.getByRole('button', { name: 'Add a document' }).click();
120-
121-
const docName = `My routing doc ${browserName}-${Math.floor(Math.random() * 1000)}`;
122-
await page.getByText('Document name').fill(docName);
123-
await page.getByText('Is it public ?').click();
124-
await page.getByRole('button', { name: 'Create the document' }).click();
12586

126-
const responseDoc = await responsePromiseDoc;
127-
const is_public = (await responseDoc.json()).is_public;
128-
expect(is_public).toBeTruthy();
87+
await expect(row.getByRole('cell').nth(0)).toHaveText('Public');
12988
});
13089
});

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { createDoc } from './common';
3+
import { createDoc, goToGridDoc } from './common';
44

55
test.beforeEach(async ({ page }) => {
66
await page.goto('/');
@@ -76,77 +76,56 @@ test.describe('Doc Editor', () => {
7676

7777
test('it renders correctly when we switch from one doc to another', async ({
7878
page,
79-
browserName,
8079
}) => {
81-
const [firstDoc, secondDoc] = await createDoc(
82-
page,
83-
'doc-multiple',
84-
browserName,
85-
2,
86-
);
87-
88-
const panel = page.getByLabel('Documents panel').first();
89-
9080
// Check the first doc
91-
await panel.getByText(firstDoc).click();
81+
const firstDoc = await goToGridDoc(page);
9282
await expect(page.locator('h2').getByText(firstDoc)).toBeVisible();
9383
await page.locator('.ProseMirror.bn-editor').click();
9484
await page.locator('.ProseMirror.bn-editor').fill('Hello World Doc 1');
9585
await expect(page.getByText('Hello World Doc 1')).toBeVisible();
9686

9787
// Check the second doc
98-
await panel.getByText(secondDoc).click();
88+
const secondDoc = await goToGridDoc(page, {
89+
nthRow: 2,
90+
});
9991
await expect(page.locator('h2').getByText(secondDoc)).toBeVisible();
10092
await expect(page.getByText('Hello World Doc 1')).toBeHidden();
10193
await page.locator('.ProseMirror.bn-editor').click();
10294
await page.locator('.ProseMirror.bn-editor').fill('Hello World Doc 2');
10395
await expect(page.getByText('Hello World Doc 2')).toBeVisible();
10496

10597
// Check the first doc again
106-
await panel.getByText(firstDoc).click();
98+
await goToGridDoc(page, {
99+
title: firstDoc,
100+
});
107101
await expect(page.locator('h2').getByText(firstDoc)).toBeVisible();
108102
await expect(page.getByText('Hello World Doc 2')).toBeHidden();
109103
await expect(page.getByText('Hello World Doc 1')).toBeVisible();
110104
});
111105

112-
test('it saves the doc when we change pages', async ({
113-
page,
114-
browserName,
115-
}) => {
116-
const [doc] = await createDoc(page, 'doc-save-page', browserName, 1);
117-
118-
const panel = page.getByLabel('Documents panel').first();
119-
106+
test('it saves the doc when we change pages', async ({ page }) => {
120107
// Check the first doc
121-
await panel.getByText(doc).click();
108+
const doc = await goToGridDoc(page);
122109
await expect(page.locator('h2').getByText(doc)).toBeVisible();
123110
await page.locator('.ProseMirror.bn-editor').click();
124111
await page
125112
.locator('.ProseMirror.bn-editor')
126113
.fill('Hello World Doc persisted 1');
127114
await expect(page.getByText('Hello World Doc persisted 1')).toBeVisible();
128115

129-
await panel
130-
.getByRole('button', {
131-
name: 'Add a document',
132-
})
133-
.click();
116+
const secondDoc = await goToGridDoc(page, {
117+
nthRow: 2,
118+
});
134119

135120
await expect(
136121
page.getByText(`Your document "${doc}" has been saved.`),
137122
).toBeVisible();
138123

139-
const card = page.getByLabel('Create new document card').first();
140-
await expect(
141-
card.getByRole('heading', {
142-
name: 'Name the document',
143-
level: 3,
144-
}),
145-
).toBeVisible();
146-
147-
await page.goto('/');
124+
await expect(page.locator('h2').getByText(secondDoc)).toBeVisible();
148125

149-
await panel.getByText(doc).click();
126+
await goToGridDoc(page, {
127+
title: doc,
128+
});
150129

151130
await expect(page.getByText('Hello World Doc persisted 1')).toBeVisible();
152131
});
@@ -155,12 +134,8 @@ test.describe('Doc Editor', () => {
155134
// eslint-disable-next-line playwright/no-skipped-test
156135
test.skip(browserName === 'webkit', 'This test is very flaky with webkit');
157136

158-
const [doc] = await createDoc(page, 'doc-save-quit', browserName, 1);
159-
160-
const panel = page.getByLabel('Documents panel').first();
161-
162137
// Check the first doc
163-
await panel.getByText(doc).click();
138+
const doc = await goToGridDoc(page);
164139
await expect(page.locator('h2').getByText(doc)).toBeVisible();
165140
await page.locator('.ProseMirror.bn-editor').click();
166141
await page
@@ -170,12 +145,14 @@ test.describe('Doc Editor', () => {
170145

171146
await page.goto('/');
172147

173-
await panel.getByText(doc).click();
148+
await goToGridDoc(page, {
149+
title: doc,
150+
});
174151

175152
await expect(page.getByText('Hello World Doc persisted 2')).toBeVisible();
176153
});
177154

178-
test('it cannot edit if viewer', async ({ page, browserName }) => {
155+
test('it cannot edit if viewer', async ({ page }) => {
179156
await page.route('**/documents/**/', async (route) => {
180157
const request = route.request();
181158
if (
@@ -206,7 +183,7 @@ test.describe('Doc Editor', () => {
206183
}
207184
});
208185

209-
await createDoc(page, 'doc-right-edit', browserName, 1);
186+
await goToGridDoc(page);
210187

211188
await expect(
212189
page.getByText(

src/frontend/apps/e2e/__tests__/app-impress/doc-member-grid.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { createDoc } from './common';
3+
import { createDoc, goToGridDoc } from './common';
44

55
test.beforeEach(async ({ page }) => {
66
await page.goto('/');
@@ -27,10 +27,7 @@ test.describe('Document grid members', () => {
2727
);
2828
});
2929

30-
test('it display the grid with many members', async ({
31-
page,
32-
browserName,
33-
}) => {
30+
test('it display the grid with many members', async ({ page }) => {
3431
await page.route('**/documents/*/', async (route) => {
3532
const request = route.request();
3633
if (
@@ -91,7 +88,7 @@ test.describe('Document grid members', () => {
9188
},
9289
);
9390

94-
await createDoc(page, 'grid-no-member', browserName, 1);
91+
await goToGridDoc(page);
9592

9693
await page.getByLabel('Open the document options').click();
9794
await page.getByRole('button', { name: 'Manage members' }).click();

0 commit comments

Comments
 (0)