Part.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2021-2024 Avaiga Private Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  5. * the License. You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  10. * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. * specific language governing permissions and limitations under the License.
  12. */
  13. import React from "react";
  14. import {render} from "@testing-library/react";
  15. import "@testing-library/jest-dom";
  16. import Part from './Part';
  17. describe("Part Component", () => {
  18. it("renders", async () => {
  19. const {getByText} = render(<Part>bar</Part>);
  20. const elt = getByText("bar");
  21. expect(elt.tagName).toBe("DIV");
  22. expect(elt).toHaveClass("MuiBox-root")
  23. })
  24. it("displays the right info for string", async () => {
  25. const {getByText} = render(<Part className="taipy-part">bar</Part>);
  26. const elt = getByText("bar");
  27. expect(elt).toHaveClass("taipy-part");
  28. })
  29. it("displays with width=70%", async () => {
  30. const { getByText } = render(<Part width="70%">bar</Part>);
  31. const elt = getByText("bar");
  32. expect(elt).toHaveStyle('width: 70%');
  33. });
  34. it("displays with width=500", async () => {
  35. const { getByText } = render(<Part width={500}>bar</Part>);
  36. const elt = getByText("bar");
  37. expect(elt).toHaveStyle('width: 500px');
  38. });
  39. it("renders an iframe", async () => {
  40. const {getByText} = render(<Part className="taipy-part" page="http://taipy.io">bar</Part>);
  41. const elt = getByText("bar");
  42. expect(elt.parentElement?.firstElementChild?.tagName).toBe("DIV");
  43. expect(elt.parentElement?.firstElementChild?.firstElementChild?.tagName).toBe("IFRAME");
  44. })
  45. });