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
8 changes: 7 additions & 1 deletion packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,13 @@ watch(
loading.value = true
loadingError.value = undefined

await loadResourceTask.perform()
try {
await loadResourceTask.perform()
} catch {
// errors end up in loadingError, so this only rejects when a newer run (e.g. after
// adding the drive alias to the route) or the unmount cancelled the task
return
}
if (unref(loadingError)) {
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mock } from 'vitest-mock-extended'
import { defineComponent, h, nextTick, ref, toValue, unref } from 'vue'
import { defineComponent, h, nextTick, reactive, ref, toValue, unref } from 'vue'
import { flushPromises } from '@vue/test-utils'
import type { Resource, ShareSpaceResource } from '@opencloud-eu/web-client'
import { HttpError } from '@opencloud-eu/web-client'
Expand Down Expand Up @@ -122,7 +122,9 @@ function setup({
params: { driveAliasAndItem: 'personal/alan/a.md' }
}),
isGuestContext = false,
fileContentOptions = undefined as FileContentOptions
fileContentOptions = undefined as FileContentOptions,
// Receives the errors Vue would otherwise report as unhandled.
errorHandler = undefined as (err: unknown) => void
} = {}) {
const wasWrittenByRoom = vi.fn().mockResolvedValue(writtenByRoom)
const beginSave = vi.fn()
Expand Down Expand Up @@ -261,7 +263,8 @@ function setup({
plugins: [...piniaPlugins, router],
mocks,
provide: mocks,
stubs: { 'file-side-bar': true }
stubs: { 'file-side-bar': true },
config: { errorHandler }
}
})
const [, onResourcesDeleted] = subscribeSpy.mock.calls.find(
Expand Down Expand Up @@ -417,6 +420,49 @@ describe('AppWrapper — missing drive alias', () => {
)
}
)

it('loads the file after adding the drive alias restarted the loading', async () => {
getResourceContextSpy.mockResolvedValue({ space: shareSpace, path: '/sub/a.md' })
const route = reactive({
path: '/test-app',
query: { fileId: 'file-id' },
params: { driveAliasAndItem: '' }
})
const errorHandler = vi.fn()
const s = setup({
yjsEnabled: false,
currentRoute: route as unknown as RouteLocation,
errorHandler
})
// Like the router: the new route changes the file context, which restarts
// the loading while the first run is still waiting for the route change.
s.routerPush.mockImplementationOnce(async (to: any) => {
route.params.driveAliasAndItem = to.params.driveAliasAndItem
s.currentFileContext.value = mock<FileContext>({ space: mock<any>(), path: '/sub/a.md' })
await flushPromises()
return undefined
})
await flushPromises()
await s.resolveResource(FILE_A)
await s.resolveContent('content of a')

expect(s.routerPush).toHaveBeenCalledTimes(1)
expect(s.currentContent()).toBe('content of a')
expect(errorHandler).not.toHaveBeenCalled()
})
})

describe('AppWrapper — closing the app while the file is loading', () => {
it('stops loading without an error', async () => {
const errorHandler = vi.fn()
const s = setup({ yjsEnabled: false, errorHandler })
await nextTick()

s.wrapper.unmount()
await flushPromises()

expect(errorHandler).not.toHaveBeenCalled()
})
})

describe('AppWrapper — top bar extension', () => {
Expand Down
Loading