test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 { User } from "@src/@types/User";
  19. import DetailsPageHeader from ".";
  20. type Props = {
  21. user?: User | null;
  22. };
  23. const wrap = (props: Props) =>
  24. new TW(
  25. shallow(
  26. <DetailsPageHeader onUserItemClick={() => {}} testMode {...props} />
  27. ),
  28. "dpHeader"
  29. );
  30. const user = {
  31. name: "User name",
  32. email: "email@email.com",
  33. id: "user",
  34. project: { id: "", name: "" },
  35. };
  36. describe("DetailsPageHeader Component", () => {
  37. it("renders with given user", () => {
  38. const wrapper = wrap({ user });
  39. expect(wrapper.find("userDropdown").prop("user").name).toBe(user.name);
  40. expect(wrapper.find("userDropdown").prop("user").email).toBe(user.email);
  41. });
  42. it("dispatches user item click", () => {
  43. const onUserItemClick = sinon.spy();
  44. const wrapper = wrap({ user, onUserItemClick });
  45. wrapper
  46. .find("userDropdown")
  47. .simulate("itemClick", { value: "", label: "" });
  48. expect(onUserItemClick.called).toBe(true);
  49. });
  50. });