Skip to content

Commit e0e031e

Browse files
committed
fix(files): properly show file not found error
Signed-off-by: skjnldsv <[email protected]>
1 parent 7841905 commit e0e031e

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

apps/files/src/views/FilesList.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,26 @@ export default defineComponent({
486486
},
487487
},
488488
489-
mounted() {
490-
this.fetchContent()
491-
489+
async mounted() {
492490
subscribe('files:node:deleted', this.onNodeDeleted)
493491
subscribe('files:node:updated', this.onUpdatedNode)
494492
subscribe('nextcloud:unified-search.search', this.onSearch)
495493
subscribe('nextcloud:unified-search.reset', this.resetSearch)
496494
497-
// reload on settings change
495+
// Reload on settings change
498496
this.unsubscribeStoreCallback = this.userConfigStore.$subscribe(() => this.fetchContent(), { deep: true })
497+
498+
// Finally, fetch the current directory contents
499+
await this.fetchContent()
500+
if (this.fileId) {
501+
// If we have a fileId, let's check if the file exists
502+
const node = this.dirContents.find(node => node.fileid.toString() === this.fileId.toString())
503+
// If the file isn't in the current directory nor if
504+
// the current directory is the file, we show an error
505+
if (!node && this.currentFolder.fileid.toString() !== this.fileId.toString()) {
506+
showError(t('files', 'The file could not be found'))
507+
}
508+
}
499509
},
500510
501511
unmounted() {

cypress/e2e/files/files.cy.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { User } from "@nextcloud/cypress"
2+
13
/**
24
* @copyright Copyright (c) 2022 John Molakvoæ <[email protected]>
35
*
@@ -20,14 +22,53 @@
2022
*
2123
*/
2224
describe('Files', { testIsolation: true }, () => {
25+
let currentUser: User
26+
2327
beforeEach(() => {
2428
cy.createRandomUser().then((user) => {
25-
cy.login(user)
29+
currentUser = user
2630
})
2731
})
2832

2933
it('Login with a user and open the files app', () => {
34+
cy.login(currentUser)
3035
cy.visit('/apps/files')
3136
cy.get('[data-cy-files-list] [data-cy-files-list-row-name="welcome.txt"]').should('be.visible')
3237
})
38+
39+
it('Opens a valid file shows it as active', () => {
40+
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original.txt').then((response) => {
41+
const fileId = Number.parseInt(response.headers['oc-fileid'] ?? '0')
42+
43+
cy.login(currentUser)
44+
cy.visit('/apps/files/files/' + fileId)
45+
46+
cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
47+
.should('be.visible')
48+
cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
49+
.invoke('attr', 'data-cy-files-list-row-name').should('eq', 'original.txt')
50+
cy.get(`[data-cy-files-list-row-fileid=${fileId}]`)
51+
.invoke('attr', 'class').should('contain', 'active')
52+
cy.contains('The file could not be found').should('not.exist')
53+
})
54+
})
55+
56+
it('Opens a valid folder shows its content', () => {
57+
cy.mkdir(currentUser, '/folder').then(() => {
58+
cy.login(currentUser)
59+
cy.visit('/apps/files/files?dir=/folder')
60+
61+
cy.get('[data-cy-files-content-breadcrumbs]').contains('folder').should('be.visible')
62+
cy.contains('The file could not be found').should('not.exist')
63+
})
64+
})
65+
66+
it('Opens an unknown file show an error', () => {
67+
cy.intercept('PROPFIND', /\/remote.php\/dav\//).as('propfind')
68+
cy.login(currentUser)
69+
cy.visit('/apps/files/files/123456')
70+
71+
cy.wait('@propfind')
72+
cy.contains('The file could not be found').should('be.visible')
73+
})
3374
})

0 commit comments

Comments
 (0)