WizardScripts.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 { fireEvent, render, screen } from "@testing-library/react";
  16. import { INSTANCE_MOCK } from "@tests/mocks/InstancesMock";
  17. import WizardScripts from "./";
  18. describe("WizardScripts", () => {
  19. let defaultProps: WizardScripts["props"];
  20. beforeEach(() => {
  21. defaultProps = {
  22. instances: [INSTANCE_MOCK],
  23. uploadedScripts: [],
  24. removedScripts: [],
  25. userScriptData: null,
  26. onScriptsChange: jest.fn(),
  27. };
  28. });
  29. it("renders without crashing", () => {
  30. const { getByText, getAllByText } = render(
  31. <WizardScripts {...defaultProps} />,
  32. );
  33. expect(getByText(INSTANCE_MOCK.name)).toBeTruthy();
  34. expect(getAllByText("Choose Scripts").length).toBeGreaterThan(0);
  35. });
  36. it("offers 'Edit Scripts' for a configured target and 'Choose Scripts' otherwise", () => {
  37. const { getByText, getAllByText } = render(
  38. <WizardScripts
  39. {...defaultProps}
  40. userScriptData={{
  41. global: {
  42. linux: [
  43. { phase: "osmorphing_pre_os_mount", payload: "echo pre" },
  44. { phase: "replica_first_boot", payload: "echo boot" },
  45. ],
  46. },
  47. }}
  48. />,
  49. );
  50. expect(getByText("Edit Scripts")).toBeTruthy();
  51. expect(getAllByText("Choose Scripts").length).toBe(2);
  52. });
  53. it("opens the per-phase modal showing all three phases", () => {
  54. const { getAllByText } = render(<WizardScripts {...defaultProps} />);
  55. fireEvent.click(getAllByText("Choose Scripts")[0]);
  56. expect(screen.getByText("Windows Script File - User Scripts")).toBeTruthy();
  57. expect(screen.getByText("OS morphing: before mount")).toBeTruthy();
  58. expect(screen.getByText("OS morphing: after mount")).toBeTruthy();
  59. expect(screen.getByText("VM first boot script")).toBeTruthy();
  60. expect(screen.getAllByText("Choose File...").length).toBe(3);
  61. });
  62. });