| 
6 | 6 |   keyCloakSignIn,  | 
7 | 7 |   verifyDocName,  | 
8 | 8 | } from './utils-common';  | 
9 |  | -import { addNewMember } from './utils-share';  | 
 | 9 | +import { addNewMember, updateRoleUser, updateShareLink } from './utils-share';  | 
10 | 10 | 
 
  | 
11 | 11 | test.beforeEach(async ({ page }) => {  | 
12 | 12 |   await page.goto('/');  | 
@@ -125,6 +125,10 @@ test.describe('Doc Comments', () => {  | 
125 | 125 |     await expect(  | 
126 | 126 |       thread.getByText(`E2E ${otherBrowserName}`).first(),  | 
127 | 127 |     ).toBeVisible();  | 
 | 128 | + | 
 | 129 | +    await otherPage.close();  | 
 | 130 | +    await otherContext.close();  | 
 | 131 | +    await otherBrowser.close();  | 
128 | 132 |   });  | 
129 | 133 | 
 
  | 
130 | 134 |   test('it checks the comments interactions', async ({ page, browserName }) => {  | 
@@ -195,4 +199,130 @@ test.describe('Doc Comments', () => {  | 
195 | 199 |       'rgba(0, 0, 0, 0)',  | 
196 | 200 |     );  | 
197 | 201 |   });  | 
 | 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 | +  });  | 
198 | 328 | });  | 
0 commit comments