Added tests for the added functionality in type.vue and typelink.vue

This commit is contained in:
Andrew Bastin
2021-02-08 21:08:30 -05:00
parent 09719a4ad3
commit e8e855a36c
2 changed files with 174 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import type from "../type"
import { shallowMount } from "@vue/test-utils"
import {GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType} from "graphql"
const gqlType = {
name: "TestType",
@@ -14,7 +15,7 @@ const factory = (props) =>
$t: (text) => text,
},
propsData: { gqlTypes: [], ...props },
stubs: ["field"],
stubs: ["field", "typelink"],
})
describe("type", () => {
@@ -72,4 +73,162 @@ describe("type", () => {
expect(wrapper.findAll("field-stub").length).toEqual(2)
})
test("prepends 'input' to type name for Input Types", () => {
const testType = new GraphQLInputObjectType({
name: "TestType",
fields: {}
})
const wrapper = factory({
gqlType: testType
})
expect(wrapper.find(".type-title").text().startsWith("input")).toEqual(true)
})
test("prepends 'interface' to type name for Interface Types", () => {
const testType = new GraphQLInterfaceType({
name: "TestType",
fields: {}
})
const wrapper = factory({
gqlType: testType
})
expect(wrapper.find(".type-title").text().startsWith("interface")).toEqual(true)
})
test("prepends 'enum' to type name for Enum Types", () => {
const testType = new GraphQLEnumType({
name: "TestType",
values: {}
})
const wrapper = factory({
gqlType: testType
})
expect(wrapper.find(".type-title").text().startsWith("enum")).toEqual(true)
})
test("'interfaces' computed property returns all the related interfaces", () => {
const testInterfaceA = new GraphQLInterfaceType({
name: "TestInterfaceA",
fields: {}
})
const testInterfaceB = new GraphQLInterfaceType({
name: "TestInterfaceB",
fields: {}
})
const type = new GraphQLObjectType({
name: "TestType",
interfaces: [testInterfaceA, testInterfaceB],
fields: {}
})
const wrapper = factory({
gqlType: type
})
expect(wrapper.vm.interfaces).toEqual(expect.arrayContaining([testInterfaceA, testInterfaceB]))
})
test("'interfaces' computed property returns an empty array if there are no interfaces", () => {
const type = new GraphQLObjectType({
name: "TestType",
fields: {}
})
const wrapper = factory({
gqlType: type
})
expect(wrapper.vm.interfaces).toEqual([])
})
test("'interfaces' computed property returns an empty array if the type is an enum", () => {
const type = new GraphQLEnumType({
name: "TestType",
values: {}
})
const wrapper = factory({
gqlType: type
})
expect(wrapper.vm.interfaces).toEqual([])
})
test("'children' computed property returns all the types implementing an interface", () => {
const testInterface = new GraphQLInterfaceType({
name: "TestInterface",
fields: {}
})
const typeA = new GraphQLObjectType({
name: "TypeA",
interfaces: [testInterface],
fields: {}
})
const typeB = new GraphQLObjectType({
name: "TypeB",
interfaces: [testInterface],
fields: {}
})
const wrapper = factory({
gqlType: testInterface,
gqlTypes: [testInterface, typeA, typeB]
})
expect(wrapper.vm.children).toEqual(expect.arrayContaining([typeA, typeB]))
})
test("'children' computed property returns an empty array if there are no types implementing the interface", () => {
const testInterface = new GraphQLInterfaceType({
name: "TestInterface",
fields: {}
})
const typeA = new GraphQLObjectType({
name: "TypeA",
fields: {}
})
const typeB = new GraphQLObjectType({
name: "TypeB",
fields: {}
})
const wrapper = factory({
gqlType: testInterface,
gqlTypes: [testInterface, typeA, typeB]
})
expect(wrapper.vm.children).toEqual([])
})
test("'children' computed property returns an empty array if the type is an enum", () => {
const testInterface = new GraphQLInterfaceType({
name: "TestInterface",
fields: {}
})
const testType = new GraphQLEnumType({
name: "TestEnum",
values: {}
})
const wrapper = factory({
gqlType: testType,
gqlTypes: [testInterface, testType]
})
expect(wrapper.vm.children).toEqual([])
})
})

View File

@@ -1,5 +1,6 @@
import typelink from "../typelink"
import { shallowMount } from "@vue/test-utils"
import {GraphQLInt} from "graphql"
const factory = (props) =>
shallowMount(typelink, {
@@ -33,6 +34,19 @@ describe("typelink", () => {
expect(callback).toHaveBeenCalledTimes(1)
})
test("jumpToType callback is not called if the root type is a scalar", async () => {
const callback = jest.fn()
const wrapper = factory({
gqlType: GraphQLInt,
jumpTypeCallback: callback
})
await wrapper.trigger("click")
expect(callback).not.toHaveBeenCalled()
})
test("link text is the type string", () => {
const wrapper = factory({
gqlType,