diff options
Diffstat (limited to 'src/views/RoomSelector.spec.js')
-rw-r--r-- | src/views/RoomSelector.spec.js | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/src/views/RoomSelector.spec.js b/src/views/RoomSelector.spec.js index fd9960058..e1124d445 100644 --- a/src/views/RoomSelector.spec.js +++ b/src/views/RoomSelector.spec.js @@ -1,14 +1,18 @@ import { shallowMount } from '@vue/test-utils' +import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' import RoomSelector from './RoomSelector.vue' -import mockAxios from '../__mocks__/axios.js' import { CONVERSATION } from '../constants.js' +jest.mock('@nextcloud/axios', () => ({ + get: jest.fn(), +})) + describe('RoomSelector.vue', () => { let conversations @@ -64,27 +68,26 @@ describe('RoomSelector.vue', () => { }, }, } + + axios.get.mockResolvedValue({ + data: { + ocs: { + data: conversations, + }, + }, + }) }) afterEach(() => { - mockAxios.reset() jest.clearAllMocks() }) test('renders sorted conversation list fetched from server', async () => { const wrapper = shallowMount(RoomSelector) - expect(mockAxios.get).toHaveBeenCalledWith( + expect(axios.get).toHaveBeenCalledWith( generateOcsUrl('/apps/spreed/api/v4/room') ) - mockAxios.mockResponse({ - data: { - ocs: { - data: conversations, - }, - }, - }) - // need to wait for re-render, otherwise the list is not rendered yet await wrapper.vm.$nextTick() @@ -101,18 +104,10 @@ describe('RoomSelector.vue', () => { }, }) - expect(mockAxios.get).toHaveBeenCalledWith( + expect(axios.get).toHaveBeenCalledWith( generateOcsUrl('/apps/spreed/api/v4/room') ) - mockAxios.mockResponse({ - data: { - ocs: { - data: conversations, - }, - }, - }) - // need to wait for re-render, otherwise the list is not rendered yet await wrapper.vm.$nextTick() @@ -124,18 +119,10 @@ describe('RoomSelector.vue', () => { test('emits select event on select', async () => { const wrapper = shallowMount(RoomSelector) - expect(mockAxios.get).toHaveBeenCalledWith( + expect(axios.get).toHaveBeenCalledWith( generateOcsUrl('/apps/spreed/api/v4/room') ) - mockAxios.mockResponse({ - data: { - ocs: { - data: conversations, - }, - }, - }) - await wrapper.vm.$nextTick() const eventHandler = jest.fn() |