MainDetails.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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, { act } from "react";
  15. import { render } from "@testing-library/react";
  16. import {
  17. OPENSTACK_ENDPOINT_MOCK,
  18. VMWARE_ENDPOINT_MOCK,
  19. } from "@tests/mocks/EndpointsMock";
  20. import { INSTANCE_MOCK } from "@tests/mocks/InstancesMock";
  21. import { MINION_POOL_MOCK } from "@tests/mocks/MinionPoolMock";
  22. import { STORAGE_BACKEND_MOCK } from "@tests/mocks/StoragesMock";
  23. import { TRANSFER_MOCK } from "@tests/mocks/TransferMock";
  24. import TestUtils from "@tests/TestUtils";
  25. import MainDetails from "./";
  26. jest.mock("@src/components/modules/EndpointModule/EndpointLogos", () => ({
  27. __esModule: true,
  28. default: (props: any) => <div>{props.endpoint}</div>,
  29. }));
  30. jest.mock("react-router", () => ({ Link: "a" }));
  31. describe("MainDetails", () => {
  32. let defaultProps: MainDetails["props"];
  33. beforeEach(() => {
  34. defaultProps = {
  35. item: TRANSFER_MOCK,
  36. minionPools: [MINION_POOL_MOCK],
  37. storageBackends: [STORAGE_BACKEND_MOCK],
  38. destinationSchema: [],
  39. destinationSchemaLoading: false,
  40. sourceSchema: [],
  41. sourceSchemaLoading: false,
  42. instancesDetails: [INSTANCE_MOCK],
  43. instancesDetailsLoading: false,
  44. endpoints: [OPENSTACK_ENDPOINT_MOCK, VMWARE_ENDPOINT_MOCK],
  45. bottomControls: <div>Bottom controls</div>,
  46. loading: false,
  47. };
  48. });
  49. it("renders without crashing", () => {
  50. const { getByText } = render(<MainDetails {...defaultProps} />);
  51. expect(getByText(TRANSFER_MOCK.id)).toBeTruthy();
  52. expect(getByText("Bottom controls")).toBeTruthy();
  53. });
  54. it("renders missing endpoint", () => {
  55. const { getByText } = render(
  56. <MainDetails
  57. {...defaultProps}
  58. item={{ ...TRANSFER_MOCK, destination_endpoint_id: "missing" }}
  59. />
  60. );
  61. expect(getByText("Endpoint is missing")).toBeTruthy();
  62. });
  63. it("renders loading", () => {
  64. render(<MainDetails {...defaultProps} loading />);
  65. expect(TestUtils.select("MainDetails__Loading")).toBeTruthy();
  66. });
  67. it("renders allocating minions error", () => {
  68. render(
  69. <MainDetails
  70. {...defaultProps}
  71. item={{
  72. ...TRANSFER_MOCK,
  73. last_execution_status: "ERROR_ALLOCATING_MINIONS",
  74. }}
  75. />
  76. );
  77. expect(
  78. Array.from(document.querySelectorAll("*")).find(el =>
  79. el.textContent?.includes("error allocating minion machines")
  80. )
  81. ).toBeTruthy();
  82. });
  83. it("shows password", async () => {
  84. const { getByText } = render(<MainDetails {...defaultProps} />);
  85. const passwordEl = TestUtils.select("PasswordValue__Wrapper")!;
  86. expect(passwordEl).toBeTruthy();
  87. expect(passwordEl.textContent).toBe("•••••••••");
  88. await act(async () => {
  89. passwordEl.click();
  90. });
  91. expect(
  92. getByText(TRANSFER_MOCK.destination_environment.password)
  93. ).toBeTruthy();
  94. });
  95. });