Skip to content

Commit f51df8b

Browse files
AntoLClunika
authored andcommitted
🏷️(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 06d0ed9 commit f51df8b

File tree

6 files changed

+146
-4
lines changed

6 files changed

+146
-4
lines changed

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

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
keyCloakSignIn,
77
verifyDocName,
88
} from './utils-common';
9-
import { addNewMember } from './utils-share';
9+
import { addNewMember, updateRoleUser, updateShareLink } from './utils-share';
1010

1111
test.beforeEach(async ({ page }) => {
1212
await page.goto('/');
@@ -125,6 +125,10 @@ test.describe('Doc Comments', () => {
125125
await expect(
126126
thread.getByText(`E2E ${otherBrowserName}`).first(),
127127
).toBeVisible();
128+
129+
await otherPage.close();
130+
await otherContext.close();
131+
await otherBrowser.close();
128132
});
129133

130134
test('it checks the comments interactions', async ({ page, browserName }) => {
@@ -195,4 +199,130 @@ test.describe('Doc Comments', () => {
195199
'rgba(0, 0, 0, 0)',
196200
);
197201
});
202+
203+
test('it checks the comments abilities', async ({ page, browserName }) => {
204+
test.slow();
205+
206+
const [docTitle] = await createDoc(page, 'comment-doc', browserName, 1);
207+
208+
// We share the doc with another user
209+
const otherBrowserName = BROWSERS.find((b) => b !== browserName);
210+
if (!otherBrowserName) {
211+
throw new Error('No alternative browser found');
212+
}
213+
214+
// Add a new member with editor role
215+
await page.getByRole('button', { name: 'Share' }).click();
216+
await addNewMember(page, 0, 'Editor', otherBrowserName);
217+
218+
await expect(
219+
page
220+
.getByRole('listbox', { name: 'Suggestions' })
221+
.getByText(new RegExp(otherBrowserName)),
222+
).toBeVisible();
223+
224+
const urlCommentDoc = page.url();
225+
226+
// We open another browser with another user
227+
const otherBrowser = await chromium.launch({ headless: true });
228+
const otherContext = await otherBrowser.newContext({
229+
locale: 'en-US',
230+
timezoneId: 'Europe/Paris',
231+
permissions: [],
232+
storageState: {
233+
cookies: [],
234+
origins: [],
235+
},
236+
});
237+
const otherPage = await otherContext.newPage();
238+
await otherPage.goto(urlCommentDoc);
239+
240+
await otherPage.getByRole('button', { name: 'Login' }).click({
241+
timeout: 15000,
242+
});
243+
244+
await keyCloakSignIn(otherPage, otherBrowserName, false);
245+
246+
await verifyDocName(otherPage, docTitle);
247+
248+
const otherEditor = otherPage.locator('.ProseMirror');
249+
await otherEditor.fill('Hello, I can edit the document');
250+
await expect(
251+
otherEditor.getByText('Hello, I can edit the document'),
252+
).toBeVisible();
253+
await otherEditor.getByText('Hello').selectText();
254+
await otherPage.getByRole('button', { name: 'Comment' }).click();
255+
const otherThread = otherPage.locator('.bn-thread');
256+
await otherThread
257+
.getByRole('paragraph')
258+
.first()
259+
.fill('I can add a comment');
260+
await otherThread.locator('[data-test="save"]').click();
261+
262+
await expect(otherEditor.getByText('Hello')).toHaveCSS(
263+
'background-color',
264+
'rgb(244, 210, 97)',
265+
);
266+
267+
// We change the role of the second user to commenter
268+
updateRoleUser(page, 'Commenter', `user.test@${otherBrowserName}.test`);
269+
270+
// With the commenter role, the second user cannot edit the document
271+
await otherPage.reload();
272+
await verifyDocName(otherPage, docTitle);
273+
274+
const otherEditor2 = otherPage.locator('.ProseMirror');
275+
await expect(otherEditor2).toHaveAttribute('contenteditable', 'false');
276+
277+
// With the commenter role, the second user can still add comments
278+
await otherEditor.getByText('Hello').click();
279+
await otherThread
280+
.getByRole('paragraph')
281+
.last()
282+
.fill('This is a comment from the other user');
283+
await otherThread.locator('[data-test="save"]').click();
284+
await expect(
285+
otherThread.getByText('This is a comment from the other user').first(),
286+
).toBeVisible();
287+
288+
// We change the role of the second user to reader
289+
updateRoleUser(page, 'Reader', `user.test@${otherBrowserName}.test`);
290+
291+
// With the reader role, the second user cannot see comments
292+
await otherPage.reload();
293+
await verifyDocName(otherPage, docTitle);
294+
295+
await expect(otherEditor.getByText('Hello')).toHaveCSS(
296+
'background-color',
297+
'rgba(0, 0, 0, 0)',
298+
);
299+
await otherEditor.getByText('Hello').click();
300+
await expect(otherThread).toBeHidden();
301+
await otherEditor.getByText('Hello').selectText();
302+
await expect(
303+
otherPage.getByRole('button', { name: 'Comment' }),
304+
).toBeHidden();
305+
306+
await otherPage.reload();
307+
308+
// Change the link role of the doc to set it in commenting mode
309+
updateShareLink(page, 'Connected', 'Commenting');
310+
311+
// The second user with reader role can now see and add comments
312+
await otherPage.reload();
313+
await verifyDocName(otherPage, docTitle);
314+
315+
await expect(otherEditor.getByText('Hello')).toHaveCSS(
316+
'background-color',
317+
'rgb(244, 210, 97)',
318+
);
319+
await otherEditor.getByText('Hello').click();
320+
await expect(
321+
otherThread.getByText('This is a comment from the other user').first(),
322+
).toBeVisible();
323+
324+
await otherPage.close();
325+
await otherContext.close();
326+
await otherBrowser.close();
327+
});
198328
});

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: true;
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)