Skip to content

Commit 4f795e1

Browse files
committed
fix(files): properly show file not found error
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 2e50a39 commit 4f795e1

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

apps/files/src/views/FilesList.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,24 @@ export default defineComponent({
525525
},
526526
},
527527
528-
mounted() {
529-
this.fetchContent()
530-
528+
async mounted() {
531529
subscribe('files:node:deleted', this.onNodeDeleted)
532530
subscribe('files:node:updated', this.onUpdatedNode)
533531
534532
// reload on settings change
535533
subscribe('files:config:updated', this.fetchContent)
534+
535+
// Finally, fetch the current directory contents
536+
await this.fetchContent()
537+
if (this.fileId) {
538+
// If we have a fileId, let's check if the file exists
539+
const node = this.dirContents.find(node => node.fileid.toString() === this.fileId.toString())
540+
// If the file isn't in the current directory nor if
541+
// the current directory is the file, we show an error
542+
if (!node && this.currentFolder.fileid.toString() !== this.fileId.toString()) {
543+
showError(t('files', 'The file could not be found'))
544+
}
545+
}
536546
},
537547
538548
unmounted() {

cypress/e2e/files/files.cy.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,57 @@
1+
import type { User } from "@nextcloud/cypress"
2+
13
/**
24
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
35
* SPDX-License-Identifier: AGPL-3.0-or-later
46
*/
57
describe('Files', { testIsolation: true }, () => {
8+
let currentUser: User
9+
610
beforeEach(() => {
711
cy.createRandomUser().then((user) => {
8-
cy.login(user)
12+
currentUser = user
913
})
1014
})
1115

1216
it('Login with a user and open the files app', () => {
17+
cy.login(currentUser)
1318
cy.visit('/apps/files')
1419
cy.get('[data-cy-files-list] [data-cy-files-list-row-name="welcome.txt"]').should('be.visible')
1520
})
21+
22+
it('Opens a valid file shows it as active', () => {
23+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt').then((response) => {
24+
const fileId = Number.parseInt(response.headers['oc-fileid'] ?? '0')
25+
26+
cy.login(currentUser)
27+
cy.visit('/apps/files/files/' + fileId)
28+
29+
cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
30+
.should('be.visible')
31+
cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
32+
.invoke('attr', 'data-cy-files-list-row-name').should('eq', 'original.txt')
33+
cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
34+
.invoke('attr', 'class').should('contain', 'active')
35+
cy.contains('The file could not be found').should('not.exist')
36+
})
37+
})
38+
39+
it('Opens a valid folder shows its content', () => {
40+
cy.mkdir(currentUser, '/folder').then(() => {
41+
cy.login(currentUser)
42+
cy.visit('/apps/files/files?dir=/folder')
43+
44+
cy.get('[data-cy-files-content-breadcrumbs]').contains('folder').should('be.visible')
45+
cy.contains('The file could not be found').should('not.exist')
46+
})
47+
})
48+
49+
it('Opens an unknown file show an error', () => {
50+
cy.intercept('PROPFIND', /\/remote.php\/dav\//).as('propfind')
51+
cy.login(currentUser)
52+
cy.visit('/apps/files/files/123456')
53+
54+
cy.wait('@propfind')
55+
cy.contains('The file could not be found').should('be.visible')
56+
})
1657
})

0 commit comments

Comments
 (0)