Skip to content

Commit 3ed3383

Browse files
committed
🏷️(frontend) add commenter type
Our document got new types: - user can be commenters, commenters can view and add comments to documents but cannot edit the document content itself. - document can be in 'commenters' mode, allowing viewers to add comments.
1 parent 555585e commit 3ed3383

File tree

7 files changed

+155
-6
lines changed

7 files changed

+155
-6
lines changed

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

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

3-
import { createDoc, getOtherBrowserName } from './utils-common';
3+
import { createDoc, getOtherBrowserName, verifyDocName } from './utils-common';
44
import { writeInEditor } from './utils-editor';
5-
import { addNewMember, connectOtherUserToDoc } from './utils-share';
5+
import {
6+
addNewMember,
7+
connectOtherUserToDoc,
8+
updateRoleUser,
9+
updateShareLink,
10+
} from './utils-share';
611

712
test.beforeEach(async ({ page }) => {
813
await page.goto('/');
@@ -177,4 +182,135 @@ test.describe('Doc Comments', () => {
177182
'rgba(0, 0, 0, 0)',
178183
);
179184
});
185+
186+
test('it checks the comments abilities', async ({ page, browserName }) => {
187+
test.slow();
188+
189+
const [docTitle] = await createDoc(page, 'comment-doc', browserName, 1);
190+
191+
// We share the doc with another user
192+
const otherBrowserName = getOtherBrowserName(browserName);
193+
194+
// Add a new member with editor role
195+
await page.getByRole('button', { name: 'Share' }).click();
196+
await addNewMember(page, 0, 'Editor', otherBrowserName);
197+
198+
await expect(
199+
page
200+
.getByRole('listbox', { name: 'Suggestions' })
201+
.getByText(new RegExp(otherBrowserName)),
202+
).toBeVisible();
203+
204+
const urlCommentDoc = page.url();
205+
206+
const { otherPage, cleanup } = await connectOtherUserToDoc({
207+
otherBrowserName,
208+
docUrl: urlCommentDoc,
209+
docTitle,
210+
});
211+
212+
const otherEditor = await writeInEditor({
213+
page: otherPage,
214+
text: 'Hello, I can edit the document',
215+
});
216+
await expect(
217+
otherEditor.getByText('Hello, I can edit the document'),
218+
).toBeVisible();
219+
await otherEditor.getByText('Hello').selectText();
220+
await otherPage.getByRole('button', { name: 'Comment' }).click();
221+
const otherThread = otherPage.locator('.bn-thread');
222+
await otherThread
223+
.getByRole('paragraph')
224+
.first()
225+
.fill('I can add a comment');
226+
await otherThread.locator('[data-test="save"]').click();
227+
await expect(
228+
otherThread.getByText('I can add a comment').first(),
229+
).toBeHidden();
230+
231+
await expect(otherEditor.getByText('Hello')).toHaveCSS(
232+
'background-color',
233+
'rgba(237, 180, 0, 0.4)',
234+
);
235+
236+
// We change the role of the second user to commenter
237+
updateRoleUser(page, 'Commenter', `user.test@${otherBrowserName}.test`);
238+
239+
// With the commenter role, the second user cannot edit the document
240+
await otherPage.reload();
241+
await verifyDocName(otherPage, docTitle);
242+
243+
const otherEditor2 = otherPage.locator('.ProseMirror');
244+
await expect(otherEditor2).toHaveAttribute('contenteditable', 'false');
245+
246+
// With the commenter role, the second user can still add comments
247+
await otherEditor.getByText('Hello').click();
248+
await otherThread
249+
.getByRole('paragraph')
250+
.last()
251+
.fill('This is a comment from the other user');
252+
await otherThread.locator('[data-test="save"]').click();
253+
await expect(
254+
otherThread.getByText('This is a comment from the other user').first(),
255+
).toBeVisible();
256+
257+
// We change the role of the second user to reader
258+
updateRoleUser(page, 'Reader', `user.test@${otherBrowserName}.test`);
259+
260+
// With the reader role, the second user cannot see comments
261+
await otherPage.reload();
262+
await verifyDocName(otherPage, docTitle);
263+
264+
await expect(otherEditor.getByText('Hello')).toHaveCSS(
265+
'background-color',
266+
'rgba(0, 0, 0, 0)',
267+
);
268+
await otherEditor.getByText('Hello').click();
269+
await expect(otherThread).toBeHidden();
270+
await otherEditor.getByText('Hello').selectText();
271+
await expect(
272+
otherPage.getByRole('button', { name: 'Comment' }),
273+
).toBeHidden();
274+
275+
await otherPage.reload();
276+
277+
// Change the link role of the doc to set it in commenting mode
278+
updateShareLink(page, 'Public', 'Commenting');
279+
280+
// Anonymous user can see and add comments
281+
await otherPage.getByRole('button', { name: 'Logout' }).click();
282+
283+
await otherPage.goto(urlCommentDoc);
284+
285+
await verifyDocName(otherPage, docTitle);
286+
287+
await expect(otherEditor.getByText('Hello')).toHaveCSS(
288+
'background-color',
289+
'rgba(237, 180, 0, 0.4)',
290+
);
291+
await otherEditor.getByText('Hello').click();
292+
await expect(
293+
otherThread.getByText('This is a comment from the other user').first(),
294+
).toBeVisible();
295+
296+
await otherThread
297+
.locator('.ProseMirror.bn-editor[contenteditable="true"]')
298+
.getByRole('paragraph')
299+
.first()
300+
.fill('Comment by anonymous user');
301+
await otherThread.locator('[data-test="save"]').click();
302+
303+
await expect(
304+
otherThread.getByText('Comment by anonymous user').first(),
305+
).toBeVisible();
306+
307+
await expect(
308+
otherThread.getByRole('img', { name: `Anonymous` }).first(),
309+
).toBeVisible();
310+
311+
await otherThread.getByText('Comment by anonymous user').first().hover();
312+
await expect(otherThread.locator('[data-test="moreactions"]')).toBeHidden();
313+
314+
await cleanup();
315+
});
180316
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ export const verifyDocName = async (page: Page, docName: string) => {
132132
try {
133133
await expect(
134134
page.getByRole('textbox', { name: 'Document title' }),
135-
).toContainText(docName);
135+
).toContainText(docName, {
136+
timeout: 1000,
137+
});
136138
} catch {
137139
await expect(page.getByRole('heading', { name: docName })).toBeVisible();
138140
}

src/frontend/apps/e2e/__tests__/app-impress/utils-share.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ import {
77
verifyDocName,
88
} from './utils-common';
99

10-
export type Role = 'Administrator' | 'Owner' | 'Member' | 'Editor' | 'Reader';
10+
export type Role =
11+
| 'Administrator'
12+
| 'Owner'
13+
| 'Member'
14+
| 'Editor'
15+
| 'Reader'
16+
| 'Commenter';
1117
export type LinkReach = 'Private' | 'Connected' | 'Public';
12-
export type LinkRole = 'Reading' | 'Edition';
18+
export type LinkRole = 'Reading' | 'Edition' | 'Commenting';
1319

1420
export const addNewMember = async (
1521
page: Page,
1622
index: number,
17-
role: 'Administrator' | 'Owner' | 'Editor' | 'Reader',
23+
role: Role,
1824
fillText: string = 'user.test',
1925
) => {
2026
const responsePromiseSearchUser = page.waitForResponse(

src/frontend/apps/impress/src/features/docs/doc-management/hooks/useTrans.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const useTrans = () => {
77

88
const translatedRoles = {
99
[Role.READER]: t('Reader'),
10+
[Role.COMMENTER]: t('Commenter'),
1011
[Role.EDITOR]: t('Editor'),
1112
[Role.ADMIN]: t('Administrator'),
1213
[Role.OWNER]: t('Owner'),

src/frontend/apps/impress/src/features/docs/doc-management/types.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Access {
2323

2424
export enum Role {
2525
READER = 'reader',
26+
COMMENTER = 'commenter',
2627
EDITOR = 'editor',
2728
ADMIN = 'administrator',
2829
OWNER = 'owner',
@@ -43,6 +44,7 @@ export enum LinkReach {
4344

4445
export enum LinkRole {
4546
READER = 'reader',
47+
COMMENTER = 'commenter',
4648
EDITOR = 'editor',
4749
}
4850

src/frontend/apps/impress/src/features/docs/doc-share/hooks/useTranslatedShareSettings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const useTranslatedShareSettings = () => {
1313

1414
const linkModeTranslations = {
1515
[LinkRole.READER]: t('Reading'),
16+
[LinkRole.COMMENTER]: t('Commenting'),
1617
[LinkRole.EDITOR]: t('Editing'),
1718
};
1819

src/frontend/apps/impress/src/features/service-worker/plugins/ApiPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export class ApiPlugin implements WorkboxPlugin {
187187
children_create: true,
188188
children_list: true,
189189
collaboration_auth: true,
190+
comment: true,
190191
destroy: true,
191192
duplicate: true,
192193
favorite: true,

0 commit comments

Comments
 (0)