Commit e31519b4 by chenwq

feat(ui): add form control wrappers and test setup

1 parent 0a1f34e5
......@@ -9,6 +9,7 @@
},
"scripts": {
"dev": "vite",
"test": "vitest run",
"build": "tsc --noEmit && vite build",
"preview": "vite preview",
"typecheck": "tsc --noEmit",
......@@ -30,6 +31,9 @@
"zustand": "^5.0.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^7.0.1",
"@testing-library/react": "^16.3.3",
"@testing-library/user-event": "^14.6.7",
"@types/jsrsasign": "^10.5.15",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
......@@ -38,10 +42,12 @@
"eslint": "^9",
"eslint-config-prettier": "^9",
"husky": "^9",
"jsdom": "^30.1.1",
"lint-staged": "^15",
"prettier": "^3",
"typescript": "^5.6.3",
"vite": "^6.0.0"
"vite": "^6.0.0",
"vitest": "^5.0.2"
},
"lint-staged": {
"src/access/**/*.{ts,tsx}": [
......
import { DatePicker, type DatePickerProps } from 'antd';
export type UDatePickerProps = DatePickerProps;
export const UDatePicker = Object.assign((props: UDatePickerProps) => <DatePicker {...props} />, {
RangePicker: DatePicker.RangePicker,
});
import { Descriptions, type DescriptionsProps } from 'antd';
export type UDescriptionsProps = DescriptionsProps;
export const UDescriptions = Object.assign(
(props: UDescriptionsProps) => <Descriptions {...props} />,
{
Item: Descriptions.Item,
},
);
import { Radio, type RadioGroupProps, type RadioProps } from 'antd';
export type URadioProps = RadioProps;
export type URadioGroupProps = RadioGroupProps;
export const URadio = Object.assign((props: URadioProps) => <Radio {...props} />, {
Group: Radio.Group,
});
import { Switch, type SwitchProps } from 'antd';
export type USwitchProps = SwitchProps;
export const USwitch = (props: USwitchProps) => <Switch {...props} />;
......@@ -31,3 +31,12 @@ export { UCheckbox } from './components/Checkbox';
export { UList } from './components/List';
export { UTooltip } from './components/Tooltip';
export { UResult } from './components/Result';
export { UDatePicker } from './components/DatePicker';
export type { UDatePickerProps } from './components/DatePicker';
export { URadio } from './components/Radio';
export type { URadioProps, URadioGroupProps } from './components/Radio';
export { USwitch } from './components/Switch';
export type { USwitchProps } from './components/Switch';
export { UDescriptions } from './components/Descriptions';
export type { UDescriptionsProps } from './components/Descriptions';
import { render, screen } from '@testing-library/react';
import { UDatePicker, UDescriptions, URadio, USwitch } from '@uj/ui';
import { describe, expect, it } from 'vitest';
describe('统一表单控件', () => {
it('提供日期、单选、开关与详情展示控件', () => {
render(
<>
<label htmlFor="date">日期</label>
<UDatePicker id="date" />
<URadio.Group aria-label="状态" options={[{ label: '启用', value: 'enabled' }]} />
<USwitch aria-label="开关" />
<UDescriptions items={[{ key: 'name', label: '名称', children: '门店 A' }]} />
</>,
);
expect(screen.getByLabelText('日期')).toBeInTheDocument();
expect(screen.getByLabelText('状态')).toBeInTheDocument();
expect(screen.getByLabelText('开关')).toBeInTheDocument();
expect(screen.getByText('门店 A')).toBeInTheDocument();
});
});
import '@testing-library/jest-dom/vitest';
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => undefined,
removeListener: () => undefined,
addEventListener: () => undefined,
removeEventListener: () => undefined,
dispatchEvent: () => false,
}),
});
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@uj/ui': fileURLToPath(new URL('./packages/ui/src/index.ts', import.meta.url)),
},
},
test: { environment: 'jsdom', setupFiles: ['./src/test/setup.ts'] },
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!