endpoints-list.cy.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /// <reference types="cypress" />
  2. import { routeSelectors } from "../../support/routeSelectors";
  3. describe("Endpoints list", () => {
  4. beforeEach(() => {
  5. cy.setProjectIdCookie();
  6. cy.mockAuth({ filterResources: ["users"] });
  7. cy.intercept(routeSelectors.ENDPOINTS, {
  8. fixture: "endpoints/endpoints",
  9. }).as("endpoints");
  10. });
  11. const waitForAll = () => {
  12. cy.waitMockAuth({ filterResources: ["users"] });
  13. cy.wait(["@endpoints"]);
  14. };
  15. it("renders empty list", () => {
  16. cy.intercept(routeSelectors.ENDPOINTS, {
  17. body: { endpoints: [] },
  18. }).as("endpoints-empty");
  19. cy.visit("/endpoints");
  20. cy.wait(["@endpoints-empty"]);
  21. cy.waitMockAuth({ filterResources: ["users"] });
  22. cy.get("div[class^='MainList__EmptyListMessage']").should(
  23. "contain.text",
  24. "don't have any Cloud Endpoints in this project",
  25. );
  26. cy.get("button").should("contain.text", "Add Endpoint");
  27. });
  28. it("filters list", () => {
  29. cy.visit("/endpoints");
  30. waitForAll();
  31. cy.fixture("endpoints/endpoints").then((endpointsFixture: any) => {
  32. const endpoints = endpointsFixture.endpoints;
  33. const ITEMS_PER_PAGE = 10;
  34. cy.get("div[class^='MainListFilter__FilterItem']")
  35. .contains("Azure")
  36. .click();
  37. const azureEndpoints = endpoints.filter(r => r.type === "azure");
  38. cy.get("div[class^='EndpointListItem__Wrapper']").should(
  39. "have.length",
  40. Math.min(azureEndpoints.length, ITEMS_PER_PAGE),
  41. );
  42. cy.get("div[class^='MainListFilter__FilterItem']")
  43. .contains("VMware")
  44. .click();
  45. const vmwareEndpoints = endpoints.filter(
  46. r => r.type === "vmware_vsphere",
  47. );
  48. cy.get("div[class^='EndpointListItem__Wrapper']").should(
  49. "have.length",
  50. Math.min(vmwareEndpoints.length, ITEMS_PER_PAGE),
  51. );
  52. cy.get("div[class^='SearchButton__Wrapper']").click();
  53. cy.get("input[class*='SearchInput']").type("cor");
  54. const vmwareCorEndpoints = endpoints.filter(
  55. e => e.type === "vmware_vsphere" && e.name.includes("cor"),
  56. );
  57. cy.get("div[class^='EndpointListItem__Wrapper']").should(
  58. "have.length",
  59. Math.min(vmwareCorEndpoints.length, ITEMS_PER_PAGE),
  60. );
  61. cy.get("div[class^='TextInput__Close']").click();
  62. cy.get("input[class*='SearchInput']").should("have.value", "");
  63. cy.get("div[class^='MainListFilter__FilterItem']")
  64. .contains("All")
  65. .click();
  66. cy.get("div[class^='EndpointListItem__Wrapper']").should(
  67. "have.length",
  68. Math.min(endpoints.length, ITEMS_PER_PAGE),
  69. );
  70. cy.get("div[class^='SearchButton__Wrapper']").click();
  71. cy.get("input[class*='SearchInput']").type("cor");
  72. cy.get("input[class*='SearchInput']").should("have.value", "cor");
  73. const corEndpoints = endpoints.filter(e => e.name.includes("cor"));
  74. cy.get("div[class^='EndpointListItem__Wrapper']").should(
  75. "have.length",
  76. Math.min(corEndpoints.length, ITEMS_PER_PAGE),
  77. );
  78. });
  79. });
  80. it("does bulk actions", () => {
  81. cy.visit("/endpoints");
  82. waitForAll();
  83. cy.get("div[class^='SearchButton__Wrapper']").click();
  84. cy.get("input[class*='SearchInput']").type("cor");
  85. cy.get(
  86. "div[class^='MainListFilter__Wrapper'] div[class^='Checkbox__Wrapper']",
  87. ).click();
  88. cy.fixture("endpoints/endpoints").then((endpointsFixture: any) => {
  89. const endpoints = endpointsFixture.endpoints;
  90. const corEndpoints = endpoints.filter(e => e.name.includes("cor"));
  91. cy.get("div[class^='MainListFilter__SelectionText']").should(
  92. "contain.text",
  93. `${corEndpoints.length} of ${corEndpoints.length}`,
  94. );
  95. cy.get("div[class^='ActionDropdown__Wrapper']").click();
  96. cy.get("div[class^='ActionDropdown__ListItem']")
  97. .contains("Delete")
  98. .click();
  99. cy.get("div[class^='AlertModal__Message']").should(
  100. "contain.text",
  101. "they are in use by replicas or migrations",
  102. );
  103. });
  104. });
  105. });