123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import { flushPromises } from "@vue/test-utils";
- import { h } from "vue";
- import { getWrapper } from "@/tests/utils/utils";
- import { useConfigStore } from "@/stores/config";
- import { useModalsStore } from "@/stores/modals";
- import Modal from "@/components/Modal.vue";
- describe("Modal component", () => {
- beforeEach(async context => {
- context.wrapper = await getWrapper(Modal);
- });
- test("title prop", async ({ wrapper }) => {
- const title = "Modal Title";
- await wrapper.setProps({ title });
- expect(wrapper.find(".modal-card-title").text()).toBe(title);
- });
- test("size prop", async ({ wrapper }) => {
- await wrapper.setProps({ size: "slim" });
- expect(wrapper.find(".modal-card").classes()).toContain("modal-slim");
- await wrapper.setProps({ size: "wide" });
- expect(wrapper.find(".modal-card").classes()).toContain("modal-wide");
- });
- test("split prop", async ({ wrapper }) => {
- expect(wrapper.find(".modal-card").classes()).not.toContain(
- "modal-split"
- );
- await wrapper.setProps({ split: true });
- expect(wrapper.find(".modal-card").classes()).toContain("modal-split");
- });
- test("christmas lights render if enabled", async () => {
- const wrapper = await getWrapper(Modal, {
- shallow: true
- });
- const configStore = useConfigStore();
- configStore.christmas = true;
- await flushPromises();
- expect(
- wrapper.findComponent({ name: "ChristmasLights" }).exists()
- ).toBeTruthy();
- });
- test("click to close modal calls store action", async ({ wrapper }) => {
- const modalsStore = useModalsStore();
- await wrapper.find(".modal-background").trigger("click");
- await wrapper.find(".modal-card-head > .delete").trigger("click");
- await flushPromises();
- expect(modalsStore.closeCurrentModal).toHaveBeenCalledTimes(2);
- });
- test("renders slots", async () => {
- const wrapper = await getWrapper(Modal, {
- slots: {
- sidebar: h("div", {}, "Sidebar Slot"),
- toggleMobileSidebar: h("div", {}, "Toggle Mobile Sidebar Slot"),
- body: h("div", {}, "Body Slot"),
- footer: h("div", {}, "Footer Slot")
- }
- });
- expect(wrapper.html()).toMatchSnapshot();
- });
- });
|