drag-n-drop.cy.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { getRowForFile } from './FilesUtils.ts'
  2. describe('files: Drag and Drop', { testIsolation: true }, () => {
  3. beforeEach(() => {
  4. cy.createRandomUser().then((user) => {
  5. cy.login(user)
  6. })
  7. cy.visit('/apps/files')
  8. })
  9. it('can drop a file', () => {
  10. const dataTransfer = new DataTransfer()
  11. dataTransfer.items.add(new File([], 'single-file.txt'))
  12. cy.intercept('PUT', /\/remote.php\/dav\/files\//).as('uploadFile')
  13. cy.get('[data-cy-files-drag-drop-area]').should('not.be.visible')
  14. // Trigger the drop notice
  15. cy.get('main.app-content').trigger('dragover', { dataTransfer })
  16. cy.get('[data-cy-files-drag-drop-area]').should('be.visible')
  17. // Upload drop a file
  18. cy.get('[data-cy-files-drag-drop-area]').selectFile({
  19. fileName: 'single-file.txt',
  20. contents: ['hello '.repeat(1024)],
  21. }, { action: 'drag-drop' })
  22. cy.wait('@uploadFile')
  23. getRowForFile('single-file.txt').should('be.visible')
  24. getRowForFile('single-file.txt').find('[data-cy-files-list-row-size]').should('contain', '6 KB')
  25. })
  26. it('can drop multiple files', () => {
  27. const dataTransfer = new DataTransfer()
  28. dataTransfer.items.add(new File([], 'first.txt'))
  29. dataTransfer.items.add(new File([], 'second.txt'))
  30. cy.intercept('PUT', /\/remote.php\/dav\/files\//).as('uploadFile')
  31. // Trigger the drop notice
  32. cy.get('main.app-content').trigger('dragover', { dataTransfer })
  33. cy.get('[data-cy-files-drag-drop-area]').should('be.visible')
  34. // Upload drop a file
  35. cy.get('[data-cy-files-drag-drop-area]').selectFile([
  36. {
  37. fileName: 'first.txt',
  38. contents: ['Hello'],
  39. },
  40. {
  41. fileName: 'second.txt',
  42. contents: ['World'],
  43. },
  44. ], { action: 'drag-drop' })
  45. cy.wait('@uploadFile')
  46. getRowForFile('first.txt').should('be.visible')
  47. getRowForFile('second.txt').should('be.visible')
  48. })
  49. })