|
| 1 | +import { mount } from "@vue/test-utils"; |
| 2 | +import { describe, expect, it, vi } from "vitest"; |
| 3 | +import Container from "../Container.vue"; |
| 4 | + |
| 5 | +vi.mock("@/utils/functions", () => ({ |
| 6 | + checkBenchieSupport: () => false, |
| 7 | +})); |
| 8 | + |
| 9 | +describe("Container", () => { |
| 10 | + it("renders with default props", () => { |
| 11 | + const wrapper = mount(Container); |
| 12 | + expect(wrapper.html({ raw: true })).toContain( |
| 13 | + '<div class="container"></div>', |
| 14 | + ); |
| 15 | + }); |
| 16 | + |
| 17 | + it("render with type class", () => { |
| 18 | + const wrapper = mount(Container, { |
| 19 | + props: { |
| 20 | + type: "type-class-1 type-class-2", |
| 21 | + }, |
| 22 | + }); |
| 23 | + expect(wrapper.classes()).length(3); |
| 24 | + expect(wrapper.classes()).toContain("container"); |
| 25 | + expect(wrapper.classes()).toContain("type-class-1"); |
| 26 | + expect(wrapper.classes()).toContain("type-class-2"); |
| 27 | + |
| 28 | + // check order |
| 29 | + expect(wrapper.html({ raw: true })).toContain( |
| 30 | + '<div class="container type-class-1 type-class-2"></div>', |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + it("render with class attribute", () => { |
| 35 | + const wrapper = mount(Container, { |
| 36 | + attrs: { |
| 37 | + class: "custom-class", |
| 38 | + }, |
| 39 | + }); |
| 40 | + expect(wrapper.classes()).length(2); |
| 41 | + expect(wrapper.classes()).toContain("container"); |
| 42 | + expect(wrapper.classes()).toContain("custom-class"); |
| 43 | + |
| 44 | + // check order |
| 45 | + expect(wrapper.html({ raw: true })).toContain( |
| 46 | + '<div class="container custom-class"></div>', |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it("render with type class and class attribute", () => { |
| 51 | + const wrapper = mount(Container, { |
| 52 | + props: { |
| 53 | + type: "type-class-1 type-class-2", |
| 54 | + }, |
| 55 | + attrs: { |
| 56 | + class: "custom-class-1 custom-class-2", |
| 57 | + }, |
| 58 | + }); |
| 59 | + expect(wrapper.classes()).length(5); |
| 60 | + expect(wrapper.classes()).toContain("container"); |
| 61 | + expect(wrapper.classes()).toContain("type-class-1"); |
| 62 | + expect(wrapper.classes()).toContain("type-class-2"); |
| 63 | + expect(wrapper.classes()).toContain("custom-class-1"); |
| 64 | + expect(wrapper.classes()).toContain("custom-class-2"); |
| 65 | + |
| 66 | + // check order |
| 67 | + expect(wrapper.html({ raw: true })).toContain( |
| 68 | + '<div class="container type-class-1 type-class-2 custom-class-1 custom-class-2"></div>', |
| 69 | + ); |
| 70 | + }); |
| 71 | + |
| 72 | + it("render with class attribute", () => { |
| 73 | + const wrapper = mount(Container, { |
| 74 | + attrs: { |
| 75 | + class: "custom-class", |
| 76 | + }, |
| 77 | + }); |
| 78 | + expect(wrapper.classes()).length(2); |
| 79 | + expect(wrapper.classes()).toContain("container"); |
| 80 | + expect(wrapper.classes()).toContain("custom-class"); |
| 81 | + }); |
| 82 | + |
| 83 | + it("render with type class and class attribute", () => { |
| 84 | + const wrapper = mount(Container, { |
| 85 | + props: { |
| 86 | + type: "type-class-1 type-class-2", |
| 87 | + }, |
| 88 | + attrs: { |
| 89 | + class: "custom-class-1 custom-class-2", |
| 90 | + }, |
| 91 | + }); |
| 92 | + expect(wrapper.classes()).length(5); |
| 93 | + expect(wrapper.classes()).toContain("container"); |
| 94 | + expect(wrapper.classes()).toContain("type-class-1"); |
| 95 | + expect(wrapper.classes()).toContain("type-class-2"); |
| 96 | + expect(wrapper.classes()).toContain("custom-class-1"); |
| 97 | + expect(wrapper.classes()).toContain("custom-class-2"); |
| 98 | + }); |
| 99 | + |
| 100 | + it("render with background image", () => { |
| 101 | + const wrapper = mount(Container, { |
| 102 | + props: { |
| 103 | + bg: "https://example.com/image.jpg", |
| 104 | + }, |
| 105 | + }); |
| 106 | + const containerEl = wrapper.element; |
| 107 | + expect(containerEl.style.backgroundImage).toBe( |
| 108 | + "url(https://example.com/image.jpg)", |
| 109 | + ); |
| 110 | + expect(containerEl.style.backgroundSize).toBe("cover"); |
| 111 | + expect(containerEl.style.backgroundRepeat).toBe("no-repeat"); |
| 112 | + }); |
| 113 | +}); |
0 commit comments