From e1eb1be781487fa016b81bbae834657e5a888622 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 23 Aug 2020 17:40:32 -0400 Subject: [PATCH] Add test spec for components/graphql/type.vue --- components/graphql/__types__/type.spec.js | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 components/graphql/__types__/type.spec.js diff --git a/components/graphql/__types__/type.spec.js b/components/graphql/__types__/type.spec.js new file mode 100644 index 000000000..4960a9b4f --- /dev/null +++ b/components/graphql/__types__/type.spec.js @@ -0,0 +1,75 @@ +import type from "../type" + +import { shallowMount } from "@vue/test-utils" + +const gqlType = { + name: "TestType", + description: "TestDescription", + getFields: () => [{ name: "field1" }, { name: "field2" }], +} + +const factory = (props) => + shallowMount(type, { + mocks: { + $t: (text) => text, + }, + propsData: props, + stubs: ["field"], + }) + +describe("type", () => { + test("mounts properly when props are passed", () => { + const wrapper = factory({ + gqlType, + }) + + expect(wrapper).toBeTruthy() + }) + + test("title of the type is rendered properly", () => { + const wrapper = factory({ + gqlType, + }) + + expect(wrapper.find(".type-title").text()).toEqual("TestType") + }) + + test("description of the type is rendered properly if present", () => { + const wrapper = factory({ + gqlType, + }) + + expect(wrapper.find(".type-desc").text()).toEqual("TestDescription") + }) + + test("description of the type is not rendered if not present", () => { + const wrapper = factory({ + gqlType: { + ...gqlType, + description: undefined, + }, + }) + + expect(wrapper.find(".type-desc").exists()).toEqual(false) + }) + + test("fields are not rendered if not present", () => { + const wrapper = factory({ + gqlType: { + ...gqlType, + getFields: undefined, + }, + }) + expect(wrapper.find("field-stub").exists()).toEqual(false) + }) + + test("all fields are rendered if present with props passed properly", () => { + const wrapper = factory({ + gqlType: { + ...gqlType, + }, + }) + + expect(wrapper.findAll("field-stub").length).toEqual(2) + }) +})