From db36ab927659fd4ea48d3d7ab0471cdd6f66e2cf Mon Sep 17 00:00:00 2001 From: Barrior Date: Mon, 15 Jan 2024 18:30:54 +0800 Subject: [PATCH] test: add test cases --- test/@helpers/dom.ts | 14 ++++ test/core-react/@helpers/Vertical.tsx | 36 +++++++++ test/core-react/@helpers/renderers.tsx | 53 ++++++++++++ test/core-react/span.test.tsx | 107 +++++++++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 test/core-react/@helpers/Vertical.tsx create mode 100644 test/core-react/@helpers/renderers.tsx create mode 100644 test/core-react/span.test.tsx diff --git a/test/@helpers/dom.ts b/test/@helpers/dom.ts index de3bbc7..3c6ee36 100644 --- a/test/@helpers/dom.ts +++ b/test/@helpers/dom.ts @@ -23,3 +23,17 @@ export function createElement(params?: ICreateElementParams) { return element } + +/** + * 获取 DOM 元素样式 + * @param container 容器 + * @param selector 选择器 + * @returns 样式对象 + */ +export function getElementStyle(container: HTMLElement, selector: string) { + const elem = container.querySelector(selector) + if (elem) { + return window.getComputedStyle(elem) + } + return {} as Partial +} diff --git a/test/core-react/@helpers/Vertical.tsx b/test/core-react/@helpers/Vertical.tsx new file mode 100644 index 0000000..9abcea3 --- /dev/null +++ b/test/core-react/@helpers/Vertical.tsx @@ -0,0 +1,36 @@ +import type { IOpenItemLayoutParams } from '@core-react/index' +import type { FC } from 'react' + +const Vertical: FC = ({ body, schema, validator, required }) => { + return ( +
+
+ {required && *} + + {schema.title} + + {!!schema.titleDescription && ( + {schema.titleDescription} + )} +
+ +
{body}
+ +
+ {validator.status === 'error' && !!validator.message && ( +
{validator.message}
+ )} + + {validator.status === 'warning' && !!validator.message && ( +
{validator.message}
+ )} + + {!!schema.description && ( +
{schema.description}
+ )} +
+
+ ) +} + +export default Vertical diff --git a/test/core-react/@helpers/renderers.tsx b/test/core-react/@helpers/renderers.tsx new file mode 100644 index 0000000..ca92012 --- /dev/null +++ b/test/core-react/@helpers/renderers.tsx @@ -0,0 +1,53 @@ +import type { IRenderers, ISchema } from '@core-react/index' +import classNames from 'classnames' + +const renderers: IRenderers = { + InputText: { + component: ({ schema, value, disabled, readonly, onChange }) => { + if (readonly) { + return
{value}
+ } + return ( + onChange(e.target.value)} + /> + ) + }, + }, + InputNumber: { + component: ({ schema, value, disabled, readonly, onChange }) => { + if (readonly) { + return
{value}
+ } + return ( + onChange(Number(e.target.value))} + /> + ) + }, + }, + TextArea: { + component: ({ schema, value, disabled, readonly, onChange }) => { + if (readonly) { + return
{value}
+ } + return ( +