2020-02-12 02:19:43 +04:00
|
|
|
import { queries, buildQueries } from "@testing-library/react";
|
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
const toolMap = {
|
2020-04-07 14:39:06 +03:00
|
|
|
selection: "selection",
|
|
|
|
rectangle: "rectangle",
|
|
|
|
diamond: "diamond",
|
|
|
|
ellipse: "ellipse",
|
|
|
|
arrow: "arrow",
|
|
|
|
line: "line",
|
2020-05-12 20:10:11 +01:00
|
|
|
draw: "draw",
|
2020-03-23 16:38:41 -07:00
|
|
|
};
|
2020-02-12 02:19:43 +04:00
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
export type ToolName = keyof typeof toolMap;
|
|
|
|
|
|
|
|
const _getAllByToolName = (container: HTMLElement, tool: string) => {
|
|
|
|
const toolTitle = toolMap[tool as ToolName];
|
2020-04-07 14:39:06 +03:00
|
|
|
return queries.getAllByTestId(container, toolTitle);
|
2020-02-12 02:19:43 +04:00
|
|
|
};
|
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
const getMultipleError = (_container: any, tool: any) =>
|
2020-02-12 02:19:43 +04:00
|
|
|
`Found multiple elements with tool name: ${tool}`;
|
2020-03-07 10:20:38 -05:00
|
|
|
const getMissingError = (_container: any, tool: any) =>
|
2020-02-12 02:19:43 +04:00
|
|
|
`Unable to find an element with tool name: ${tool}`;
|
|
|
|
|
|
|
|
export const [
|
|
|
|
queryByToolName,
|
|
|
|
getAllByToolName,
|
|
|
|
getByToolName,
|
|
|
|
findAllByToolName,
|
|
|
|
findByToolName,
|
|
|
|
] = buildQueries<string[]>(
|
|
|
|
_getAllByToolName,
|
|
|
|
getMultipleError,
|
|
|
|
getMissingError,
|
|
|
|
);
|