Skip to content

Commit

Permalink
feat(UploadPicker): Allow to pick folders for upload
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Apr 29, 2024
1 parent 826c3b9 commit 2f43c3d
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 81 deletions.
82 changes: 81 additions & 1 deletion cypress/components/UploadPicker.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Folder, Permission, addNewFileMenuEntry, type Entry } from '@nextcloud/files'
import { generateRemoteUrl } from '@nextcloud/router'
import { UploadPicker, getUploader } from '../../lib/index.ts'
import { basename } from 'path'

describe('UploadPicker rendering', () => {
afterEach(() => {
Expand Down Expand Up @@ -106,6 +107,10 @@ describe('UploadPicker valid uploads', () => {

describe('UploadPicker invalid uploads', () => {

// Cypress shares the module state between tests, we need to reset it
// ref: https://github.com/cypress-io/cypress/issues/25441
beforeEach(() => getUploader(true))

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
Expand Down Expand Up @@ -171,7 +176,82 @@ describe('UploadPicker invalid uploads', () => {
cy.wait('@upload')
// Should not have been called more than once as the first file is invalid
cy.get('@upload.all').should('have.length', 1)
cy.get('body').should('contain', '"$" is not allowed inside a file name.')
cy.contains('[role="dialog"]', 'Invalid file name')
.should('be.visible')
})

it('Can rename invalid files', () => {
// Make sure we reset the destination
// so other tests do not interfere
const propsData = {
destination: new Folder({
id: 56,
owner: 'user',
source: generateRemoteUrl('dav/files/user'),
permissions: Permission.ALL,
root: '/files/user',
}),
forbiddenCharacters: ['$', '#', '~', '&'],
}

// Mount picker
cy.mount(UploadPicker, { propsData }).as('uploadPicker')

// Label is displayed before upload
cy.get('[data-cy-upload-picker]').contains('New').should('be.visible')

// Check and init aliases
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').as('input').should('exist')
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')

// Intercept single upload
cy.intercept('PUT', '/remote.php/dav/files/*/*', (req) => {
req.reply({
statusCode: 201,
delay: 2000,
})
}).as('upload')

// Upload 2 files
cy.get('@input').attachFile({
// Fake file of 5 MB
fileContent: new Blob([new ArrayBuffer(2 * 1024 * 1024)]),
fileName: 'invalid-image$.jpg',
mimeType: 'image/jpeg',
encoding: 'utf8',
lastModified: new Date().getTime(),
})

cy.get('@input').attachFile({
// Fake file of 5 MB
fileContent: new Blob([new ArrayBuffer(2 * 1024 * 1024)]),
fileName: 'valid-image.jpg',
mimeType: 'image/jpeg',
encoding: 'utf8',
lastModified: new Date().getTime(),
})

cy.get('[data-cy-upload-picker] .upload-picker__progress')
.as('progress')
.should('not.be.visible')

cy.contains('[role="dialog"]', 'Invalid file name')
.should('be.visible')
.contains('button', 'Rename')
.click()

cy.wait('@upload')
// Should have been called two times with an valid name now
cy.get('@upload.all').should('have.length', 2).then((array): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const requests = (array as unknown as any[]).map(({ request }) => basename(request.url))
// The valid one is included
expect(requests).to.contain('valid-image.jpg')
// The invalid is NOT included
expect(requests).to.not.contain('invalid-image$.jpg')
// The invalid was made valid
expect(requests).to.contain('invalid-image-.jpg')
})
})
})

Expand Down
25 changes: 23 additions & 2 deletions l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"

msgid "\"{filename}\" contains invalid characters, how do you want to continue?"
msgstr ""

msgid "{count} file conflict"
msgid_plural "{count} files conflict"
msgstr[0] ""
Expand Down Expand Up @@ -34,6 +37,9 @@ msgstr ""
msgid "Continue"
msgstr ""

msgid "Create new"
msgstr ""

msgid "estimating time left"
msgstr ""

Expand All @@ -43,6 +49,9 @@ msgstr ""
msgid "If you select both versions, the incoming file will have a number added to its name."
msgstr ""

msgid "Invalid file name"
msgstr ""

msgid "Last modified date unknown"
msgstr ""

Expand All @@ -58,6 +67,9 @@ msgstr ""
msgid "Preview image"
msgstr ""

msgid "Rename"
msgstr ""

msgid "Select all checkboxes"
msgstr ""

Expand All @@ -67,6 +79,9 @@ msgstr ""
msgid "Select all new files"
msgstr ""

msgid "Skip"
msgstr ""

msgid "Skip this file"
msgid_plural "Skip {count} files"
msgstr[0] ""
Expand All @@ -75,10 +90,16 @@ msgstr[1] ""
msgid "Unknown size"
msgstr ""

msgid "Upload cancelled"
msgid "Upload files"
msgstr ""

msgid "Upload files"
msgid "Upload folders"
msgstr ""

msgid "Upload from device"
msgstr ""

msgid "Upload has been cancelled"
msgstr ""

msgid "Upload progress"
Expand Down
Loading

0 comments on commit 2f43c3d

Please sign in to comment.