Shared:Tests:Unit: add i18 mock, fix warnings

This commit is contained in:
Timofey Boyko 2023-12-29 16:06:40 +03:00
parent 90ee60a260
commit 756cc36368
6 changed files with 46 additions and 5 deletions

View File

@ -0,0 +1,37 @@
/* eslint-disable react/display-name */
/* eslint-disable @typescript-eslint/naming-convention */
/* global jest */
const react_i18next: {
translate: () => (
Component: React.JSXElementConstructor<{
t: () => string;
}>,
) => (props: {}) => JSX.Element;
useTranslation: (value: string) => {
t: (key: string) => string;
i18n: {
language: string;
};
};
language: string;
i18n: {
language: string;
};
} = jest.genMockFromModule("react-i18next");
const translate =
() =>
(Component: React.JSXElementConstructor<{ t: () => string }>) =>
(props: {}) => <Component t={() => ""} {...props} />;
react_i18next.translate = translate;
react_i18next.useTranslation = () => ({
t: () => "",
i18n: {
language: "en",
},
});
react_i18next.i18n = { language: "en" };
module.exports = react_i18next;

View File

@ -3,7 +3,7 @@ import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import { Cron } from ".";
import Cron from "./Cron";
test("<Cron />: render without error", () => {
render(<Cron value="* * * * *" setValue={() => {}} />);

View File

@ -23,7 +23,7 @@ import { CronWrapper, Suffix } from "./Cron.styled";
import type { PeriodType, CronProps } from "./Cron.types";
function Cron({ value = defaultCronString, setValue, onError }: CronProps) {
const Cron = ({ value = defaultCronString, setValue, onError }: CronProps) => {
const { t } = useTranslation("Common");
const didMountRef = useRef<boolean>(false);
@ -162,6 +162,6 @@ function Cron({ value = defaultCronString, setValue, onError }: CronProps) {
<Suffix>{t("Common:UTC")}</Suffix>
</CronWrapper>
);
}
};
export default Cron;

View File

@ -22,7 +22,7 @@ const DropDownItem = (props: DropDownItemProps) => {
isHeader,
withHeaderArrow,
headerArrowAction,
label,
icon,
children,
disabled,
@ -41,7 +41,8 @@ const DropDownItem = (props: DropDownItemProps) => {
const { t } = useTranslation(["Settings"]);
const { withToggle, checked, onClick, onClickSelectedItem, ...rest } = props;
const { withToggle, checked, onClick, onClickSelectedItem, label, ...rest } =
props;
const onClickAction = (
e: React.MouseEvent | React.ChangeEvent<HTMLInputElement>,

View File

@ -72,6 +72,8 @@ const ClearTextareaAutosize = React.forwardRef(
paddingLeftProp,
isJSONField,
enableCopy,
heightTextAreaProp,
heightTextArea,
...props
}: TextareaProps & {
disabled?: boolean;

View File

@ -92,6 +92,7 @@ const config: Config = {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|scss)$": "<rootDir>/__mocks__/styleMock.js",
"react-i18next": "<rootDir>/__mocks__/reacti18nextMock.tsx",
"PUBLIC_DIR/": "<rootDir>/__mocks__/fileMock.js",
},