-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutoModeButton.test.ts
More file actions
58 lines (52 loc) · 1.93 KB
/
AutoModeButton.test.ts
File metadata and controls
58 lines (52 loc) · 1.93 KB
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
57
58
import { describe, it, expect, vi } from "vitest";
import { ref } from "vue";
import { mount } from "@vue/test-utils";
import fc from "fast-check";
import { fcError, fcUndefinedOr } from "@/graphql/tests/arbitraries";
import { onReady } from "@/utils/on-ready";
import AutoModeButton from "../AutoModeButton.vue";
import { useAutoMode } from "../use-auto-mode";
vi.mock("../use-auto-mode", () => ({ useAutoMode: vi.fn() }));
const fcReturns = () =>
fc
.record({
autoMode: fcUndefinedOr(fc.boolean()).map((v) => ref(v)),
pulling: fc.constant(ref(false)),
loading: fc.boolean().map((v) => ref(v)),
error: fcUndefinedOr(fcError).map((v) => ref(v)),
})
.map((ret) => onReady(ret, Promise.resolve()));
describe("AutoModeButton", () => {
it("Property test", () => {
fc.assert(
fc.property(fcReturns(), (ret) => {
vi.mocked(useAutoMode).mockReturnValue(ret);
const wrapper = mount(AutoModeButton, {
global: {
stubs: {
ButtonOff: true,
ButtonAutoMode: true,
ButtonError: true,
},
},
});
if (ret.loading.value) {
const button = wrapper.findComponent({ name: "VBtn" });
expect(button.exists()).toBe(true);
expect(button.props()["loading"]).toBe(true);
} else if (ret.error.value) {
const button = wrapper.findComponent({ name: "ButtonError" });
expect(button.exists()).toBe(true);
expect(button.props("error")).toEqual(ret.error.value);
} else if (ret.autoMode.value === true) {
expect(wrapper.findComponent({ name: "ButtonAutoMode" }).exists()).toBe(true);
} else if (ret.autoMode.value === false) {
expect(wrapper.findComponent({ name: "ButtonOff" }).exists()).toBe(true);
} else {
expect(wrapper.html()).toContain("Unknown");
}
wrapper.unmount();
}),
);
});
});