11import { expect , test } from '@playwright/test' ;
22
3- import { createDoc , getGridRow } from './utils-common' ;
3+ import { createDoc , getGridRow , verifyDocName } from './utils-common' ;
4+ import { addNewMember , connectOtherUserToDoc } from './utils-share' ;
45
56type SmallDoc = {
67 id : string ;
@@ -11,7 +12,7 @@ test.describe('Documents Grid mobile', () => {
1112 test . use ( { viewport : { width : 500 , height : 1200 } } ) ;
1213
1314 test ( 'it checks the grid when mobile' , async ( { page } ) => {
14- await page . route ( '** /documents/**' , async ( route ) => {
15+ await page . route ( / . * \ /d o c u m e n t s \/ . * / , async ( route ) => {
1516 const request = route . request ( ) ;
1617 if ( request . method ( ) . includes ( 'GET' ) && request . url ( ) . includes ( 'page=' ) ) {
1718 await route . fulfill ( {
@@ -161,7 +162,7 @@ test.describe('Document grid item options', () => {
161162 test ( "it checks if the delete option is disabled if we don't have the destroy capability" , async ( {
162163 page,
163164 } ) => {
164- await page . route ( '*/** /api/v1.0/documents/ ?page=1' , async ( route ) => {
165+ await page . route ( / . * \ /a p i \ /v 1 .0 \ /d o c u m e n t s \/ \ ?p a g e = 1 / , async ( route ) => {
165166 await route . fulfill ( {
166167 json : {
167168 results : [
@@ -192,90 +193,68 @@ test.describe('Document grid item options', () => {
192193 } ) ;
193194 await page . goto ( '/' ) ;
194195
195- const button = page . getByTestId (
196- `docs-grid-actions-button-mocked-document-id` ,
197- ) ;
196+ const button = page
197+ . getByTestId ( `docs-grid-actions-button-mocked-document-id` )
198+ . first ( ) ;
198199 await expect ( button ) . toBeVisible ( ) ;
199200 await button . click ( ) ;
200- const removeButton = page . getByTestId (
201- `docs-grid-actions-remove-mocked-document-id` ,
202- ) ;
201+ const removeButton = page
202+ . getByTestId ( `docs-grid-actions-remove-mocked-document-id` )
203+ . first ( ) ;
203204 await expect ( removeButton ) . toBeVisible ( ) ;
204205 await removeButton . isDisabled ( ) ;
205206 } ) ;
206207} ) ;
207208
208209test . describe ( 'Documents filters' , ( ) => {
209- test ( 'it checks the prebuild left panel filters' , async ( { page } ) => {
210+ test ( 'it checks the left panel filters' , async ( { page, browserName } ) => {
210211 void page . goto ( '/' ) ;
211212
212- // All Docs
213- const response = await page . waitForResponse (
214- ( response ) =>
215- response . url ( ) . endsWith ( 'documents/?page=1' ) &&
216- response . status ( ) === 200 ,
217- ) ;
218- const result = await response . json ( ) ;
219- const allCount = result . count as number ;
220- await expect ( page . getByTestId ( 'grid-loader' ) ) . toBeHidden ( ) ;
213+ // Create my doc
214+ const [ docName ] = await createDoc ( page , 'my-doc' , browserName , 1 ) ;
215+ await verifyDocName ( page , docName ) ;
216+
217+ // Another user create a doc and share it with me
218+ const { cleanup, otherPage, otherBrowserName } =
219+ await connectOtherUserToDoc ( {
220+ browserName,
221+ docUrl : '/' ,
222+ } ) ;
221223
222- const allDocs = page . getByLabel ( 'All docs' ) ;
223- const myDocs = page . getByLabel ( 'My docs' ) ;
224- const sharedWithMe = page . getByLabel ( 'Shared with me' ) ;
224+ const [ docShareName ] = await createDoc (
225+ otherPage ,
226+ 'my-share-doc' ,
227+ otherBrowserName ,
228+ 1 ,
229+ ) ;
225230
226- // Initial state
227- await expect ( allDocs ) . toBeVisible ( ) ;
228- await expect ( allDocs ) . toHaveAttribute ( 'aria-current' , 'page' ) ;
231+ await verifyDocName ( otherPage , docShareName ) ;
229232
230- await expect ( myDocs ) . toBeVisible ( ) ;
231- await expect ( myDocs ) . toHaveCSS ( 'background-color' , 'rgba(0, 0, 0, 0)' ) ;
232- await expect ( myDocs ) . not . toHaveAttribute ( 'aria-current' ) ;
233+ await otherPage . getByRole ( 'button' , { name : 'Share' } ) . click ( ) ;
233234
234- await expect ( sharedWithMe ) . toBeVisible ( ) ;
235- await expect ( sharedWithMe ) . toHaveCSS (
236- 'background-color' ,
237- 'rgba(0, 0, 0, 0)' ,
238- ) ;
239- await expect ( sharedWithMe ) . not . toHaveAttribute ( 'aria-current' ) ;
235+ await addNewMember ( otherPage , 0 , 'Editor' , browserName ) ;
240236
241- await allDocs . click ( ) ;
237+ // Let's check the filters
238+ await page . getByRole ( 'button' , { name : 'Back to homepage' } ) . click ( ) ;
242239
243- await page . waitForURL ( '**/?target=all_docs' ) ;
240+ const row = await getGridRow ( page , docName ) ;
241+ const rowShare = await getGridRow ( page , docShareName ) ;
244242
245- let url = new URL ( page . url ( ) ) ;
246- let target = url . searchParams . get ( 'target' ) ;
247- expect ( target ) . toBe ( 'all_docs' ) ;
243+ // All Docs
244+ await expect ( row ) . toBeVisible ( ) ;
245+ await expect ( rowShare ) . toBeVisible ( ) ;
248246
249- // My docs
250- await myDocs . click ( ) ;
251- url = new URL ( page . url ( ) ) ;
252- target = url . searchParams . get ( 'target' ) ;
253- expect ( target ) . toBe ( 'my_docs' ) ;
254- const responseMyDocs = await page . waitForResponse (
255- ( response ) =>
256- response . url ( ) . endsWith ( 'documents/?page=1&is_creator_me=true' ) &&
257- response . status ( ) === 200 ,
258- ) ;
259- const resultMyDocs = await responseMyDocs . json ( ) ;
260- const countMyDocs = resultMyDocs . count as number ;
261- await expect ( page . getByTestId ( 'grid-loader' ) ) . toBeHidden ( ) ;
262- expect ( countMyDocs ) . toBeLessThanOrEqual ( allCount ) ;
247+ // My Docs
248+ await page . getByRole ( 'link' , { name : 'My docs' } ) . click ( ) ;
249+ await expect ( row ) . toBeVisible ( ) ;
250+ await expect ( rowShare ) . toBeHidden ( ) ;
263251
264252 // Shared with me
265- await sharedWithMe . click ( ) ;
266- url = new URL ( page . url ( ) ) ;
267- target = url . searchParams . get ( 'target' ) ;
268- expect ( target ) . toBe ( 'shared_with_me' ) ;
269- const responseSharedWithMe = await page . waitForResponse (
270- ( response ) =>
271- response . url ( ) . includes ( 'documents/?page=1&is_creator_me=false' ) &&
272- response . status ( ) === 200 ,
273- ) ;
274- const resultSharedWithMe = await responseSharedWithMe . json ( ) ;
275- const countSharedWithMe = resultSharedWithMe . count as number ;
276- await expect ( page . getByTestId ( 'grid-loader' ) ) . toBeHidden ( ) ;
277- expect ( countSharedWithMe ) . toBeLessThanOrEqual ( allCount ) ;
278- expect ( countSharedWithMe + countMyDocs ) . toEqual ( allCount ) ;
253+ await page . getByRole ( 'link' , { name : 'Shared with me' } ) . click ( ) ;
254+ await expect ( row ) . toBeHidden ( ) ;
255+ await expect ( rowShare ) . toBeVisible ( ) ;
256+
257+ await cleanup ( ) ;
279258 } ) ;
280259} ) ;
281260
0 commit comments