Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

292 рядки
9.4 KiB

  1. describe("Deep linking feature", () => {
  2. describe("in Swagger 2", () => {
  3. const swagger2BaseUrl = "/?deepLinking=true&url=/documents/features/deep-linking.swagger.yaml"
  4. describe("regular Operation", () => {
  5. OperationDeeplinkTestFactory({
  6. baseUrl: swagger2BaseUrl,
  7. elementToGet: ".opblock-get",
  8. correctElementId: "operations-myTag-myOperation",
  9. correctFragment: "#/myTag/myOperation",
  10. correctHref: "#/myTag/myOperation"
  11. })
  12. })
  13. describe("Operation with whitespace in tag+id", () => {
  14. const elementToGet = ".opblock-post"
  15. const correctFragment = "#/my%20Tag/my%20Operation"
  16. OperationDeeplinkTestFactory({
  17. baseUrl: swagger2BaseUrl,
  18. elementToGet,
  19. correctElementId: "operations-my_Tag-my_Operation",
  20. correctFragment,
  21. correctHref: "#/my%20Tag/my%20Operation"
  22. })
  23. const legacyFragment = "#/my_Tag/my_Operation"
  24. it("should expand the operation when reloaded and provided the legacy fragment", () => {
  25. cy.visit(`${swagger2BaseUrl}${legacyFragment}`)
  26. .reload()
  27. .get(`${elementToGet}.is-open`)
  28. .should("exist")
  29. })
  30. it.skip("should rewrite to the correct fragment when provided the legacy fragment", () => {
  31. cy.visit(`${swagger2BaseUrl}${legacyFragment}`)
  32. .reload()
  33. .window()
  34. .should("have.deep.property", "location.hash", correctFragment)
  35. })
  36. })
  37. describe("Operation with underscores in tag+id", () => {
  38. OperationDeeplinkTestFactory({
  39. baseUrl: swagger2BaseUrl,
  40. elementToGet: ".opblock-patch",
  41. correctElementId: "operations-underscore_Tag-underscore_Operation",
  42. correctFragment: "#/underscore_Tag/underscore_Operation",
  43. correctHref: "#/underscore_Tag/underscore_Operation"
  44. })
  45. })
  46. describe("Operation with UTF-16 characters", () => {
  47. OperationDeeplinkTestFactory({
  48. baseUrl: swagger2BaseUrl,
  49. elementToGet: ".opblock-head",
  50. correctElementId: "operations-шеллы-пошел",
  51. correctFragment: "#/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B/%D0%BF%D0%BE%D1%88%D0%B5%D0%BB",
  52. correctHref: "#/шеллы/пошел"
  53. })
  54. })
  55. describe("Operation with no operationId", () => {
  56. OperationDeeplinkTestFactory({
  57. baseUrl: swagger2BaseUrl,
  58. elementToGet: ".opblock-put",
  59. correctElementId: "operations-tagTwo-put_noOperationId",
  60. correctFragment: "#/tagTwo/put_noOperationId",
  61. correctHref: "#/tagTwo/put_noOperationId"
  62. })
  63. })
  64. describe("regular Tag", () => {
  65. TagDeeplinkTestFactory({
  66. isTagCase: true,
  67. baseUrl: swagger2BaseUrl,
  68. elementToGet: `.opblock-tag[data-tag="myTag"][data-is-open="true"]`,
  69. correctElementId: "operations-tag-myTag",
  70. correctFragment: "#/myTag",
  71. correctHref: "#/myTag"
  72. })
  73. })
  74. describe("Tag with whitespace", () => {
  75. TagDeeplinkTestFactory({
  76. isTagCase: true,
  77. baseUrl: swagger2BaseUrl,
  78. elementToGet: `.opblock-tag[data-tag="my Tag"][data-is-open="true"]`,
  79. correctElementId: "operations-tag-my_Tag",
  80. correctFragment: "#/my%20Tag",
  81. correctHref: "#/my%20Tag"
  82. })
  83. })
  84. })
  85. describe("in OpenAPI 3", () => {
  86. const openAPI3BaseUrl = "/?deepLinking=true&url=/documents/features/deep-linking.openapi.yaml"
  87. describe("regular Operation", () => {
  88. OperationDeeplinkTestFactory({
  89. baseUrl: openAPI3BaseUrl,
  90. elementToGet: ".opblock-get",
  91. correctElementId: "operations-myTag-myOperation",
  92. correctFragment: "#/myTag/myOperation",
  93. correctHref: "#/myTag/myOperation"
  94. })
  95. })
  96. describe("Operation with whitespace in tag+id", () => {
  97. const elementToGet = ".opblock-post"
  98. const correctFragment = "#/my%20Tag/my%20Operation"
  99. OperationDeeplinkTestFactory({
  100. baseUrl: openAPI3BaseUrl,
  101. elementToGet: ".opblock-post",
  102. correctElementId: "operations-my_Tag-my_Operation",
  103. correctFragment,
  104. correctHref: "#/my%20Tag/my%20Operation"
  105. })
  106. const legacyFragment = "#/my_Tag/my_Operation"
  107. it("should expand the operation when reloaded and provided the legacy fragment", () => {
  108. cy.visit(`${openAPI3BaseUrl}${legacyFragment}`)
  109. .reload()
  110. .get(`${elementToGet}.is-open`)
  111. .should("exist")
  112. })
  113. it.skip("should rewrite to the correct fragment when provided the legacy fragment", () => {
  114. cy.visit(`${openAPI3BaseUrl}${legacyFragment}`)
  115. .reload()
  116. .window()
  117. .should("have.deep.property", "location.hash", correctFragment)
  118. })
  119. })
  120. describe("Operation with underscores in tag+id", () => {
  121. OperationDeeplinkTestFactory({
  122. baseUrl: openAPI3BaseUrl,
  123. elementToGet: ".opblock-patch",
  124. correctElementId: "operations-underscore_Tag-underscore_Operation",
  125. correctFragment: "#/underscore_Tag/underscore_Operation",
  126. correctHref: "#/underscore_Tag/underscore_Operation"
  127. })
  128. })
  129. describe("Operation with UTF-16 characters", () => {
  130. OperationDeeplinkTestFactory({
  131. baseUrl: openAPI3BaseUrl,
  132. elementToGet: ".opblock-head",
  133. correctElementId: "operations-шеллы-пошел",
  134. correctFragment: "#/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B/%D0%BF%D0%BE%D1%88%D0%B5%D0%BB",
  135. correctHref: "#/шеллы/пошел"
  136. })
  137. })
  138. describe("Operation with no operationId", () => {
  139. OperationDeeplinkTestFactory({
  140. baseUrl: openAPI3BaseUrl,
  141. elementToGet: ".opblock-put",
  142. correctElementId: "operations-tagTwo-put_noOperationId",
  143. correctFragment: "#/tagTwo/put_noOperationId",
  144. correctHref: "#/tagTwo/put_noOperationId"
  145. })
  146. })
  147. describe("regular Tag", () => {
  148. TagDeeplinkTestFactory({
  149. isTagCase: true,
  150. baseUrl: openAPI3BaseUrl,
  151. elementToGet: `.opblock-tag[data-tag="myTag"][data-is-open="true"]`,
  152. correctElementId: "operations-tag-myTag",
  153. correctFragment: "#/myTag",
  154. correctHref: "#/myTag"
  155. })
  156. })
  157. describe("Tag with whitespace", () => {
  158. TagDeeplinkTestFactory({
  159. isTagCase: true,
  160. baseUrl: openAPI3BaseUrl,
  161. elementToGet: `.opblock-tag[data-tag="my Tag"][data-is-open="true"]`,
  162. correctElementId: "operations-tag-my_Tag",
  163. correctFragment: "#/my%20Tag",
  164. correctHref: "#/my%20Tag"
  165. })
  166. })
  167. })
  168. })
  169. function OperationDeeplinkTestFactory({ baseUrl, elementToGet, correctElementId, correctFragment, correctHref }) {
  170. it("should generate a correct element ID", () => {
  171. cy.visit(baseUrl)
  172. .get(elementToGet)
  173. .should("have.id", correctElementId)
  174. })
  175. it("should add the correct element fragment to the URL when expanded", () => {
  176. cy.visit(baseUrl)
  177. .get(elementToGet)
  178. .click()
  179. cy.location().should((loc) => {
  180. expect(loc.hash).to.eq(correctFragment)
  181. })
  182. })
  183. it("should provide an anchor link that has the correct fragment as href", () => {
  184. cy.visit(baseUrl)
  185. .get(elementToGet)
  186. .find("a")
  187. .should("have.attr", "href", correctHref)
  188. .click()
  189. cy.location().should((loc) => {
  190. expect(loc.hash).to.eq(correctFragment)
  191. })
  192. })
  193. it("should expand the operation when reloaded", () => {
  194. cy.visit(`${baseUrl}${correctFragment}`)
  195. .get(`${elementToGet}.is-open`)
  196. .should("exist")
  197. })
  198. it("should retain the correct fragment when reloaded", () => {
  199. cy.visit(`${baseUrl}${correctFragment}`)
  200. .reload()
  201. .should("exist")
  202. cy.location().should((loc) => {
  203. expect(loc.hash).to.eq(correctFragment)
  204. })
  205. })
  206. it("should expand a tag with docExpansion disabled", () => {
  207. cy.visit(`${baseUrl}&docExpansion=none${correctFragment}`)
  208. .get(`.opblock-tag-section.is-open`)
  209. .should("have.length", 1)
  210. })
  211. it("should expand an operation with docExpansion disabled", () => {
  212. cy.visit(`${baseUrl}&docExpansion=none${correctFragment}`)
  213. .get(`.opblock.is-open`)
  214. .should("have.length", 1)
  215. })
  216. }
  217. function TagDeeplinkTestFactory({ baseUrl, elementToGet, correctElementId, correctFragment, correctHref, isTagCase = false }) {
  218. it("should generate a correct element ID", () => {
  219. cy.visit(baseUrl)
  220. .get(elementToGet)
  221. .should("have.id", correctElementId)
  222. })
  223. it("should add the correct element fragment to the URL when expanded", () => {
  224. cy.visit(baseUrl)
  225. .get(elementToGet)
  226. .click()
  227. .click() // tags need two clicks because they're expanded by default
  228. cy.location().should((loc) => {
  229. expect(loc.hash).to.eq(correctFragment)
  230. })
  231. })
  232. it("should provide an anchor link that has the correct fragment as href", () => {
  233. cy.visit(baseUrl)
  234. .get(elementToGet)
  235. .find("a")
  236. .should("have.attr", "href", correctHref)
  237. })
  238. it("should expand the tag when reloaded", () => {
  239. cy.visit(`${baseUrl}${correctFragment}`)
  240. .get(`${elementToGet}[data-is-open="true"]`)
  241. .should("exist")
  242. })
  243. it("should retain the correct fragment when reloaded", () => {
  244. cy.visit(`${baseUrl}${correctFragment}`)
  245. .reload()
  246. .should("exist")
  247. cy.location().should((loc) => {
  248. expect(loc.hash).to.eq(correctFragment)
  249. })
  250. })
  251. it("should expand a tag with docExpansion disabled", () => {
  252. cy.visit(`${baseUrl}&docExpansion=none${correctFragment}`)
  253. .get(`.opblock-tag-section.is-open`)
  254. .should("have.length", 1)
  255. })
  256. }