Skip to content

Commit

Permalink
test: Migrated all Jest tests to vitest
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Aug 24, 2024
1 parent 0e0dcf9 commit 0dce19a
Show file tree
Hide file tree
Showing 33 changed files with 776 additions and 336 deletions.
17 changes: 9 additions & 8 deletions apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { action } from './inlineUnreadCommentsAction'
import { expect } from '@jest/globals'
import { File, Permission, View, FileAction } from '@nextcloud/files'
import { describe, expect, test, vi } from 'vitest'

import { action } from './inlineUnreadCommentsAction'
import logger from '../logger'

const view = {
Expand All @@ -29,7 +30,7 @@ describe('Inline unread comments action display name tests', () => {
expect(action.id).toBe('comments-unread')
expect(action.displayName([file], view)).toBe('')
expect(action.title!([file], view)).toBe('1 new comment')
expect(action.iconSvgInline([], view)).toBe('<svg>SvgMock</svg>')
expect(action.iconSvgInline([], view)).toMatch(/<svg.+<\/svg>/)
expect(action.enabled!([file], view)).toBe(true)
expect(action.inline!(file, view)).toBe(true)
expect(action.default).toBeUndefined()
Expand Down Expand Up @@ -115,8 +116,8 @@ describe('Inline unread comments action enabled tests', () => {

describe('Inline unread comments action execute tests', () => {
test('Action opens sidebar', async () => {
const openMock = jest.fn()
const setActiveTabMock = jest.fn()
const openMock = vi.fn()
const setActiveTabMock = vi.fn()
window.OCA = {
Files: {
Sidebar: {
Expand Down Expand Up @@ -145,8 +146,8 @@ describe('Inline unread comments action execute tests', () => {
})

test('Action handles sidebar open failure', async () => {
const openMock = jest.fn(() => { throw new Error('Mock error') })
const setActiveTabMock = jest.fn()
const openMock = vi.fn(() => { throw new Error('Mock error') })
const setActiveTabMock = vi.fn()
window.OCA = {
Files: {
Sidebar: {
Expand All @@ -155,7 +156,7 @@ describe('Inline unread comments action execute tests', () => {
},
},
}
jest.spyOn(logger, 'error').mockImplementation(() => jest.fn())
vi.spyOn(logger, 'error').mockImplementation(() => vi.fn())

const file = new File({
id: 1,
Expand Down
27 changes: 10 additions & 17 deletions apps/dav/src/views/CalDavSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,33 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { render } from '@testing-library/vue'
import { beforeEach, describe, expect, test, vi } from 'vitest'

import CalDavSettings from './CalDavSettings.vue'
// eslint-disable-next-line no-unused-vars
import { generateUrl } from '@nextcloud/router'

jest.mock('@nextcloud/axios')
jest.mock('@nextcloud/router', () => {
vi.mock('@nextcloud/axios')
vi.mock('@nextcloud/router', () => {
return {
generateUrl(url) {
return url
},
}
})
jest.mock('@nextcloud/initial-state', () => {
vi.mock('@nextcloud/initial-state', () => {
return {
loadState: jest.fn(() => 'https://docs.nextcloud.com/server/23/go.php?to=user-sync-calendars'),
loadState: vi.fn(() => 'https://docs.nextcloud.com/server/23/go.php?to=user-sync-calendars'),
}
})

describe('CalDavSettings', () => {
const originalOC = global.OC
const originalOCP = global.OCP

beforeEach(() => {
global.OC = { requestToken: 'secret' }
global.OCP = {
window.OC = { requestToken: 'secret' }
window.OCP = {
AppConfig: {
setValue: jest.fn(),
setValue: vi.fn(),
},
}
})
afterAll(() => {
global.OC = originalOC
global.OCP = originalOCP
})

test('interactions', async () => {
const TLUtils = render(
Expand All @@ -53,7 +46,7 @@ describe('CalDavSettings', () => {
},
},
Vue => {
Vue.prototype.$t = jest.fn((app, text) => text)
Vue.prototype.$t = vi.fn((app, text) => text)
},
)
expect(TLUtils.container).toMatchSnapshot()
Expand Down
Loading

0 comments on commit 0dce19a

Please sign in to comment.