typeChecks.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { API } from "@excalidraw/excalidraw/tests/helpers/api";
  2. import { hasBoundTextElement } from "../src/typeChecks";
  3. describe("Test TypeChecks", () => {
  4. describe("Test hasBoundTextElement", () => {
  5. it("should return true for text bindable containers with bound text", () => {
  6. expect(
  7. hasBoundTextElement(
  8. API.createElement({
  9. type: "rectangle",
  10. boundElements: [{ type: "text", id: "text-id" }],
  11. }),
  12. ),
  13. ).toBeTruthy();
  14. expect(
  15. hasBoundTextElement(
  16. API.createElement({
  17. type: "ellipse",
  18. boundElements: [{ type: "text", id: "text-id" }],
  19. }),
  20. ),
  21. ).toBeTruthy();
  22. expect(
  23. hasBoundTextElement(
  24. API.createElement({
  25. type: "arrow",
  26. boundElements: [{ type: "text", id: "text-id" }],
  27. }),
  28. ),
  29. ).toBeTruthy();
  30. });
  31. it("should return false for text bindable containers without bound text", () => {
  32. expect(
  33. hasBoundTextElement(
  34. API.createElement({
  35. type: "freedraw",
  36. boundElements: [{ type: "arrow", id: "arrow-id" }],
  37. }),
  38. ),
  39. ).toBeFalsy();
  40. });
  41. it("should return false for non text bindable containers", () => {
  42. expect(
  43. hasBoundTextElement(
  44. API.createElement({
  45. type: "freedraw",
  46. boundElements: [{ type: "text", id: "text-id" }],
  47. }),
  48. ),
  49. ).toBeFalsy();
  50. });
  51. expect(
  52. hasBoundTextElement(
  53. API.createElement({
  54. type: "image",
  55. boundElements: [{ type: "text", id: "text-id" }],
  56. }),
  57. ),
  58. ).toBeFalsy();
  59. });
  60. });