Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Always request current content when triggering a menu entry #1313

Merged
merged 2 commits into from
Aug 2, 2024
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
69 changes: 22 additions & 47 deletions cypress/components/UploadPicker.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ import { generateRemoteUrl } from '@nextcloud/router'
import { UploadPicker, getUploader } from '../../lib/index.ts'
import { basename } from 'path'

describe('UploadPicker rendering', () => {
afterEach(() => {
// Make sure we clear the body
let state: string | undefined
before(() => {
cy.window().then((win) => {
state = win.document.body.innerHTML
})
})

const resetDocument = () => {
if (state) {
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
win.document.body.innerHTML = state!
})
})
}
}

describe('UploadPicker rendering', () => {
afterEach(() => resetDocument())

it('Renders default UploadPicker', () => {
const propsData = {
Expand Down Expand Up @@ -66,12 +76,7 @@ describe('UploadPicker valid uploads', () => {
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')
})

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Uploads a file', () => {
// Intercept single upload
Expand Down Expand Up @@ -117,12 +122,7 @@ describe('UploadPicker invalid uploads', { testIsolation: true }, () => {
getUploader(false, true)
})

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Fails a file if forbidden character', () => {
// Make sure we reset the destination
Expand Down Expand Up @@ -287,12 +287,7 @@ describe('NewFileMenu handling', () => {
addNewFileMenuEntry(entry)
})

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Open the New File Menu', () => {
// Mount picker
Expand Down Expand Up @@ -377,12 +372,7 @@ describe('UploadPicker valid uploads', () => {
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')
})

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Uploads a file with chunking', () => {
// Init and reset chunk request spy
Expand Down Expand Up @@ -481,12 +471,7 @@ describe('Destination management', () => {
}),
}

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Upload then changes the destination', () => {
// Mount picker
Expand Down Expand Up @@ -557,12 +542,7 @@ describe('Root management', () => {
}),
}

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Upload then changes the root', () => {
// Mount picker
Expand Down Expand Up @@ -659,12 +639,7 @@ describe('UploadPicker notify testing', () => {
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')
})

afterEach(() => {
// Make sure we clear the body
cy.window().then((win) => {
win.document.body.innerHTML = '<div data-cy-root></div>'
})
})
afterEach(() => resetDocument())

it('Uploads a file without chunking', () => {
const notify = cy.spy()
Expand Down
9 changes: 8 additions & 1 deletion cypress/support/component-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

<!-- Nextcloud customizations -->
<link href="https://nextcloud.github.io/server/apps/theming/css/default.css" rel="stylesheet" />
<link href="https://nextcloud.github.io/server/core/css/server.css" rel="stylesheet" />
<link href="https://nextcloud.github.io/server/core/css/apps.css" rel="stylesheet" />
<script type="text/javascript">
// mocking the webroot for @nextcloud/router
window._oc_webroot = ''
Expand All @@ -25,6 +27,11 @@
</script>
</head>
<body>
<div data-cy-root></div>
<header id="header" style="height: var(--header-height); width: 100%; position: absolute;"></header>
<main id="content">
<div id="app-content">
<div data-cy-root></div>
</div>
</main>
</body>
</html>
27 changes: 15 additions & 12 deletions lib/components/UploadPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="entry.handler(destination, currentContent)">
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
Expand All @@ -74,7 +74,7 @@
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="entry.handler(destination, currentContent)">
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
Expand All @@ -91,7 +91,7 @@
:close-after-click="true"
:data-cy-upload-picker-menu-entry="entry.id"
class="upload-picker__menu-entry"
@click="entry.handler(destination, currentContent)">
@click="onClick(entry)">
<template v-if="entry.iconSvgInline" #icon>
<NcIconSvgWrapper :svg="entry.iconSvgInline" />
</template>
Expand Down Expand Up @@ -233,7 +233,6 @@ export default Vue.extend({
eta: null,
timeLeft: '',

currentContent: [] as Node[],
newFileMenuEntries: [] as Entry[],
uploadManager: getUploader(),
}
Expand Down Expand Up @@ -307,13 +306,6 @@ export default Vue.extend({
},
},

content: {
immediate: true,
async handler() {
this.currentContent = await this.getContent()
},
},

destination(destination) {
this.setDestination(destination)
},
Expand Down Expand Up @@ -350,6 +342,17 @@ export default Vue.extend({
},

methods: {
/**
* Handle clicking a new-menu entry
* @param entry The entry that was clicked
*/
async onClick(entry: Entry) {
entry.handler(
this.destination!,
await this.getContent().catch(() => []),
)
},

/**
* Trigger file picker
* @param uploadFolders Upload folders
Expand Down Expand Up @@ -408,7 +411,7 @@ export default Vue.extend({

async handleConflicts(nodes: Array<File|Directory>, path: string): Promise<Array<File|Directory>|false> {
try {
const content = path === '' ? this.currentContent : await this.getContent(path).catch(() => [])
const content = await this.getContent(path).catch(() => [])
const conflicts = getConflicts(nodes, content)

// First handle conflicts as this might already remove invalid files
Expand Down
Loading
Loading