schema-form-enum-boolean.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @prettier
  3. */
  4. describe("JSON Schema Form: Enum & Boolean in a Parameter", () => {
  5. beforeEach(() => {
  6. cy.visit(
  7. "/?url=/documents/features/schema-form-enum-boolean.yaml"
  8. )
  9. .get("#operations-pet-findPetsByStatus")
  10. .click()
  11. // Expand Try It Out
  12. .get(".try-out__btn")
  13. .click()
  14. // @alias Execute Button
  15. cy.get(".execute.opblock-control__btn").as("executeBtn")
  16. // @alias Parameters
  17. cy.get(".opblock-section tbody > tr > .parameters-col_description > select")
  18. .eq(0)
  19. .as("enumIsRequired")
  20. cy.get(".opblock-section tbody > tr > .parameters-col_description > select")
  21. .eq(1)
  22. .as("booleanIsOptional")
  23. cy.get(".opblock-section tbody > tr > .parameters-col_description > select")
  24. .eq(2)
  25. .as("booleanIsRequired")
  26. })
  27. it("should render @enumIsRequired with list of three options", () => {
  28. cy.get("@enumIsRequired")
  29. .should("contains.text", "available")
  30. .should("contains.text", "pending")
  31. .should("contains.text", "sold")
  32. .should("not.contains.text", "--")
  33. .find("option")
  34. .should("have.length", 3)
  35. })
  36. it("should render @booleanIsOptional with default empty string value (display '--')", () => {
  37. cy.get("@booleanIsOptional")
  38. .should("have.value", "")
  39. .should("contains.text", "--")
  40. })
  41. it("should render @booleanIsRequired with default empty string value (display '--')", () => {
  42. cy.get("@booleanIsRequired")
  43. .should("have.value", "")
  44. .should("contains.text", "--")
  45. })
  46. it("should NOT be able to execute with empty @enumIsRequired and @booleanIsRequired values", () => {
  47. // Execute
  48. cy.get("@executeBtn")
  49. .click()
  50. cy.get("@enumIsRequired")
  51. .should("have.class", "invalid")
  52. cy.get("@booleanIsRequired")
  53. .should("have.class", "invalid")
  54. // cURL component
  55. cy.get(".responses-wrapper .curl-command")
  56. .should("not.exist")
  57. })
  58. it("should NOT be able to execute with empty @booleanIsRequired value, but valid @enumIsRequired", () => {
  59. cy.get("@enumIsRequired")
  60. .select("pending")
  61. // Execute
  62. cy.get("@executeBtn")
  63. .click()
  64. cy.get("@enumIsRequired")
  65. .should("not.have.class", "invalid")
  66. cy.get("@booleanIsRequired")
  67. .should("have.class", "invalid")
  68. // cURL component
  69. cy.get(".responses-wrapper .curl-command")
  70. .should("not.exist")
  71. })
  72. it("should NOT be able to execute with empty @enumIsRequired value, but valid @booleanIsRequired", () => {
  73. cy.get("@booleanIsRequired")
  74. .select("false")
  75. // Execute
  76. cy.get("@executeBtn")
  77. .click()
  78. cy.get("@enumIsRequired")
  79. .should("have.class", "invalid")
  80. cy.get("@booleanIsRequired")
  81. .should("not.have.class", "invalid")
  82. // cURL component
  83. cy.get(".responses-wrapper .curl-command")
  84. .should("not.exist")
  85. })
  86. it("should execute, if @booleanIsOptional value is 'false'", () => {
  87. cy.get("@enumIsRequired")
  88. .select("pending")
  89. cy.get("@booleanIsRequired")
  90. .select("false")
  91. cy.get("@booleanIsOptional")
  92. .select("false")
  93. // Execute
  94. cy.get("@executeBtn")
  95. .click()
  96. cy.get("@enumIsRequired")
  97. .should("not.have.class", "invalid")
  98. cy.get("@booleanIsRequired")
  99. .should("not.have.class", "invalid")
  100. .should("not.contains.text", "expectIsOptional")
  101. // cURL component
  102. cy.get(".responses-wrapper .curl-command")
  103. .should("exist")
  104. .get(".responses-wrapper .curl-command span")
  105. .should("contains.text", "expectIsOptional=false")
  106. })
  107. it("should execute, but NOT send @booleanIsOptional value if not provided", () => {
  108. cy.get("@enumIsRequired")
  109. .select("pending")
  110. cy.get("@booleanIsRequired")
  111. .select("false")
  112. // Execute
  113. cy.get("@executeBtn")
  114. .click()
  115. cy.get("@enumIsRequired")
  116. .should("not.have.class", "invalid")
  117. cy.get("@booleanIsRequired")
  118. .should("not.have.class", "invalid")
  119. .should("not.contains.text", "expectIsOptional")
  120. // cURL component
  121. cy.get(".responses-wrapper .curl-command")
  122. .should("exist")
  123. .get(".responses-wrapper .curl-command span")
  124. .should("not.contains.text", "expectIsOptional")
  125. })
  126. })