GraphqlCard.sample 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { mount } from "@vue/test-utils"
  2. import GraphqlCard from "../graphql/Card"
  3. const factory = (props) => {
  4. return mount(GraphqlCard, {
  5. propsData: props,
  6. mocks: {
  7. $t: (text) => text,
  8. },
  9. directives: {
  10. tooltip() {
  11. /* stub */
  12. },
  13. closePopover() {
  14. /* stub */
  15. },
  16. },
  17. })
  18. }
  19. const url = "https://dummydata.com"
  20. const query = `query getUser($uid: String!) {
  21. user(uid: $uid) {
  22. name
  23. }
  24. }`
  25. describe("GraphqlCard", () => {
  26. test("Mounts properly if props are given", () => {
  27. const wrapper = factory({
  28. entry: {
  29. type: "graphql",
  30. url,
  31. query,
  32. star: false,
  33. },
  34. })
  35. expect(wrapper).toBeTruthy()
  36. })
  37. // test("toggle-star emitted on clicking on star button", async () => {
  38. // const wrapper = factory({
  39. // entry: {
  40. // type: "graphql",
  41. // url,
  42. // query,
  43. // star: true,
  44. // },
  45. // })
  46. // await wrapper.find("button[data-testid='star_button']").trigger("click")
  47. // expect(wrapper.emitted("toggle-star")).toBeTruthy()
  48. // })
  49. test("query expands on clicking the show more button", async () => {
  50. const wrapper = factory({
  51. entry: {
  52. type: "graphql",
  53. url,
  54. query,
  55. star: true,
  56. },
  57. })
  58. expect(wrapper.vm.query).toStrictEqual([
  59. `query getUser($uid: String!) {`,
  60. ` user(uid: $uid) {`,
  61. `...`,
  62. ])
  63. await wrapper.find("button[data-testid='query_expand']").trigger("click")
  64. expect(wrapper.vm.query).toStrictEqual([
  65. `query getUser($uid: String!) {`,
  66. ` user(uid: $uid) {`,
  67. ` name`,
  68. ` }`,
  69. `}`,
  70. ])
  71. })
  72. // test("use-entry emit on clicking the restore button", async () => {
  73. // const wrapper = factory({
  74. // entry: {
  75. // type: "graphql",
  76. // url,
  77. // query,
  78. // star: true,
  79. // },
  80. // })
  81. // await wrapper
  82. // .find("button[data-testid='restore_history_entry']")
  83. // .trigger("click")
  84. // expect(wrapper.emitted("use-entry")).toBeTruthy()
  85. // })
  86. // test("delete-entry emit on clicking the delete button", async () => {
  87. // const wrapper = factory({
  88. // entry: {
  89. // type: "graphql",
  90. // url,
  91. // query,
  92. // star: true,
  93. // },
  94. // })
  95. // await wrapper
  96. // .find("button[data-testid=delete_history_entry]")
  97. // .trigger("click")
  98. // expect(wrapper.emitted("delete-entry")).toBeTruthy()
  99. // })
  100. })