summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/AdminSettings.spec.ts
blob: 06b1c5784ee923d46a9d170f6f80dc9f8bfec995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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();
	});
});