Modal.spec.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { flushPromises } from "@vue/test-utils";
  2. import { h } from "vue";
  3. import { getWrapper } from "@/tests/utils/utils";
  4. import { useConfigStore } from "@/stores/config";
  5. import { useModalsStore } from "@/stores/modals";
  6. import Modal from "@/components/Modal.vue";
  7. describe("Modal component", () => {
  8. beforeEach(async context => {
  9. context.wrapper = await getWrapper(Modal);
  10. });
  11. test("title prop", async ({ wrapper }) => {
  12. const title = "Modal Title";
  13. await wrapper.setProps({ title });
  14. expect(wrapper.find(".modal-card-title").text()).toBe(title);
  15. });
  16. test("size prop", async ({ wrapper }) => {
  17. await wrapper.setProps({ size: "slim" });
  18. expect(wrapper.find(".modal-card").classes()).toContain("modal-slim");
  19. await wrapper.setProps({ size: "wide" });
  20. expect(wrapper.find(".modal-card").classes()).toContain("modal-wide");
  21. });
  22. test("split prop", async ({ wrapper }) => {
  23. expect(wrapper.find(".modal-card").classes()).not.toContain(
  24. "modal-split"
  25. );
  26. await wrapper.setProps({ split: true });
  27. expect(wrapper.find(".modal-card").classes()).toContain("modal-split");
  28. });
  29. test("christmas lights render if enabled", async () => {
  30. const wrapper = await getWrapper(Modal, {
  31. shallow: true
  32. });
  33. const configStore = useConfigStore();
  34. configStore.christmas = true;
  35. await flushPromises();
  36. expect(
  37. wrapper.findComponent({ name: "ChristmasLights" }).exists()
  38. ).toBeTruthy();
  39. });
  40. test("click to close modal calls store action", async ({ wrapper }) => {
  41. const modalsStore = useModalsStore();
  42. await wrapper.find(".modal-background").trigger("click");
  43. await wrapper.find(".modal-card-head > .delete").trigger("click");
  44. await flushPromises();
  45. expect(modalsStore.closeCurrentModal).toHaveBeenCalledTimes(2);
  46. });
  47. test("renders slots", async () => {
  48. const wrapper = await getWrapper(Modal, {
  49. slots: {
  50. sidebar: h("div", {}, "Sidebar Slot"),
  51. toggleMobileSidebar: h("div", {}, "Toggle Mobile Sidebar Slot"),
  52. body: h("div", {}, "Body Slot"),
  53. footer: h("div", {}, "Footer Slot")
  54. }
  55. });
  56. expect(wrapper.html()).toMatchSnapshot();
  57. });
  58. });