toolQueries.ts 862 B

12345678910111213141516171819202122232425262728293031323334
  1. import { queries, buildQueries } from "@testing-library/react";
  2. const toolMap = {
  3. selection: "selection",
  4. rectangle: "rectangle",
  5. diamond: "diamond",
  6. ellipse: "ellipse",
  7. arrow: "arrow",
  8. line: "line",
  9. };
  10. export type ToolName = keyof typeof toolMap;
  11. const _getAllByToolName = (container: HTMLElement, tool: string) => {
  12. const toolTitle = toolMap[tool as ToolName];
  13. return queries.getAllByTestId(container, toolTitle);
  14. };
  15. const getMultipleError = (_container: any, tool: any) =>
  16. `Found multiple elements with tool name: ${tool}`;
  17. const getMissingError = (_container: any, tool: any) =>
  18. `Unable to find an element with tool name: ${tool}`;
  19. export const [
  20. queryByToolName,
  21. getAllByToolName,
  22. getByToolName,
  23. findAllByToolName,
  24. findByToolName,
  25. ] = buildQueries<string[]>(
  26. _getAllByToolName,
  27. getMultipleError,
  28. getMissingError,
  29. );