Field.spec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { shallowMount } from "@vue/test-utils"
  2. import field from "../Field"
  3. const gqlField = {
  4. name: "testField",
  5. args: [
  6. {
  7. name: "arg1",
  8. type: "Arg1Type",
  9. },
  10. {
  11. name: "arg2",
  12. type: "Arg2type",
  13. },
  14. ],
  15. type: "FieldType",
  16. description: "TestDescription",
  17. }
  18. const factory = (props) =>
  19. shallowMount(field, {
  20. propsData: props,
  21. stubs: {
  22. GraphqlTypeLink: {
  23. template: "<span>Typelink</span>",
  24. },
  25. },
  26. mocks: {
  27. $t: (text) => text,
  28. },
  29. })
  30. describe("field", () => {
  31. test("mounts properly if props are given", () => {
  32. const wrapper = factory({
  33. gqlField,
  34. })
  35. expect(wrapper).toBeTruthy()
  36. })
  37. test("field title is set correctly for fields with no args", () => {
  38. const wrapper = factory({
  39. gqlField: {
  40. ...gqlField,
  41. args: undefined,
  42. },
  43. })
  44. expect(
  45. wrapper
  46. .find(".field-title")
  47. .text()
  48. .replace(/[\r\n]+/g, "")
  49. .replace(/ +/g, " ")
  50. ).toEqual("testField : Typelink")
  51. })
  52. test("field title is correctly given for fields with single arg", () => {
  53. const wrapper = factory({
  54. gqlField: {
  55. ...gqlField,
  56. args: [
  57. {
  58. name: "arg1",
  59. type: "Arg1Type",
  60. },
  61. ],
  62. },
  63. })
  64. expect(
  65. wrapper
  66. .find(".field-title")
  67. .text()
  68. .replace(/[\r\n]+/g, "")
  69. .replace(/ +/g, " ")
  70. ).toEqual("testField ( arg1: Typelink ) : Typelink")
  71. })
  72. test("field title is correctly given for fields with multiple args", () => {
  73. const wrapper = factory({
  74. gqlField: {
  75. ...gqlField,
  76. args: [
  77. {
  78. name: "arg1",
  79. type: "Arg1Type",
  80. },
  81. ],
  82. },
  83. })
  84. expect(
  85. wrapper
  86. .find(".field-title")
  87. .text()
  88. .replace(/[\r\n]+/g, "")
  89. .replace(/ +/g, " ")
  90. ).toEqual("testField ( arg1: Typelink ) : Typelink")
  91. })
  92. test("all typelinks are passed the jump callback", () => {
  93. const wrapper = factory({
  94. gqlField: {
  95. ...gqlField,
  96. args: [
  97. {
  98. name: "arg1",
  99. type: "Arg1Type",
  100. },
  101. {
  102. name: "arg2",
  103. type: "Arg2Type",
  104. },
  105. ],
  106. },
  107. })
  108. expect(
  109. wrapper
  110. .find(".field-title")
  111. .text()
  112. .replace(/[\r\n]+/g, "")
  113. .replace(/ +/g, " ")
  114. ).toEqual("testField ( arg1: Typelink , arg2: Typelink ) : Typelink")
  115. })
  116. test("description is rendered when it is present", () => {
  117. const wrapper = factory({
  118. gqlField,
  119. })
  120. expect(wrapper.find(".field-desc").text()).toEqual("TestDescription")
  121. })
  122. test("description not rendered when it is not present", () => {
  123. const wrapper = factory({
  124. gqlField: {
  125. ...gqlField,
  126. description: undefined,
  127. },
  128. })
  129. expect(wrapper.find(".field-desc").exists()).toEqual(false)
  130. })
  131. test("deprecation warning is displayed when field is deprecated", () => {
  132. const wrapper = factory({
  133. gqlField: {
  134. ...gqlField,
  135. isDeprecated: true,
  136. },
  137. })
  138. expect(wrapper.find(".field-deprecated").exists()).toEqual(true)
  139. })
  140. test("deprecation warning is not displayed wwhen field is not deprecated", () => {
  141. const wrapper = factory({
  142. gqlField: {
  143. ...gqlField,
  144. isDeprecated: false,
  145. },
  146. })
  147. expect(wrapper.find(".field-deprecated").exists()).toEqual(false)
  148. })
  149. })