From 9166f734c98a53f306f2644ffb1335fa20f8776b Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 24 Aug 2020 15:42:48 -0400 Subject: [PATCH] Add test spec for components/ui/tab.vue --- components/ui/__tests__/tab.spec.js | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 components/ui/__tests__/tab.spec.js diff --git a/components/ui/__tests__/tab.spec.js b/components/ui/__tests__/tab.spec.js new file mode 100644 index 00000000..de3a754d --- /dev/null +++ b/components/ui/__tests__/tab.spec.js @@ -0,0 +1,75 @@ +import tab from "../tab" +import { mount } from "@vue/test-utils" + +const factory = (props, data) => + mount(tab, { + propsData: props, + data: data ? () => data : undefined, + slots: { + default: '
', + }, + }) + +describe("tab", () => { + test("mounts properly when needed props are passed in", () => { + const wrapper = factory({ + label: "TestLabel", + icon: "TestIcon", + id: "testid", + selected: true, + }) + + expect(wrapper).toBeTruthy() + }) + + test("mounts properly when selected prop is not passed", () => { + const wrapper = factory({ + label: "TestLabel", + icon: "TestIcon", + id: "testid", + }) + + expect(wrapper).toBeTruthy() + }) + + test("if 'selected' prop is not passed, it is set to false by default", () => { + const wrapper = factory({ + label: "TestLabel", + icon: "TestIcon", + id: "testid", + }) + + expect(wrapper.props("selected")).toEqual(false) + }) + + test("if set active, the slot is shown", () => { + const wrapper = factory( + { + label: "TestLabel", + icon: "TestIcon", + id: "testid", + selected: true, + }, + { + isActive: true, + } + ) + + expect(wrapper.find("#testdiv").element.parentElement).toBeVisible() + }) + + test("if not set active, the slot is not rendered", () => { + const wrapper = factory( + { + label: "TestLabel", + icon: "TestIcon", + id: "testid", + }, + { + isActive: false, + } + ) + + expect(wrapper.find("#testdiv").element.parentElement).not.toBeVisible() + }) +})