diff options
-rw-r--r-- | src/components/AdminSettings.vue | 2 | ||||
-rw-r--r-- | tests/javascript/unit/components/AdminSettings.spec.ts | 56 | ||||
-rw-r--r-- | tests/javascript/unit/components/Explore.spec.ts | 33 |
3 files changed, 73 insertions, 18 deletions
diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 450034140..b2b89d44b 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -104,7 +104,7 @@ import { loadState } from '@nextcloud/initial-state' import { showError, showSuccess } from '@nextcloud/dialogs' import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' -import confirmPassword from '@nextcloud/password-confirmation' +import { confirmPassword } from '@nextcloud/password-confirmation' // TODO: throws 'invariant' error with jest? /** * diff --git a/tests/javascript/unit/components/AdminSettings.spec.ts b/tests/javascript/unit/components/AdminSettings.spec.ts new file mode 100644 index 000000000..06b1c5784 --- /dev/null +++ b/tests/javascript/unit/components/AdminSettings.spec.ts @@ -0,0 +1,56 @@ +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 AdminSettings from "Components/AdminSettings.vue"; + +jest.mock("@nextcloud/axios"); +jest.mock("@nextcloud/initial-state"); +jest.mock("@nextcloud/router"); +jest.mock("@nextcloud/dialogs"); + +describe("AdminSettings.vue", () => { + "use strict"; + + let wrapper: Wrapper<AdminSettings>; + + beforeAll(() => { + wrapper = shallowMount(AdminSettings, { localVue, store }); + }); + + it("should initialize and fetch settings from state", () => { + expect(loadState).toBeCalledTimes(7); + }); + + it("should send post with updated settings", () => { + jest.spyOn(axios, "post").mockResolvedValue({ data: {} }); + + wrapper.vm.$options?.methods?.update.call(wrapper.vm); + + expect(axios.post).toBeCalled; + }); + + it("should handle bad response", () => { + console.error = jest.fn(); + wrapper.vm.$options?.methods?.handleResponse.call(wrapper.vm, { + error: true, + errorMessage: "FAIL", + }); + + expect(showError).toBeCalled; + }); + + it("should handle success response", () => { + wrapper.vm.$options?.methods?.handleResponse.call(wrapper.vm, { + success: "ok", + }); + + expect(showSuccess).toBeCalled; + }); + + afterAll(() => { + jest.clearAllMocks(); + }); +}); diff --git a/tests/javascript/unit/components/Explore.spec.ts b/tests/javascript/unit/components/Explore.spec.ts index bd50fe592..846211913 100644 --- a/tests/javascript/unit/components/Explore.spec.ts +++ b/tests/javascript/unit/components/Explore.spec.ts @@ -1,24 +1,23 @@ -import axios from '@nextcloud/axios' -import { shallowMount } from '@vue/test-utils' -import { store, localVue } from '../setupStore' +import axios from "@nextcloud/axios"; +import { shallowMount } from "@vue/test-utils"; +import { store, localVue } from "../setupStore"; -import * as router from '@nextcloud/router' +import * as router from "@nextcloud/router"; -import Explore from 'Components/Explore.vue' +import Explore from "Components/Explore.vue"; -jest.mock('@nextcloud/axios') +jest.mock("@nextcloud/axios"); -describe('Explore.vue', () => { - 'use strict' - - +describe("Explore.vue", () => { + "use strict"; - it('should initialize without showing AddFeed Component', () => { - (axios as any).get.mockResolvedValue({ data: { } }) - (router as any).generateUrl = jest.fn().mockReturnValue(''); - - const wrapper = shallowMount(Explore, { localVue, store }) + it("should initialize without showing AddFeed Component", () => { + (axios as any).get.mockResolvedValue({ data: {} }); + (router as any).generateUrl = jest.fn().mockReturnValue(""); - expect(wrapper.vm.$data.showAddFeed).toBeFalsy + jest.fn().mockReturnValue + const wrapper = shallowMount(Explore, { localVue, store }); + + expect(wrapper.vm.$data.showAddFeed).toBeFalsy; }); -});
\ No newline at end of file +}); |