dashboard.cy.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.REPLICAS, {
  24. body: { replicas: [] },
  25. }).as("replicas");
  26. cy.intercept(routeSelectors.MIGRATIONS, {
  27. body: { migrations: [] },
  28. }).as("migrations");
  29. cy.intercept(routeSelectors.ENDPOINTS, {
  30. body: { endpoints: [] },
  31. }).as("endpoints");
  32. cy.visit("/");
  33. waitForAll();
  34. cy.wait(["@replicas", "@migrations", "@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 Replica / Migration");
  54. cy.get("button").should("contain.text", "New Endpoint");
  55. });
  56. it("renders dashboard with data", () => {
  57. cy.intercept(routeSelectors.REPLICAS, {
  58. fixture: "transfers/replicas.json",
  59. }).as("replicas");
  60. cy.intercept(routeSelectors.MIGRATIONS, {
  61. fixture: "transfers/migrations.json",
  62. }).as("migrations");
  63. cy.intercept(routeSelectors.ENDPOINTS, {
  64. fixture: "endpoints/endpoints.json",
  65. }).as("endpoints");
  66. cy.visit("/");
  67. waitForAll();
  68. cy.wait(["@replicas", "@migrations", "@endpoints"]);
  69. cy.loadFixtures(
  70. [
  71. "transfers/replicas.json",
  72. "transfers/migrations.json",
  73. "endpoints/endpoints.json",
  74. ],
  75. results => {
  76. const [replicasFixture, migrationsFixture, endpointsFixture] = results;
  77. cy.get("div[class^='DashboardInfoCount__CountBlock']").should(
  78. "contain.text",
  79. `${replicasFixture.replicas.length}Replicas${migrationsFixture.migrations.length}Migrations${endpointsFixture.endpoints.length}Endpoints`
  80. );
  81. const checkItem = (type: "migration" | "replica", item: any) => {
  82. cy.get("div[class^='NotificationDropdown__ItemDescription']").should(
  83. "contain.text",
  84. `New ${type} ${item.id.substr(
  85. 0,
  86. 7
  87. )}... status: ${item.last_execution_status.toLowerCase()}`
  88. );
  89. };
  90. migrationsFixture.migrations.forEach((migration: any) => {
  91. checkItem("migration", migration);
  92. });
  93. replicasFixture.replicas.forEach((replica: any) => {
  94. checkItem("replica", replica);
  95. });
  96. }
  97. );
  98. });
  99. });