|
| 1 | +import { describe, expect, it } from "@test/unit"; |
| 2 | +import { mount } from "@vue/test-utils"; |
| 3 | +import ModelTabs from "./ModelTabs.vue"; |
| 4 | + |
| 5 | +const tabs = [ |
| 6 | + { |
| 7 | + name: "main", |
| 8 | + fields: ["headline", "Text"] |
| 9 | + }, |
| 10 | + { |
| 11 | + name: "meta", |
| 12 | + fields: ["seo"] |
| 13 | + } |
| 14 | +]; |
| 15 | + |
| 16 | +type Badge = { text: number } | undefined; |
| 17 | + |
| 18 | +function badges(diff = {}): Badge[] { |
| 19 | + const wrapper = mount(ModelTabs, { props: { tab: "main", tabs, diff } }); |
| 20 | + const withBadges = wrapper.vm.withBadges as { badge: Badge }[]; |
| 21 | + return withBadges.map((tab) => tab.badge); |
| 22 | +} |
| 23 | + |
| 24 | +describe("ModelTabs.vue", () => { |
| 25 | + describe("element", () => { |
| 26 | + it.rendersAs(() => mount(ModelTabs).find("k-tabs"), "K-TABS"); |
| 27 | + }); |
| 28 | + |
| 29 | + describe("withBadges", () => { |
| 30 | + it("counts the changed fields of a tab", () => { |
| 31 | + expect(badges({ headline: "a", seo: "b" })).toStrictEqual([ |
| 32 | + { text: 1 }, |
| 33 | + { text: 1 } |
| 34 | + ]); |
| 35 | + }); |
| 36 | + |
| 37 | + it("compares the field names case-insensitively", () => { |
| 38 | + expect(badges({ text: "a" })).toStrictEqual([{ text: 1 }, undefined]); |
| 39 | + }); |
| 40 | + |
| 41 | + it("has no badge without changes", () => { |
| 42 | + expect(badges()).toStrictEqual([undefined, undefined]); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
0 commit comments