77 keyCloakSignIn ,
88 verifyDocName ,
99} from './utils-common' ;
10- import { writeInEditor } from './utils-editor' ;
10+ import { getEditor , writeInEditor } from './utils-editor' ;
1111import { addNewMember , connectOtherUserToDoc } from './utils-share' ;
1212import { createRootSubPage } from './utils-sub-pages' ;
1313
@@ -182,15 +182,14 @@ test.describe('Doc Visibility: Restricted', () => {
182182} ) ;
183183
184184test . describe ( 'Doc Visibility: Public' , ( ) => {
185- test . use ( { storageState : { cookies : [ ] , origins : [ ] } } ) ;
185+ test . beforeEach ( async ( { page } ) => {
186+ await page . goto ( '/' ) ;
187+ } ) ;
186188
187189 test ( 'It checks a public doc in read only mode' , async ( {
188190 page,
189191 browserName,
190192 } ) => {
191- await page . goto ( '/' ) ;
192- await keyCloakSignIn ( page , browserName ) ;
193-
194193 const [ docTitle ] = await createDoc (
195194 page ,
196195 'Public read only' ,
@@ -200,6 +199,8 @@ test.describe('Doc Visibility: Public', () => {
200199
201200 await verifyDocName ( page , docTitle ) ;
202201
202+ await writeInEditor ( { page, text : 'Hello Public Viewonly' } ) ;
203+
203204 await page . getByRole ( 'button' , { name : 'Share' } ) . click ( ) ;
204205 const selectVisibility = page . getByTestId ( 'doc-visibility' ) ;
205206 await selectVisibility . click ( ) ;
@@ -241,49 +242,63 @@ test.describe('Doc Visibility: Public', () => {
241242 await expect ( page . getByTestId ( 'search-docs-button' ) ) . toBeVisible ( ) ;
242243 await expect ( page . getByTestId ( 'new-doc-button' ) ) . toBeVisible ( ) ;
243244
244- const urlDoc = page . url ( ) ;
245-
246- await page
247- . getByRole ( 'button' , {
248- name : 'Logout' ,
249- } )
250- . click ( ) ;
251-
252- await expectLoginPage ( page ) ;
245+ const docUrl = page . url ( ) ;
253246
254- await page . goto ( urlDoc ) ;
247+ const { otherPage, cleanup } = await connectOtherUserToDoc ( {
248+ browserName,
249+ docUrl,
250+ withoutSignIn : true ,
251+ } ) ;
255252
256- await expect ( page . locator ( 'h2' ) . getByText ( docTitle ) ) . toBeVisible ( ) ;
257- await expect ( page . getByTestId ( 'search-docs-button' ) ) . toBeHidden ( ) ;
258- await expect ( page . getByTestId ( 'new-doc-button' ) ) . toBeHidden ( ) ;
259- await expect ( page . getByRole ( 'button' , { name : 'Share' } ) ) . toBeVisible ( ) ;
260- const card = page . getByLabel ( 'It is the card information' ) ;
253+ await expect ( otherPage . locator ( 'h2' ) . getByText ( docTitle ) ) . toBeVisible ( ) ;
254+ await expect ( otherPage . getByTestId ( 'search-docs-button' ) ) . toBeHidden ( ) ;
255+ await expect ( otherPage . getByTestId ( 'new-doc-button' ) ) . toBeHidden ( ) ;
256+ await expect (
257+ otherPage . getByRole ( 'button' , { name : 'Share' } ) ,
258+ ) . toBeVisible ( ) ;
259+ const card = otherPage . getByLabel ( 'It is the card information' ) ;
261260 await expect ( card ) . toBeVisible ( ) ;
262261 await expect ( card . getByText ( 'Reader' ) ) . toBeVisible ( ) ;
263262
264- await page . getByRole ( 'button' , { name : 'Share' } ) . click ( ) ;
263+ const otherEditor = await getEditor ( { page : otherPage } ) ;
264+ await expect ( otherEditor ) . toHaveAttribute ( 'contenteditable' , 'false' ) ;
265+ await expect ( otherEditor . getByText ( 'Hello Public Viewonly' ) ) . toBeVisible ( ) ;
266+
267+ // Cursor and selection of the anonymous user are not visible
268+ await otherEditor . getByText ( 'Hello Public' ) . selectText ( ) ;
265269 await expect (
266- page . getByText (
270+ page . locator ( '.collaboration-cursor-custom__base' ) ,
271+ ) . toBeHidden ( ) ;
272+ await expect ( page . locator ( '.ProseMirror-yjs-selection' ) ) . toBeHidden ( ) ;
273+
274+ // Can still see changes made by others
275+ await writeInEditor ( { page, text : 'Can you see it ?' } ) ;
276+ await expect ( otherEditor . getByText ( 'Can you see it ?' ) ) . toBeVisible ( ) ;
277+
278+ await otherPage . getByRole ( 'button' , { name : 'Share' } ) . click ( ) ;
279+ await expect (
280+ otherPage . getByText (
267281 'You can view this document but need additional access to see its members or modify settings.' ,
268282 ) ,
269283 ) . toBeVisible ( ) ;
270284
271285 await expect (
272- page . getByRole ( 'button' , { name : 'Request access' } ) ,
286+ otherPage . getByRole ( 'button' , { name : 'Request access' } ) ,
273287 ) . toBeHidden ( ) ;
288+
289+ await cleanup ( ) ;
274290 } ) ;
275291
276292 test ( 'It checks a public doc in editable mode' , async ( {
277293 page,
278294 browserName,
279295 } ) => {
280- await page . goto ( '/' ) ;
281- await keyCloakSignIn ( page , browserName ) ;
282-
283296 const [ docTitle ] = await createDoc ( page , 'Public editable' , browserName , 1 ) ;
284297
285298 await verifyDocName ( page , docTitle ) ;
286299
300+ await writeInEditor ( { page, text : 'Hello Public Editable' } ) ;
301+
287302 await page . getByRole ( 'button' , { name : 'Share' } ) . click ( ) ;
288303 const selectVisibility = page . getByTestId ( 'doc-visibility' ) ;
289304 await selectVisibility . click ( ) ;
@@ -317,20 +332,47 @@ test.describe('Doc Visibility: Public', () => {
317332 cardContainer . getByText ( 'Public document' , { exact : true } ) ,
318333 ) . toBeVisible ( ) ;
319334
320- const urlDoc = page . url ( ) ;
335+ const docUrl = page . url ( ) ;
321336
322- await page
323- . getByRole ( 'button' , {
324- name : 'Logout' ,
325- } )
326- . click ( ) ;
337+ const { otherPage, cleanup } = await connectOtherUserToDoc ( {
338+ browserName,
339+ docUrl,
340+ withoutSignIn : true ,
341+ docTitle,
342+ } ) ;
327343
328- await expectLoginPage ( page ) ;
344+ await expect ( otherPage . getByTestId ( 'search-docs-button' ) ) . toBeHidden ( ) ;
345+ await expect ( otherPage . getByTestId ( 'new-doc-button' ) ) . toBeHidden ( ) ;
329346
330- await page . goto ( urlDoc ) ;
347+ const otherEditor = await getEditor ( { page : otherPage } ) ;
348+ await expect ( otherEditor ) . toHaveAttribute ( 'contenteditable' , 'true' ) ;
349+ await expect ( otherEditor . getByText ( 'Hello Public Editable' ) ) . toBeVisible ( ) ;
331350
332- await verifyDocName ( page , docTitle ) ;
333- await expect ( page . getByRole ( 'button' , { name : 'Share' } ) ) . toBeVisible ( ) ;
351+ // We can see the collaboration cursor of the anonymous user
352+ await otherEditor . getByText ( 'Hello Public' ) . selectText ( ) ;
353+ await expect (
354+ page . locator ( '.collaboration-cursor-custom__base' ) . getByText ( 'Anonymous' ) ,
355+ ) . toBeVisible ( ) ;
356+
357+ await expect (
358+ otherPage . getByRole ( 'button' , { name : 'Share' } ) ,
359+ ) . toBeVisible ( ) ;
360+ const card = otherPage . getByLabel ( 'It is the card information' ) ;
361+ await expect ( card ) . toBeVisible ( ) ;
362+ await expect ( card . getByText ( 'Editor' ) ) . toBeVisible ( ) ;
363+
364+ await otherPage . getByRole ( 'button' , { name : 'Share' } ) . click ( ) ;
365+ await expect (
366+ otherPage . getByText (
367+ 'You can view this document but need additional access to see its members or modify settings.' ,
368+ ) ,
369+ ) . toBeVisible ( ) ;
370+
371+ await expect (
372+ otherPage . getByRole ( 'button' , { name : 'Request access' } ) ,
373+ ) . toBeHidden ( ) ;
374+
375+ await cleanup ( ) ;
334376 } ) ;
335377} ) ;
336378
0 commit comments