summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/AdminSettings.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/javascript/unit/components/AdminSettings.spec.ts')
-rw-r--r--tests/javascript/unit/components/AdminSettings.spec.ts23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/javascript/unit/components/AdminSettings.spec.ts b/tests/javascript/unit/components/AdminSettings.spec.ts
index 06b1c5784..4562df933 100644
--- a/tests/javascript/unit/components/AdminSettings.spec.ts
+++ b/tests/javascript/unit/components/AdminSettings.spec.ts
@@ -4,8 +4,10 @@ import { store, localVue } from "../setupStore";
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";
+
jest.mock("@nextcloud/axios");
jest.mock("@nextcloud/initial-state");
jest.mock("@nextcloud/router");
@@ -17,40 +19,47 @@ describe("AdminSettings.vue", () => {
let wrapper: Wrapper<AdminSettings>;
beforeAll(() => {
- wrapper = shallowMount(AdminSettings, { localVue, store });
+ jest.useFakeTimers();
+ (loadState as any).mockReturnValue('');
+ wrapper = shallowMount(AdminSettings, { localVue, store});
});
it("should initialize and fetch settings from state", () => {
expect(loadState).toBeCalledTimes(7);
});
- it("should send post with updated settings", () => {
+ it("should send post with updated settings", async () => {
jest.spyOn(axios, "post").mockResolvedValue({ data: {} });
+ (wrapper.vm as any).handleResponse = jest.fn()
- wrapper.vm.$options?.methods?.update.call(wrapper.vm);
+ await wrapper.vm.$options?.methods?.update.call(wrapper.vm, 'key', 'val');
- expect(axios.post).toBeCalled;
+ expect(axios.post).toBeCalledTimes(1);
});
it("should handle bad response", () => {
+ (showError as any).mockClear();
console.error = jest.fn();
wrapper.vm.$options?.methods?.handleResponse.call(wrapper.vm, {
error: true,
errorMessage: "FAIL",
});
- expect(showError).toBeCalled;
+ expect(showError).toBeCalledTimes(1);
});
it("should handle success response", () => {
wrapper.vm.$options?.methods?.handleResponse.call(wrapper.vm, {
- success: "ok",
+ status: "ok",
});
+ (global as any).t = jest.fn();
+ jest.runAllTimers();
- expect(showSuccess).toBeCalled;
+ expect(showSuccess).toBeCalledTimes(1);
});
afterAll(() => {
jest.clearAllMocks();
+ jest.useRealTimers();
});
});