ReplicaDetailsContent.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Copyright (C) 2023 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React from "react";
  15. import Schedule from "@src/components/modules/TransferModule/Schedule";
  16. import ScheduleStore from "@src/stores/ScheduleStore";
  17. import { render } from "@testing-library/react";
  18. import {
  19. OPENSTACK_ENDPOINT_MOCK,
  20. VMWARE_ENDPOINT_MOCK,
  21. } from "@tests/mocks/EndpointsMock";
  22. import {
  23. EXECUTION_MOCK,
  24. EXECUTION_TASKS_MOCK,
  25. } from "@tests/mocks/ExecutionsMock";
  26. import { INSTANCE_MOCK } from "@tests/mocks/InstancesMock";
  27. import { MINION_POOL_MOCK } from "@tests/mocks/MinionPoolMock";
  28. import { NETWORK_MOCK } from "@tests/mocks/NetworksMock";
  29. import { STORAGE_BACKEND_MOCK } from "@tests/mocks/StoragesMock";
  30. import { TRANSFER_ITEM_DETAILS_MOCK } from "@tests/mocks/TransferMock";
  31. import ReplicaDetailsContent from ".";
  32. const scheduleStoreMock = jest.createMockFromModule<typeof ScheduleStore>(
  33. "@src/stores/ScheduleStore"
  34. );
  35. jest.mock("@src/components/modules/EndpointModule/EndpointLogos", () => ({
  36. __esModule: true,
  37. default: (props: any) => <div>{props.endpoint}</div>,
  38. }));
  39. jest.mock("react-router-dom", () => ({ Link: "a" }));
  40. jest.mock("@src/utils/Config", () => ({
  41. config: {
  42. providerSortPriority: {},
  43. providerNames: {
  44. openstack: "OpenStack",
  45. vmware_vsphere: "VMware vSphere",
  46. },
  47. providersDisabledExecuteOptions: ["metal"],
  48. },
  49. }));
  50. jest.mock("@src/components/modules/TransferModule/Schedule", () => ({
  51. __esModule: true,
  52. default: (props: Schedule["props"]) => (
  53. <div
  54. data-testid="ScheduleComponent"
  55. onClick={() => props.onTimezoneChange("utc")}
  56. >
  57. Timezone: {props.timezone}
  58. </div>
  59. ),
  60. }));
  61. describe("ReplicaDetailsContent", () => {
  62. let defaultProps: ReplicaDetailsContent["props"];
  63. beforeEach(() => {
  64. defaultProps = {
  65. item: TRANSFER_ITEM_DETAILS_MOCK,
  66. itemId: TRANSFER_ITEM_DETAILS_MOCK.id,
  67. endpoints: [OPENSTACK_ENDPOINT_MOCK, VMWARE_ENDPOINT_MOCK],
  68. sourceSchema: [],
  69. sourceSchemaLoading: false,
  70. destinationSchema: [],
  71. destinationSchemaLoading: false,
  72. networks: [NETWORK_MOCK],
  73. instancesDetails: [INSTANCE_MOCK],
  74. instancesDetailsLoading: false,
  75. scheduleStore: scheduleStoreMock,
  76. page: "",
  77. detailsLoading: false,
  78. executions: [EXECUTION_MOCK],
  79. executionsLoading: false,
  80. executionsTasks: [EXECUTION_TASKS_MOCK],
  81. executionsTasksLoading: false,
  82. minionPools: [MINION_POOL_MOCK],
  83. storageBackends: [STORAGE_BACKEND_MOCK],
  84. onExecutionChange: jest.fn(),
  85. onCancelExecutionClick: jest.fn(),
  86. onDeleteExecutionClick: jest.fn(),
  87. onExecuteClick: jest.fn(),
  88. onCreateDeploymentClick: jest.fn(),
  89. onDeleteTransferClick: jest.fn(),
  90. onAddScheduleClick: jest.fn(),
  91. onScheduleChange: jest.fn(),
  92. onScheduleRemove: jest.fn(),
  93. onScheduleSave: jest.fn(),
  94. };
  95. });
  96. it("renders without crashing", () => {
  97. const { getByText } = render(<ReplicaDetailsContent {...defaultProps} />);
  98. expect(getByText(TRANSFER_ITEM_DETAILS_MOCK.id)).toBeTruthy();
  99. });
  100. it("renders executions page", () => {
  101. const { getByText } = render(
  102. <ReplicaDetailsContent {...defaultProps} page="executions" />
  103. );
  104. expect(getByText(EXECUTION_MOCK.id)).toBeTruthy();
  105. });
  106. it("rendes schedules page", () => {
  107. const { getByTestId } = render(
  108. <ReplicaDetailsContent {...defaultProps} page="schedule" />
  109. );
  110. expect(getByTestId("ScheduleComponent")).toBeTruthy();
  111. });
  112. it("fires timezone change", () => {
  113. const { getByTestId, getByText } = render(
  114. <ReplicaDetailsContent {...defaultProps} page="schedule" />
  115. );
  116. expect(getByText("Timezone: local")).toBeTruthy();
  117. getByTestId("ScheduleComponent").click();
  118. expect(getByText("Timezone: utc")).toBeTruthy();
  119. });
  120. });