summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2022-11-21 12:40:52 -0800
committerBenjamin Brahmer <info@b-brahmer.de>2022-12-01 13:17:21 +0100
commita12e334ce2cf35f2aecc89b157f8d091b65aa1ab (patch)
treebd1f53a7f2fefab3455b4934feb159a3f68cbc28 /tests
parent01d15aef47827fe0c331a9a79581125d7e85d8f1 (diff)
add unit tests for admin settings
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/javascript/unit/components/AdminSettings.spec.ts56
-rw-r--r--tests/javascript/unit/components/Explore.spec.ts33
2 files changed, 72 insertions, 17 deletions
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
+});