summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/AdminSettings.spec.ts
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/javascript/unit/components/AdminSettings.spec.ts
parent01d15aef47827fe0c331a9a79581125d7e85d8f1 (diff)
add unit tests for admin settings
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests/javascript/unit/components/AdminSettings.spec.ts')
-rw-r--r--tests/javascript/unit/components/AdminSettings.spec.ts56
1 files changed, 56 insertions, 0 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();
+ });
+});