Skip to content

Commit f7cca14

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 fba7d97 commit f7cca14

File tree

7 files changed

+153
-6
lines changed

7 files changed

+153
-6
lines changed

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

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

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: 3 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

@@ -79,6 +81,7 @@ export interface Doc {
7981
children_create: boolean;
8082
children_list: boolean;
8183
collaboration_auth: boolean;
84+
comment: boolean;
8285
destroy: boolean;
8386
duplicate: boolean;
8487
favorite: boolean;

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)