test.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright (C) 2017 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 { shallow } from "enzyme";
  16. import sinon from "sinon";
  17. import TW from "@src/utils/TestWrapper";
  18. import type { Project } from "@src/@types/Project";
  19. import EndpointDuplicateOptions from ".";
  20. type Props = {
  21. projects: Project[];
  22. selectedProjectId: string;
  23. duplicating: boolean;
  24. onCancelClick: () => void;
  25. onDuplicateClick: (projectId: string) => void;
  26. };
  27. const wrap = (props: Props) =>
  28. new TW(shallow(<EndpointDuplicateOptions {...props} />), "edOptions");
  29. const projects: Project[] = [
  30. { id: "project-1", name: "Project 1" },
  31. { id: "project-2", name: "Project 2" },
  32. ];
  33. describe("EndpointDuplicateOptions Component", () => {
  34. it("renders projects", () => {
  35. const wrapper = wrap({
  36. projects,
  37. selectedProjectId: "project-2",
  38. duplicating: false,
  39. onCancelClick: () => {},
  40. onDuplicateClick: () => {},
  41. });
  42. expect(wrapper.find("field-project").prop("enum")[1].name).toBe(
  43. projects[1].name
  44. );
  45. expect(wrapper.find("field-project").prop("value")).toBe("project-2");
  46. expect(wrapper.find("loading").length).toBe(0);
  47. });
  48. it("dispatches duplicate", () => {
  49. const onDuplicateClick = sinon.spy();
  50. const wrapper = wrap({
  51. projects,
  52. selectedProjectId: "project-2",
  53. duplicating: false,
  54. onCancelClick: () => {},
  55. onDuplicateClick,
  56. });
  57. wrapper.find("duplicateButton").click();
  58. expect(onDuplicateClick.args[0][0]).toBe("project-2");
  59. });
  60. it("renders loading", () => {
  61. const wrapper = wrap({
  62. projects,
  63. selectedProjectId: "project-2",
  64. duplicating: true,
  65. onCancelClick: () => {},
  66. onDuplicateClick: () => {},
  67. });
  68. expect(wrapper.find("loading").length).toBe(1);
  69. });
  70. });