diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2022-12-03 17:48:40 -0800 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2022-12-06 14:57:20 +0100 |
commit | cec18279ac8ba66444d50164d4b95dc000db8fd0 (patch) | |
tree | 87c3178e91a9a2a1dc93491df6ed56471889d3d3 | |
parent | 05ad544a0c873ef98c0769881668895e51897699 (diff) |
fix admin tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
-rw-r--r-- | tests/javascript/unit/components/AdminSettings.spec.ts | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/tests/javascript/unit/components/AdminSettings.spec.ts b/tests/javascript/unit/components/AdminSettings.spec.ts index 91f03e62e..06e88a6cc 100644 --- a/tests/javascript/unit/components/AdminSettings.spec.ts +++ b/tests/javascript/unit/components/AdminSettings.spec.ts @@ -1,65 +1,64 @@ -import axios from '@nextcloud/axios'; -import { shallowMount, Wrapper } from '@vue/test-utils'; -import { store, localVue } from '../setupStore'; -import { showError, showSuccess } from '@nextcloud/dialogs'; -import { loadState } from '@nextcloud/initial-state'; +import axios from '@nextcloud/axios' +import { createLocalVue, shallowMount, Wrapper } from '@vue/test-utils' +import { showError, showSuccess } from '@nextcloud/dialogs' +import { loadState } from '@nextcloud/initial-state' import 'regenerator-runtime/runtime' // NOTE: Required for testing password-confirmation? -import AdminSettings from 'Components/AdminSettings.vue'; +import AdminSettings from '../../../../src/components/AdminSettings.vue' - -jest.mock('@nextcloud/axios'); -jest.mock('@nextcloud/initial-state'); -jest.mock('@nextcloud/router'); -jest.mock('@nextcloud/dialogs'); +jest.mock('@nextcloud/axios') +jest.mock('@nextcloud/initial-state') +jest.mock('@nextcloud/router') +jest.mock('@nextcloud/dialogs') describe('AdminSettings.vue', () => { - 'use strict'; + 'use strict' - let wrapper: Wrapper<AdminSettings>; + let wrapper: Wrapper<AdminSettings> beforeAll(() => { - jest.useFakeTimers(); - (loadState as any).mockReturnValue(''); - wrapper = shallowMount(AdminSettings, { localVue, store}); - }); + jest.useFakeTimers() + const localVue = createLocalVue(); + (loadState as any).mockReturnValue('') + wrapper = shallowMount(AdminSettings, { localVue }) + }) it('should initialize and fetch settings from state', () => { - expect(loadState).toBeCalledTimes(7); - }); + expect(loadState).toBeCalledTimes(7) + }) it('should send post with updated settings', async () => { jest.spyOn(axios, 'post').mockResolvedValue({ data: {} }); (wrapper.vm as any).handleResponse = jest.fn() - await wrapper.vm.$options?.methods?.update.call(wrapper.vm, 'key', 'val'); + await wrapper.vm.$options?.methods?.update.call(wrapper.vm, 'key', 'val') - expect(axios.post).toBeCalledTimes(1); - }); + expect(axios.post).toBeCalledTimes(1) + }) it('should handle bad response', () => { - (showError as any).mockClear(); - console.error = jest.fn(); + (showError as any).mockClear() + console.error = jest.fn() wrapper.vm.$options?.methods?.handleResponse.call(wrapper.vm, { error: true, errorMessage: 'FAIL', - }); + }) - expect(showError).toBeCalledTimes(1); - }); + expect(showError).toBeCalledTimes(1) + }) it('should handle success response', () => { wrapper.vm.$options?.methods?.handleResponse.call(wrapper.vm, { status: 'ok', }); - (global as any).t = jest.fn(); - jest.runAllTimers(); + (global as any).t = jest.fn() + jest.runAllTimers() - expect(showSuccess).toBeCalledTimes(1); - }); + expect(showSuccess).toBeCalledTimes(1) + }) afterAll(() => { - jest.clearAllMocks(); - jest.useRealTimers(); - }); -}); + jest.clearAllMocks() + jest.useRealTimers() + }) +}) |