import { AdminActions , SITE_VISIBILITY , SITE_ROLES , LoginPage , BrowsingPage , Utils , RepoClient } from '@alfresco/aca-testing-shared' ; describe ( 'Shared Files' , ( ) => { const username = `user-${ Utils . random ( ) }` ; const password = username ; const siteName = `site-${ Utils . random ( ) }` ; const fileAdmin = `fileSite-${ Utils . random ( ) }.txt` ; const folderUser = `folder-${ Utils . random ( ) }` ; let folderId ; const file1User = `file1-${ Utils . random ( ) }.txt` ; let file1Id ; const file2User = `file2-${ Utils . random ( ) }.txt` ; let file2Id ; const file3User = `file3-${ Utils . random ( ) }.txt` ; let file3Id ; const file4User = `file4-${ Utils . random ( ) }.txt` ; let file4Id ; const apis = { user : new RepoClient ( username , password ) } ; const loginPage = new LoginPage ( ) ; const page = new BrowsingPage ( ) ; const { dataTable , breadcrumb } = page ; const adminApiActions = new AdminActions ( ) ; beforeAll ( async ( done ) => { await adminApiActions . createUser ( { username } ) ; await adminApiActions . sites . createSite ( siteName , SITE_VISIBILITY . PUBLIC ) ; await adminApiActions . sites . addSiteMember ( siteName , username , SITE_ROLES . SITE_CONSUMER . ROLE ) ; const docLibId = await adminApiActions . sites . getDocLibId ( siteName ) ; const nodeId = ( await adminApiActions . nodes . createFile ( fileAdmin , docLibId ) ) . entry . id ; await adminApiActions . shareNodes ( [ nodeId ] ) ; await adminApiActions . shared . waitForFilesToBeShared ( [ nodeId ] ) ; folderId = ( await apis . user . nodes . createFolder ( folderUser ) ) . entry . id ; file1Id = ( await apis . user . nodes . createFile ( file1User , folderId ) ) . entry . id ; file2Id = ( await apis . user . nodes . createFile ( file2User ) ) . entry . id ; file3Id = ( await apis . user . nodes . createFile ( file3User ) ) . entry . id ; file4Id = ( await apis . user . nodes . createFile ( file4User ) ) . entry . id ; await apis . user . shared . shareFilesByIds ( [ file1Id , file2Id , file3Id , file4Id ] ) ; await apis . user . shared . waitForFilesToBeShared ( [ file1Id , file2Id , file3Id , file4Id ] ) ; await apis . user . nodes . deleteNodeById ( file2Id ) ; await apis . user . shared . unshareFileById ( file3Id ) ; await apis . user . shared . waitForFilesToNotBeShared ( [ file2Id , file3Id ] ) ; await loginPage . loginWith ( username ) ; done ( ) ; } ) ; beforeEach ( async ( done ) => { await page . clickSharedFilesAndWait ( ) ; done ( ) ; } ) ; afterAll ( async ( ) => { await adminApiActions . sites . deleteSite ( siteName ) ; await apis . user . nodes . deleteNodeById ( folderId ) ; await apis . user . nodes . deleteNodeById ( file4Id ) ; } ) ; it ( '[C213113] has the correct columns' , async ( ) => { const expectedColumns = [ 'Name' , 'Location' , 'Size' , 'Modified' , 'Modified by' , 'Shared by' ] ; const actualColumns = await dataTable . getColumnHeadersText ( ) ; await expect ( actualColumns ) . toEqual ( expectedColumns ) ; } ) ; it ( '[C213115] default sorting column' , async ( ) => { expect ( await dataTable . getSortedColumnHeaderText ( ) ) . toBe ( 'Modified' ) ; expect ( await dataTable . getSortingOrder ( ) ) . toBe ( 'desc' ) ; } ) ; it ( '[C213114] displays the files shared by everyone' , async ( ) => { expect ( await dataTable . isItemPresent ( fileAdmin ) ) . toBe ( true , `${ fileAdmin } not displayed` ) ; expect ( await dataTable . isItemPresent ( file1User ) ) . toBe ( true , `${ file1User } not displayed` ) ; } ) ; it ( `[C213117] file not displayed if it's been deleted` , async ( ) => { expect ( await dataTable . isItemPresent ( file2User ) ) . toBe ( false , `${ file2User } is displayed` ) ; } ) ; it ( '[C213118] unshared file is not displayed' , async ( ) => { expect ( await dataTable . isItemPresent ( file3User ) ) . toBe ( false , `${ file3User } is displayed` ) ; } ) ; it ( '[C213665] Location column displays the parent folder of the file' , async ( ) => { expect ( await dataTable . getItemLocationTooltip ( file4User ) ) . toEqual ( 'Personal Files' ) ; expect ( await dataTable . getItemLocation ( fileAdmin ) ) . toEqual ( siteName ) ; expect ( await dataTable . getItemLocation ( file1User ) ) . toEqual ( folderUser ) ; } ) ; it ( '[C213666] Location column redirect - file in user Home' , async ( ) => { await dataTable . clickItemLocation ( file4User ) ; await expect ( await breadcrumb . getAllItems ( ) ) . toEqual ( [ 'Personal Files' ] ) ; } ) ; it ( '[C280490] Location column redirect - file in folder' , async ( ) => { await dataTable . clickItemLocation ( file1User ) ; expect ( await breadcrumb . getAllItems ( ) ) . toEqual ( [ 'Personal Files' , folderUser ] ) ; } ) ; it ( '[C280491] Location column redirect - file in site' , async ( ) => { await dataTable . clickItemLocation ( fileAdmin ) ; expect ( await breadcrumb . getAllItems ( ) ) . toEqual ( [ 'My Libraries' , siteName ] ) ; } ) ; it ( '[C213667] Location column displays a tooltip with the entire path of the file' , async ( ) => { expect ( await dataTable . getItemLocationTooltip ( fileAdmin ) ) . toEqual ( `File Libraries/${ siteName }` ) ; expect ( await dataTable . getItemLocationTooltip ( file1User ) ) . toEqual ( `Personal Files/${ folderUser }` ) ; } ) ; } ) ;