|
1 | 1 | import { expect, test } from '@playwright/test';
|
2 | 2 |
|
3 |
| -import { createDoc, getOtherBrowserName } from './utils-common'; |
| 3 | +import { createDoc, getOtherBrowserName, verifyDocName } from './utils-common'; |
4 | 4 | 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'; |
6 | 11 |
|
7 | 12 | test.beforeEach(async ({ page }) => {
|
8 | 13 | await page.goto('/');
|
@@ -173,4 +178,132 @@ test.describe('Doc Comments', () => {
|
173 | 178 | 'rgba(0, 0, 0, 0)',
|
174 | 179 | );
|
175 | 180 | });
|
| 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 | + }); |
176 | 309 | });
|
0 commit comments