|
| 1 | +import { describe, it, expect, vi } from "vitest"; |
| 2 | +import { ref } from "vue"; |
| 3 | +import { mount } from "@vue/test-utils"; |
| 4 | +import fc from "fast-check"; |
| 5 | + |
| 6 | +import { fcError, fcUndefinedOr } from "@/graphql/tests/arbitraries"; |
| 7 | +import { onReady } from "@/utils/on-ready"; |
| 8 | + |
| 9 | +import AutoModeButton from "../AutoModeButton.vue"; |
| 10 | +import { useAutoMode } from "../use-auto-mode"; |
| 11 | + |
| 12 | +vi.mock("../use-auto-mode", () => ({ useAutoMode: vi.fn() })); |
| 13 | + |
| 14 | +const fcReturns = () => |
| 15 | + fc |
| 16 | + .record({ |
| 17 | + autoMode: fcUndefinedOr(fc.boolean()).map((v) => ref(v)), |
| 18 | + pulling: fc.constant(ref(false)), |
| 19 | + loading: fc.boolean().map((v) => ref(v)), |
| 20 | + error: fcUndefinedOr(fcError).map((v) => ref(v)), |
| 21 | + }) |
| 22 | + .map((ret) => onReady(ret, Promise.resolve())); |
| 23 | + |
| 24 | +describe("AutoModeButton", () => { |
| 25 | + it("Property test", () => { |
| 26 | + fc.assert( |
| 27 | + fc.property(fcReturns(), (ret) => { |
| 28 | + vi.mocked(useAutoMode).mockReturnValue(ret); |
| 29 | + const wrapper = mount(AutoModeButton, { |
| 30 | + global: { |
| 31 | + stubs: { |
| 32 | + ButtonOff: true, |
| 33 | + ButtonAutoMode: true, |
| 34 | + ButtonError: true, |
| 35 | + }, |
| 36 | + }, |
| 37 | + }); |
| 38 | + |
| 39 | + if (ret.loading.value) { |
| 40 | + const button = wrapper.findComponent({ name: "VBtn" }); |
| 41 | + expect(button.exists()).toBe(true); |
| 42 | + expect(button.props()["loading"]).toBe(true); |
| 43 | + } else if (ret.error.value) { |
| 44 | + const button = wrapper.findComponent({ name: "ButtonError" }); |
| 45 | + expect(button.exists()).toBe(true); |
| 46 | + expect(button.props("error")).toEqual(ret.error.value); |
| 47 | + } else if (ret.autoMode.value === true) { |
| 48 | + expect(wrapper.findComponent({ name: "ButtonAutoMode" }).exists()).toBe(true); |
| 49 | + } else if (ret.autoMode.value === false) { |
| 50 | + expect(wrapper.findComponent({ name: "ButtonOff" }).exists()).toBe(true); |
| 51 | + } else { |
| 52 | + expect(wrapper.html()).toContain("Unknown"); |
| 53 | + } |
| 54 | + wrapper.unmount(); |
| 55 | + }), |
| 56 | + ); |
| 57 | + }); |
| 58 | +}); |
0 commit comments