test(files): Adapte to new @nextcloud/files version

Signed-off-by: Louis Chmn <louis@chmn.me>
pull/55900/head
Louis Chmn 2025-10-22 14:49:41 +07:00
parent 0f244579ca
commit 963f280710
3 changed files with 16 additions and 13 deletions

@ -5,8 +5,7 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import { useFileListHeaders } from './useFileListHeaders.ts'
import { Header } from '@nextcloud/files'
import * as ncFiles from '@nextcloud/files'
import { Header, getFileListHeaders } from '@nextcloud/files'
jest.mock('@nextcloud/files', () => ({
...jest.requireActual<typeof import('@nextcloud/files')>('@nextcloud/files'),
@ -21,22 +20,22 @@ describe('useFileListHeaders', () => {
it('gets the headers', () => {
const header = new Header({ id: '1', order: 5, render: jest.fn(), updated: jest.fn() })
// @ts-expect-error its mocked
ncFiles.getFileListHeaders.mockImplementationOnce(() => [header])
getFileListHeaders.mockImplementationOnce(() => [header])
const headers = useFileListHeaders()
expect(headers.value).toEqual([header])
expect(ncFiles.getFileListHeaders).toBeCalled()
expect(getFileListHeaders).toBeCalled()
})
it('headers are sorted', () => {
const header = new Header({ id: '1', order: 10, render: jest.fn(), updated: jest.fn() })
const header2 = new Header({ id: '2', order: 5, render: jest.fn(), updated: jest.fn() })
// @ts-expect-error its mocked
ncFiles.getFileListHeaders.mockImplementationOnce(() => [header, header2])
getFileListHeaders.mockImplementationOnce(() => [header, header2])
const headers = useFileListHeaders()
// lower order first
expect(headers.value.map(({ id }) => id)).toStrictEqual(['2', '1'])
expect(ncFiles.getFileListHeaders).toBeCalled()
expect(getFileListHeaders).toBeCalled()
})
})

@ -3,11 +3,16 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import nextcloudFiles, { Navigation, View } from '@nextcloud/files'
import { Navigation, View, getNavigation } from '@nextcloud/files'
import { mount } from '@vue/test-utils'
import { defineComponent } from 'vue'
import { useNavigation } from './useNavigation'
jest.mock('@nextcloud/files', () => ({
...jest.requireActual<typeof import('@nextcloud/files')>('@nextcloud/files'),
getNavigation: jest.fn(),
}))
// Just a wrapper so we can test the composable
const TestComponent = defineComponent({
template: '<div></div>',
@ -21,13 +26,13 @@ const TestComponent = defineComponent({
})
describe('Composables: useNavigation', () => {
const spy = jest.spyOn(nextcloudFiles, 'getNavigation')
let navigation: Navigation
describe('currentView', () => {
beforeEach(() => {
navigation = new Navigation()
spy.mockImplementation(() => navigation)
// @ts-expect-error its mocked
getNavigation.mockImplementationOnce(() => navigation)
})
it('should return null without active navigation', () => {
@ -61,7 +66,8 @@ describe('Composables: useNavigation', () => {
describe('views', () => {
beforeEach(() => {
navigation = new Navigation()
spy.mockImplementation(() => navigation)
// @ts-expect-error its mocked
getNavigation.mockImplementationOnce(() => navigation)
})
it('should return empty array without registered views', () => {

@ -9,7 +9,7 @@ import type { Folder as CFolder, Navigation } from '@nextcloud/files'
import { expect } from '@jest/globals'
import * as eventBus from '@nextcloud/event-bus'
import * as filesUtils from '@nextcloud/files'
import { Folder, getNavigation } from '@nextcloud/files'
import * as filesDavUtils from '@nextcloud/files/dav'
import { basename } from 'path'
import { CancelablePromise } from 'cancelable-promise'
@ -18,8 +18,6 @@ import { action } from '../actions/favoriteAction'
import { registerFavoritesView } from './favorites'
import * as favoritesService from '../services/Favorites'
const { Folder, getNavigation } = filesUtils
jest.mock('@nextcloud/axios', () => ({
post: jest.fn(),
}))