MinionPoolDetailsContent.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 { render } from "@testing-library/react";
  16. import { OPENSTACK_ENDPOINT_MOCK } from "@tests/mocks/EndpointsMock";
  17. import { MINION_POOL_DETAILS_MOCK } from "@tests/mocks/MinionPoolMock";
  18. import { REPLICA_MOCK } from "@tests/mocks/TransferMock";
  19. import TestUtils from "@tests/TestUtils";
  20. import MinionPoolDetailsContent from "./MinionPoolDetailsContent";
  21. jest.mock("react-router-dom", () => ({ Link: "a" }));
  22. jest.mock("@src/components/modules/EndpointModule/EndpointLogos", () => ({
  23. __esModule: true,
  24. default: (props: any) => (
  25. <div data-testid="EndpointLogos">{props.endpoint}</div>
  26. ),
  27. }));
  28. jest.mock(
  29. "@src/components/modules/MinionModule/MinionPoolDetailsContent/MinionPoolEvents",
  30. () => ({
  31. __esModule: true,
  32. default: () => <div data-testid="MinionPoolEvents"></div>,
  33. })
  34. );
  35. describe("MinionPoolDetailsContent", () => {
  36. let defaultProps: MinionPoolDetailsContent["props"];
  37. beforeEach(() => {
  38. defaultProps = {
  39. item: MINION_POOL_DETAILS_MOCK,
  40. itemId: "minion-pool-id",
  41. replicas: [REPLICA_MOCK],
  42. migrations: [],
  43. endpoints: [OPENSTACK_ENDPOINT_MOCK],
  44. schema: [
  45. {
  46. name: "name",
  47. label: "Name",
  48. type: "text",
  49. required: true,
  50. disabled: false,
  51. },
  52. ],
  53. schemaLoading: false,
  54. loading: false,
  55. page: "",
  56. onAllocate: jest.fn(),
  57. onDeleteMinionPoolClick: jest.fn(),
  58. };
  59. });
  60. it("renders without crashing", () => {
  61. const { getByText } = render(
  62. <MinionPoolDetailsContent {...defaultProps} />
  63. );
  64. expect(getByText(MINION_POOL_DETAILS_MOCK.id)).toBeTruthy();
  65. expect(getByText(MINION_POOL_DETAILS_MOCK.notes!)).toBeTruthy();
  66. });
  67. it("calls allocate callback", () => {
  68. const { getByText } = render(
  69. <MinionPoolDetailsContent
  70. {...defaultProps}
  71. item={{ ...MINION_POOL_DETAILS_MOCK, status: "DEALLOCATED" }}
  72. />
  73. );
  74. getByText("Allocate").click();
  75. expect(defaultProps.onAllocate).toHaveBeenCalled();
  76. });
  77. it("renders loading", () => {
  78. render(<MinionPoolDetailsContent {...defaultProps} loading />);
  79. expect(TestUtils.select("MinionPoolDetailsContent__Loading")).toBeTruthy();
  80. });
  81. it("renders machines page", () => {
  82. render(<MinionPoolDetailsContent {...defaultProps} page="machines" />);
  83. expect(TestUtils.select("MinionPoolMachines")).toBeTruthy();
  84. });
  85. it("renders events page", () => {
  86. const { getByTestId } = render(
  87. <MinionPoolDetailsContent {...defaultProps} page="events" />
  88. );
  89. expect(getByTestId("MinionPoolEvents")).toBeTruthy();
  90. });
  91. });