new-endpoint.cy.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /// <reference types="cypress" />
  2. import { routeSelectors } from "../../support/routeSelectors";
  3. const clickOpenstack = () => {
  4. cy.intercept(routeSelectors.CONN_SCHEMA_OPENSTACK, {
  5. fixture: "endpoints/openstack-connection-schema",
  6. }).as("openstack-schema");
  7. let matchFound = false;
  8. return cy
  9. .get("div[class^=EndpointLogos__Logo]")
  10. .each(logo => {
  11. const style = window.getComputedStyle(logo[0]);
  12. const matches = style.backgroundImage.match(/\/api\/logos\/(.*?)\//);
  13. if (matches?.[1] === "openstack") {
  14. matchFound = true;
  15. cy.wrap(logo).click();
  16. cy.wait("@openstack-schema");
  17. }
  18. })
  19. .then(() => {
  20. if (!matchFound) {
  21. throw new Error("Openstack logo not found");
  22. }
  23. });
  24. };
  25. describe("New endpoint", () => {
  26. beforeEach(() => {
  27. cy.setProjectIdCookie();
  28. cy.mockAuth({ filterResources: ["users"] });
  29. cy.intercept(routeSelectors.ENDPOINTS, {
  30. body: { endpoints: [] },
  31. }).as("endpoints");
  32. cy.intercept(routeSelectors.PROVIDERS, {
  33. fixture: "endpoints/providers",
  34. }).as("providers");
  35. cy.intercept(routeSelectors.REGIONS, {
  36. fixture: "endpoints/regions",
  37. }).as("regions");
  38. cy.visit("/endpoints");
  39. waitForAll();
  40. cy.get("button").contains("Add Endpoint").click();
  41. cy.wait(["@providers", "@regions"]);
  42. });
  43. const waitForAll = () => {
  44. cy.waitMockAuth({ filterResources: ["users"] });
  45. cy.wait(["@endpoints"]);
  46. };
  47. it("shows all providers", () => {
  48. cy.get("div[class^=Modal__Title]").should(
  49. "contain.text",
  50. "New Cloud Endpoint",
  51. );
  52. cy.fixture("endpoints/providers").then(providersFixture => {
  53. const providers = providersFixture.providers;
  54. cy.get("div[class^=EndpointLogos__Logo]").should(
  55. "have.length",
  56. Object.keys(providers).length,
  57. );
  58. cy.get("div[class^=EndpointLogos__Logo]").each(logo => {
  59. const style = window.getComputedStyle(logo[0]);
  60. const matches = style.backgroundImage.match(/\/api\/logos\/(.*?)\//);
  61. expect(Object.keys(providers)).to.include(matches?.[1]);
  62. });
  63. });
  64. });
  65. it("validates the form for a new openstack endpoint", () => {
  66. clickOpenstack().then(() => {
  67. cy.get("input[placeholder='Password']").should(
  68. "have.attr",
  69. "type",
  70. "password",
  71. );
  72. cy.get("div[class^=FieldInput__Wrapper]")
  73. .contains("Username")
  74. .not("div[class^=FieldInput__HighlightLabel]");
  75. cy.get("button").contains("Validate and save").click();
  76. cy.get("div[class^=notifications-wrapper]").should(
  77. "contain.text",
  78. "Please fill all the required fields",
  79. );
  80. cy.get("div[class^=FieldInput__Wrapper]")
  81. .contains("Username")
  82. .get("div[class^=FieldInput__HighlightLabel]")
  83. .should("exist");
  84. cy.get("input[placeholder='Username']").type("username");
  85. cy.get("button").contains("Validate and save").click();
  86. cy.get("div[class^=FieldInput__Wrapper]")
  87. .contains("Username")
  88. .not("div[class^=FieldInput__HighlightLabel]");
  89. });
  90. });
  91. it("toggles simple and advanced mode", () => {
  92. clickOpenstack().then(() => {
  93. cy.get("div[class^=FieldInput__Wrapper]")
  94. .contains("Allow Untrusted")
  95. .should("not.exist");
  96. cy.get("div[class^=ToggleButtonBar__Item]").contains("Advanced").click();
  97. cy.get("div[class^=FieldInput__Wrapper]")
  98. .contains("Allow Untrusted")
  99. .should("exist");
  100. });
  101. });
  102. it("saves the endpoint", () => {
  103. clickOpenstack().then(() => {
  104. cy.get("input[placeholder='Name']").type("new openstack");
  105. cy.get("input[placeholder='Username']").type("username");
  106. cy.get("input[placeholder='Password']").type("password");
  107. cy.get("input[placeholder='Authentication URL']").type("auth url");
  108. cy.get("input[placeholder='Project Name']").type("project name");
  109. cy.intercept("POST", routeSelectors.SECRETS, req => {
  110. expect(req.body).to.have.property("algorithm", "aes");
  111. expect(req.body).to.have.property("payload");
  112. expect(JSON.parse(req.body.payload)).to.have.property(
  113. "auth_url",
  114. "auth url",
  115. );
  116. req.reply({ fixture: "endpoints/secret-ref" });
  117. }).as("secrets-post");
  118. cy.intercept("POST", routeSelectors.ENDPOINTS, req => {
  119. expect(req.body).to.have.property("endpoint");
  120. expect(req.body.endpoint).to.have.property("name", "new openstack");
  121. expect(req.body.endpoint).to.have.property("type", "openstack");
  122. expect(req.body.endpoint).to.have.property("connection_info");
  123. expect(req.body.endpoint.connection_info).to.have.property(
  124. "secret_ref",
  125. "http://127.0.0.1:9311/v1/secrets/secret-ref-1",
  126. );
  127. req.reply({ fixture: "endpoints/endpoint" });
  128. }).as("endpoints-post");
  129. cy.intercept(`${routeSelectors.SECRETS}/secret-ref-1`, {
  130. body: { status: "ACTIVE" },
  131. }).as("secrets-active");
  132. cy.intercept(`${routeSelectors.SECRETS}/secret-ref-1/payload`, {
  133. body: { username: "username", password: "password" },
  134. }).as("secrets-payload");
  135. cy.intercept("POST", `${routeSelectors.ENDPOINTS}/**/actions`, {
  136. fixture: "endpoints/validation-fail",
  137. }).as("endpoints-validate");
  138. cy.get("button").contains("Validate and save").click();
  139. cy.wait([
  140. "@secrets-post",
  141. "@endpoints-post",
  142. "@secrets-active",
  143. "@secrets-payload",
  144. "@endpoints-validate",
  145. ]);
  146. });
  147. });
  148. it("fails validation", () => {
  149. clickOpenstack().then(() => {
  150. cy.get("input[placeholder='Name']").type("new openstack");
  151. cy.get("input[placeholder='Username']").type("username");
  152. cy.get("input[placeholder='Password']").type("password");
  153. cy.get("input[placeholder='Authentication URL']").type("auth url");
  154. cy.get("input[placeholder='Project Name']").type("project name");
  155. cy.intercept("POST", routeSelectors.SECRETS, {
  156. fixture: "endpoints/secret-ref",
  157. }).as("secrets-post");
  158. cy.intercept("POST", routeSelectors.ENDPOINTS, {
  159. fixture: "endpoints/endpoint",
  160. }).as("endpoints-post");
  161. cy.intercept(`${routeSelectors.SECRETS}/secret-ref-1`, {
  162. body: { status: "ACTIVE" },
  163. }).as("secrets-active");
  164. cy.intercept(`${routeSelectors.SECRETS}/secret-ref-1/payload`, {
  165. body: { username: "username", password: "password" },
  166. }).as("secrets-payload");
  167. cy.intercept("POST", `${routeSelectors.ENDPOINTS}/**/actions`, {
  168. fixture: "endpoints/validation-fail",
  169. }).as("endpoints-validate");
  170. cy.get("button").contains("Validate and save").click();
  171. cy.wait([
  172. "@secrets-post",
  173. "@endpoints-post",
  174. "@secrets-active",
  175. "@secrets-payload",
  176. "@endpoints-validate",
  177. ]);
  178. cy.get("div[class^=EndpointModal__StatusMessage]").should(
  179. "contain.text",
  180. "Validation failed",
  181. );
  182. cy.get("span[class^=EndpointModal__ShowErrorButton]").click();
  183. cy.fixture("endpoints/validation-fail").then(validationFailFixture => {
  184. cy.get("div[class^=EndpointModal__StatusError]").should(
  185. "contain.text",
  186. validationFailFixture["validate-connection"].message,
  187. );
  188. });
  189. });
  190. });
  191. it("validates successfully", () => {
  192. clickOpenstack().then(() => {
  193. cy.get("input[placeholder='Name']").type("new openstack");
  194. cy.get("input[placeholder='Username']").type("username");
  195. cy.get("input[placeholder='Password']").type("password");
  196. cy.get("input[placeholder='Authentication URL']").type("auth url");
  197. cy.get("input[placeholder='Project Name']").type("project name");
  198. cy.intercept("POST", routeSelectors.SECRETS, {
  199. fixture: "endpoints/secret-ref",
  200. }).as("secrets-post");
  201. cy.intercept("POST", routeSelectors.ENDPOINTS, {
  202. fixture: "endpoints/endpoint",
  203. }).as("endpoints-post");
  204. cy.intercept(`${routeSelectors.SECRETS}/secret-ref-1`, {
  205. body: { status: "ACTIVE" },
  206. }).as("secrets-active");
  207. cy.intercept(`${routeSelectors.SECRETS}/secret-ref-1/payload`, {
  208. body: { username: "username", password: "password" },
  209. }).as("secrets-payload");
  210. cy.intercept("POST", `${routeSelectors.ENDPOINTS}/**/actions`, req => {
  211. expect(req.body).to.have.property("validate-connection", null);
  212. req.reply({ fixture: "endpoints/validation-success" });
  213. }).as("endpoints-validate");
  214. cy.get("button").contains("Validate and save").click();
  215. cy.wait([
  216. "@secrets-post",
  217. "@endpoints-post",
  218. "@secrets-active",
  219. "@secrets-payload",
  220. "@endpoints-validate",
  221. ]);
  222. cy.get("div[class^=EndpointModal__StatusMessage]").should(
  223. "contain.text",
  224. "Endpoint is Valid",
  225. );
  226. });
  227. });
  228. });