Skip to content

Commit

Permalink
test: Add Cypress test for renaming loading state
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 26, 2024
1 parent 3c0993c commit cac6e9e
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion cypress/e2e/files/files-renaming.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

import type { User } from '@nextcloud/cypress'
import { getRowForFile, triggerActionForFile } from './FilesUtils'
// Remove with Node 22
import 'core-js/actual/promise/with-resolvers.js'

const haveValidity = (validity: string | RegExp) => {
if (typeof validity === 'string') {
Expand Down Expand Up @@ -74,4 +75,48 @@ describe('files: Rename nodes', { testIsolation: true }, () => {
// See validity
.should(haveValidity(/reserved name/i))
})

it('shows accessible loading information', () => {
const { resolve, promise } = Promise.withResolvers()

getRowForFile('file.txt').should('be.visible')

// intercept the rename (MOVE)
// the callback will wait until the promise resolve (so we have time to check the loading state)
cy.intercept(
'MOVE',
/\/remote.php\/dav\/files\//,
async () => { await promise },
).as('moveFile')

// Start the renaming
triggerActionForFile('file.txt', 'rename')
getRowForFile('file.txt')
.findByRole('textbox', { name: 'Filename' })
.should('be.visible')
.type('{selectAll}new-name.txt{enter}')

// Loading state is visible
getRowForFile('new-name.txt')
.findByRole('img', { name: 'File is loading' })
.should('be.visible')
// checkbox is not visible
getRowForFile('new-name.txt')
.findByRole('checkbox', { name: /^Toggle selection/ })
.should('not.exist')

// Resolve the promise so we can proceed
resolve(null)
// Ensure the request is done (file renamed)
cy.wait('@moveFile')

// checkbox visible again
getRowForFile('new-name.txt')
.findByRole('checkbox', { name: /^Toggle selection/ })
.should('exist')
// see the loading state is gone
getRowForFile('new-name.txt')
.findByRole('img', { name: 'File is loading' })
.should('not.exist')
})
})

0 comments on commit cac6e9e

Please sign in to comment.