dashboard.cy.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /// <reference types="cypress" />
  2. import { DateTime } from "luxon";
  3. import { routeSelectors } from "../../support/routeSelectors";
  4. describe("Dashboard", () => {
  5. beforeEach(() => {
  6. cy.setProjectIdCookie();
  7. cy.mockAuth();
  8. cy.intercept(routeSelectors.APPLIANCES, {
  9. fixture: "licences/appliances.json",
  10. }).as("appliances");
  11. cy.intercept(routeSelectors.STATUS, {
  12. fixture: "licences/status.json",
  13. }).as("status");
  14. cy.intercept(routeSelectors.APPLIANCE_STATUS, {
  15. fixture: "licences/appliance-status.json",
  16. }).as("appliance-status");
  17. });
  18. const waitForAll = () => {
  19. cy.waitMockAuth();
  20. cy.wait(["@appliances", "@status", "@appliance-status"]);
  21. };
  22. it("renders empty dashboard", () => {
  23. cy.intercept(routeSelectors.TRANSFERS, {
  24. body: { transfers: [] },
  25. }).as("transfers");
  26. cy.intercept(routeSelectors.DEPLOYMENTS, {
  27. body: { deployments: [] },
  28. }).as("deployments");
  29. cy.intercept(routeSelectors.ENDPOINTS, {
  30. body: { endpoints: [] },
  31. }).as("endpoints");
  32. cy.visit("/");
  33. waitForAll();
  34. cy.wait(["@transfers", "@deployments", "@endpoints"]);
  35. cy.get("*[class^='DashboardActivity__Message']").should(
  36. "contain.text",
  37. "There is no recent activity",
  38. );
  39. cy.fixture("licences/appliance-status.json").then(applianceStatus => {
  40. cy.get("*[class^='DashboardLicence__TopInfoDateTop']").should(
  41. "contain.text",
  42. `${DateTime.fromISO(
  43. applianceStatus.appliance_licence_status.earliest_licence_expiry_time,
  44. )
  45. .toFormat("LLL |yy")
  46. .replace("|", "'")}`,
  47. );
  48. cy.get("*[class^='DashboardLicence__ChartHeaderCurrent']").should(
  49. "contain.text",
  50. `${applianceStatus.appliance_licence_status.current_performed_replicas} Used Replica ${applianceStatus.appliance_licence_status.current_performed_migrations} Used Migrations`,
  51. );
  52. });
  53. cy.get("button").should("contain.text", "New Transfer");
  54. cy.get("button").should("contain.text", "New Endpoint");
  55. });
  56. it("renders dashboard with data", () => {
  57. cy.intercept(routeSelectors.TRANSFERS, {
  58. fixture: "transfers/replicas.json",
  59. }).as("transfers");
  60. cy.intercept(routeSelectors.ENDPOINTS, {
  61. fixture: "endpoints/endpoints.json",
  62. }).as("endpoints");
  63. cy.visit("/");
  64. waitForAll();
  65. cy.wait(["@transfers", "@endpoints"]);
  66. cy.loadFixtures(
  67. ["transfers/replicas.json", "endpoints/endpoints.json"],
  68. results => {
  69. const [transfersFixture, endpointsFixture] = results;
  70. const replicasCount = transfersFixture.transfers.filter(
  71. transfer => transfer.scenario === "replica",
  72. ).length;
  73. const migrationsCount = transfersFixture.transfers.filter(
  74. transfer => transfer.scenario === "live_migration",
  75. ).length;
  76. cy.get("div[class^='DashboardInfoCount__CountBlock']").should(
  77. "contain.text",
  78. `${replicasCount}Replicas${migrationsCount}Migrations${endpointsFixture.endpoints.length}Endpoints`,
  79. );
  80. const checkItem = (type: "transfer", item: any) => {
  81. cy.get("div[class^='NotificationDropdown__ItemDescription']").should(
  82. "contain.text",
  83. `New ${type} ${item.id.substr(
  84. 0,
  85. 7,
  86. )}... status: ${item.last_execution_status.toLowerCase()}`,
  87. );
  88. };
  89. transfersFixture.transfers.forEach((transfer: any) => {
  90. checkItem("transfer", transfer);
  91. });
  92. },
  93. );
  94. });
  95. });