Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 53 additions & 30 deletions lib/components/UploadPicker.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('UploadPicker rendering', () => {
cy.mount(UploadPicker)
cy.get('form').should('have.class', 'upload-picker')
cy.get('form input[type="file"]').should('exist')
cy.screenshot()
})
})

Expand All @@ -35,7 +34,7 @@ describe('NewFileMenu handling', () => {
displayName: 'Create empty file',
templateName: 'New file',
iconClass: 'icon-file',
if: fileInfo => fileInfo.permissions.includes('CK'),
if: (fileInfo) => fileInfo.permissions.includes('CK'),
handler() {},
}

Expand All @@ -51,19 +50,18 @@ describe('NewFileMenu handling', () => {
// Check and init aliases
cy.get('form input[type="file"]').as('input').should('exist')
cy.get('form .upload-picker__progress').as('progress').should('exist')
cy.get('form .action-item__menutoggle').as('menuButton').should('exist')
cy.get('form .action-item__menutoggle')
.as('menuButton')
.should('exist')

cy.get('@menuButton').click()
cy.get('[data-upload-picker-add]').should('have.length', 1)
cy.get('.upload-picker__menu-entry').should('have.length', 1)

cy.screenshot()

cy.get('.upload-picker__menu-entry')
.click()
.then(() => {
expect(entry.handler).to.be.called
cy.screenshot()
})
})

Expand All @@ -74,25 +72,29 @@ describe('NewFileMenu handling', () => {
// Check and init aliases
cy.get('form input[type="file"]').as('input').should('exist')
cy.get('form .upload-picker__progress').as('progress').should('exist')
cy.get('form .action-item__menutoggle').as('menuButton').should('exist')
cy.get('form .action-item__menutoggle')
.as('menuButton')
.should('exist')

cy.get('@menuButton').click()
cy.get('[data-upload-picker-add]').should('have.length', 1)
cy.get('.upload-picker__menu-entry').should('have.length', 1)
cy.screenshot()

// Close menu
cy.get('body').click()
cy.get('[data-upload-picker-add]').should('not.exist')
cy.get('.upload-picker__menu-entry').should('not.exist')
cy.get('[data-upload-picker-add]').should('not.be.visible')
cy.get('.upload-picker__menu-entry').should('not.be.visible')

cy.get('@component').then(component => {
component.setContext(Object.assign({}, propsData.context, { permissions: 'GR' }))
cy.get('@component').then((component) => {
component.setContext(
Object.assign({}, propsData.context, { permissions: 'GR' })
)
})
cy.get('form .action-item__menutoggle').as('menuButton').should('not.exist')
cy.get('form .action-item__menutoggle')
.as('menuButton')
.should('not.exist')
cy.get('[data-upload-picker-add]').should('have.length', 1)
cy.get('.upload-picker__menu-entry').should('not.exist')
cy.screenshot()
})
})

Expand All @@ -119,15 +121,15 @@ describe('UploadPicker valid uploads', () => {
cy.intercept({
method: 'PUT',
url: '/remote.php/dav/uploads/*/web-file-upload*/*',
}, req => {
}, (req) => {
chunksRequestsSpy()
req.reply({
statusCode: 201,
})
}).as('chunks')

// Intercept final assembly request
cy.intercept('MOVE', '/remote.php/dav/uploads/*/web-file-upload*/.file', req => {
cy.intercept('MOVE', '/remote.php/dav/uploads/*/web-file-upload*/.file', (req) => {
req.reply({
statusCode: 204,
// Fake assembling chunks
Expand All @@ -146,15 +148,22 @@ describe('UploadPicker valid uploads', () => {
})

cy.wait('@init').then(() => {
cy.get('form .upload-picker__progress').as('progress').should('be.visible')
cy.get('form .upload-picker__progress')
.as('progress')
.should('be.visible')
})
cy.wait('@chunks').then(() => {
cy.get('form .upload-picker__progress').as('progress').should('be.visible')
cy.get('@progress').children('progress').should('not.have.value', '0')
cy.screenshot()
cy.get('form .upload-picker__progress')
.as('progress')
.should('be.visible')
cy.get('@progress')
.children('progress')
.should('not.have.value', '0')
})
cy.wait('@assembly', { timeout: 60000 }).then(() => {
cy.get('form .upload-picker__progress').as('progress').should('not.be.visible')
cy.get('form .upload-picker__progress')
.as('progress')
.should('not.be.visible')
expect(chunksRequestsSpy).to.have.always.been.callCount(26)
})
})
Expand All @@ -174,9 +183,13 @@ describe('UploadPicker valid uploads', () => {
lastModified: new Date().getTime(),
})

cy.get('form .upload-picker__progress').as('progress').should('not.be.visible')
cy.get('form .upload-picker__progress')
.as('progress')
.should('not.be.visible')
cy.wait('@upload').then(() => {
cy.get('@progress').children('progress').should('not.have.value', '0')
cy.get('@progress')
.children('progress')
.should('not.have.value', '0')
})
})
})
Expand Down Expand Up @@ -209,10 +222,12 @@ describe('Destination management', () => {
})

cy.wait('@upload').then((upload) => {
expect(upload.request.url).to.have.string('/remote.php/dav/files/user/image.jpg')
expect(upload.request.url).to.have.string(
'/remote.php/dav/files/user/image.jpg'
)
})

cy.get('@component').then(component => {
cy.get('@component').then((component) => {
component.setDestination('/Photos')
// Wait for prop propagation
expect(component.uploadManager.destination).to.equal('/Photos')
Expand All @@ -228,7 +243,9 @@ describe('Destination management', () => {
})

cy.wait('@upload').then((upload) => {
expect(upload.request.url).to.have.string('/remote.php/dav/files/user/Photos/image.jpg')
expect(upload.request.url).to.have.string(
'/remote.php/dav/files/user/Photos/image.jpg'
)
})
})
})
Expand Down Expand Up @@ -262,14 +279,18 @@ describe('Root management', () => {
})

cy.wait('@upload').then((upload) => {
expect(upload.request.url).to.have.string('/remote.php/dav/files/user/image.jpg')
expect(upload.request.url).to.have.string(
'/remote.php/dav/files/user/image.jpg'
)
})

cy.get('@component').then(component => {
cy.get('@component').then((component) => {
component.setRoot('dav/photos/admin/albums')
component.setDestination('/2022 Summer Vacations')
// Wait for prop propagation
expect(component.uploadManager.root).to.match(/dav\/photos\/admin\/albums$/i)
expect(component.uploadManager.root).to.match(
/dav\/photos\/admin\/albums$/i
)
})

// Intercept single upload
Expand All @@ -287,7 +308,9 @@ describe('Root management', () => {
})

cy.wait('@upload').then((upload) => {
expect(upload.request.url).to.have.string('/remote.php/dav/photos/admin/albums/2022%20Summer%20Vacations/image.jpg')
expect(upload.request.url).to.have.string(
'/remote.php/dav/photos/admin/albums/2022%20Summer%20Vacations/image.jpg'
)
})
})
})
30 changes: 15 additions & 15 deletions lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
</NcButton>

<!-- New file menu -->
<Actions v-else :menu-title="addLabel">
<NcActions v-else :menu-title="addLabel">
<template #icon>
<Plus title="" :size="20" decorative />
</template>
<ActionButton data-upload-picker-add @click="onClick">
<NcActionButton data-upload-picker-add @click="onClick">
<template #icon>
<Upload title="" :size="20" decorative />
</template>
{{ uploadLabel }}
</ActionButton>
</NcActionButton>

<!-- Custom new file entries -->
<ActionButton v-for="entry in newFileMenuEntries"
<NcActionButton v-for="entry in newFileMenuEntries"
:key="entry.id"
:icon="entry.iconClass"
class="upload-picker__menu-entry"
Expand All @@ -36,12 +36,12 @@
<ActionIcon :svg="entry.iconSvgInline" />
</template>
{{ entry.displayName }}
</ActionButton>
</Actions>
</NcActionButton>
</NcActions>

<!-- Progressbar and status, hidden by css -->
<div class="upload-picker__progress">
<ProgressBar :error="hasFailure"
<NcProgressBar :error="hasFailure"
:value="progress"
size="medium" />
<p>{{ timeLeft }}</p>
Expand Down Expand Up @@ -76,10 +76,10 @@ import { getNewFileMenuEntries } from '@nextcloud/files'
import { getUploader } from '../index.ts'
import makeEta from 'simple-eta'

import ActionButton from '@nextcloud/vue/dist/Components/ActionButton.js'
import Actions from '@nextcloud/vue/dist/Components/Actions.js'
import NcButton from '@nextcloud/vue/dist/Components/Button.js'
import ProgressBar from '@nextcloud/vue/dist/Components/ProgressBar.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcProgressBar from '@nextcloud/vue/dist/Components/NcProgressBar.js'

import Cancel from 'vue-material-design-icons/Cancel.vue'
import Plus from 'vue-material-design-icons/Plus.vue'
Expand All @@ -97,13 +97,13 @@ const uploadManager = getUploader()
export default {
name: 'UploadPicker',
components: {
ActionButton,
NcActionButton,
ActionIcon,
Actions,
NcActions,
NcButton,
Cancel,
Plus,
ProgressBar,
NcProgressBar,
Upload,
},

Expand Down Expand Up @@ -300,7 +300,7 @@ export default {
},

setContext(context) {
logger.debug('Context changed to', context);
logger.debug('Context changed to', context)
this.newFileMenuEntries = getNewFileMenuEntries(context)
},
},
Expand Down
Loading