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
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ module.exports = {
moduleNameMapper: {
'\\.(css|scss)$': 'jest-transform-stub',
'vendor/tflite/(.*).wasm$': '<rootDir>/src/utils/media/effects/virtual-background/vendor/tflite/$1.js',
// Axios using ESM since v1.0.0, so we need to replace it with CJS for tests
axios: '<rootDir>/node_modules/@nextcloud/axios/node_modules/axios/dist/node/axios.cjs',
},

transform: {
Expand Down
155 changes: 49 additions & 106 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@linusborg/vue-simple-portal": "^0.1.5",
"@nextcloud/auth": "^2.1.0",
"@nextcloud/axios": "^2.3.0",
"@nextcloud/axios": "^2.4.0",
"@nextcloud/browser-storage": "^0.2.0",
"@nextcloud/capabilities": "^1.1.0",
"@nextcloud/dialogs": "^4.1.0",
Expand Down Expand Up @@ -85,7 +85,6 @@
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"jest-localstorage-mock": "^2.4.26",
"jest-mock-axios": "^4.7.2",
"jest-mock-console": "^2.0.0",
"jest-transform-stub": "^2.0.0",
"regenerator-runtime": "^0.13.11",
Expand Down
4 changes: 0 additions & 4 deletions src/__mocks__/axios.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ import Conversation from './Conversation.vue'

import router from '../../../__mocks__/router.js'
import { CONVERSATION, PARTICIPANT, ATTENDEE } from '../../../constants.js'
import { leaveConversation } from '../../../services/participantsService.js'
import storeConfig from '../../../store/storeConfig.js'

jest.mock('@nextcloud/dialogs', () => ({
showSuccess: jest.fn(),
showError: jest.fn(),
}))

jest.mock('../../../services/participantsService', () => ({
leaveConversation: jest.fn(),
}))

// TODO fix after RouterLinkStub can support slots https://github.com/vuejs/vue-test-utils/issues/1803
const RouterLinkStub = true

Expand Down Expand Up @@ -357,11 +362,12 @@ describe('Conversation.vue', () => {
test('leaves conversation', async () => {
const actionHandler = jest.fn()
testStoreConfig.modules.participantsStore.actions.removeCurrentUserFromConversation = actionHandler

leaveConversation.mockResolvedValue()
const action = shallowMountAndGetAction('Leave conversation')
expect(action.exists()).toBe(true)

await action.find('button').trigger('click')
await flushPromises()

expect(actionHandler).toHaveBeenCalledWith(expect.anything(), { token: TOKEN })
})
Expand Down
10 changes: 7 additions & 3 deletions src/services/conversationsService.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import axios from '@nextcloud/axios'
import { loadState } from '@nextcloud/initial-state'
import { generateOcsUrl } from '@nextcloud/router'

import mockAxios from '../__mocks__/axios.js'
import { SHARE } from '../constants.js'
import { searchPossibleConversations } from './conversationsService.js'

jest.mock('@nextcloud/axios', () => ({
get: jest.fn(),
}))

jest.mock('@nextcloud/initial-state', () => ({
loadState: jest.fn(),
}))
Expand All @@ -27,7 +31,7 @@ describe('conversationsService', () => {

afterEach(() => {
// cleaning up the mess left behind the previous test
mockAxios.reset()
jest.clearAllMocks()
})

/**
Expand All @@ -46,7 +50,7 @@ describe('conversationsService', () => {
dummyOption: true,
}
)
expect(mockAxios.get).toHaveBeenCalledWith(
expect(axios.get).toHaveBeenCalledWith(
generateOcsUrl('core/autocomplete/get'),
{
dummyOption: true,
Expand Down
10 changes: 7 additions & 3 deletions src/services/filesSharingServices.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'

import mockAxios from '../__mocks__/axios.js'
import { shareFile } from './filesSharingServices.js'

jest.mock('@nextcloud/axios', () => ({
post: jest.fn(),
}))

describe('filesSharingServices', () => {
afterEach(() => {
// cleaning up the mess left behind the previous test
mockAxios.reset()
jest.clearAllMocks()
})

test('shareFile calls the sharing API endpoint', () => {
shareFile('path/to/file', 'XXTOKENXX', 'the-reference-id')

expect(mockAxios.post).toHaveBeenCalledWith(
expect(axios.post).toHaveBeenCalledWith(
generateOcsUrl('apps/files_sharing/api/v1/shares'),
{
shareType: 10,
Expand Down
Loading