forked from hoppscotch/hoppscotch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test spec for components/graphql/field.vue
- Loading branch information
1 parent
5150e13
commit b8bd0cc
Showing
1 changed file
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
import field from "../field" | ||
import { shallowMount } from "@vue/test-utils" | ||
|
||
const gqlField = { | ||
name: "testField", | ||
args: [ | ||
{ | ||
name: "arg1", | ||
type: "Arg1Type", | ||
}, | ||
{ | ||
name: "arg2", | ||
type: "Arg2type", | ||
}, | ||
], | ||
type: "FieldType", | ||
description: "TestDescription", | ||
} | ||
|
||
const factory = (props) => | ||
shallowMount(field, { | ||
propsData: props, | ||
stubs: { | ||
typelink: { | ||
template: "<span>Typelink</span>", | ||
}, | ||
}, | ||
mocks: { | ||
$t: (text) => text, | ||
}, | ||
}) | ||
|
||
describe("field", () => { | ||
test("mounts properly if props are given", () => { | ||
const wrapper = factory({ | ||
gqlField, | ||
}) | ||
|
||
expect(wrapper).toBeTruthy() | ||
}) | ||
|
||
test("field title is set correctly for fields with no args", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
args: undefined, | ||
}, | ||
}) | ||
|
||
expect( | ||
wrapper | ||
.find(".field-title") | ||
.text() | ||
.replace(/[\r\n]+/g, "") | ||
.replace(/ +/g, " ") | ||
).toEqual("testField : Typelink") | ||
}) | ||
|
||
test("field title is correctly given for fields with single arg", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
args: [ | ||
{ | ||
name: "arg1", | ||
type: "Arg1Type", | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect( | ||
wrapper | ||
.find(".field-title") | ||
.text() | ||
.replace(/[\r\n]+/g, "") | ||
.replace(/ +/g, " ") | ||
).toEqual("testField ( arg1: Typelink ) : Typelink") | ||
}) | ||
|
||
test("field title is correctly given for fields with multiple args", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
args: [ | ||
{ | ||
name: "arg1", | ||
type: "Arg1Type", | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect( | ||
wrapper | ||
.find(".field-title") | ||
.text() | ||
.replace(/[\r\n]+/g, "") | ||
.replace(/ +/g, " ") | ||
).toEqual("testField ( arg1: Typelink ) : Typelink") | ||
}) | ||
|
||
test("all typelinks are passed the jump callback", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
args: [ | ||
{ | ||
name: "arg1", | ||
type: "Arg1Type", | ||
}, | ||
{ | ||
name: "arg2", | ||
type: "Arg2Type", | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect( | ||
wrapper | ||
.find(".field-title") | ||
.text() | ||
.replace(/[\r\n]+/g, "") | ||
.replace(/ +/g, " ") | ||
).toEqual("testField ( arg1: Typelink , arg2: Typelink ) : Typelink") | ||
}) | ||
|
||
test("description is rendered when it is present", () => { | ||
const wrapper = factory({ | ||
gqlField, | ||
}) | ||
|
||
expect(wrapper.find(".field-desc").text()).toEqual("TestDescription") | ||
}) | ||
|
||
test("description not rendered when it is not present", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
description: undefined, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find(".field-desc").exists()).toEqual(false) | ||
}) | ||
|
||
test("deprecation warning is displayed when field is deprecated", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
isDeprecated: true, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find(".field-deprecated").exists()).toEqual(true) | ||
}) | ||
|
||
test("deprecation warning is not displayed wwhen field is not deprecated", () => { | ||
const wrapper = factory({ | ||
gqlField: { | ||
...gqlField, | ||
isDeprecated: false, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find(".field-deprecated").exists()).toEqual(false) | ||
}) | ||
}) |