refactor: the default accuracy of the UnixTimestamp field is second (#4418)

* refactor: the default accuracy of the UnixTimestamp field is second

* refactor: the default accuracy of the UnixTimestamp field is second

* fix: bug
This commit is contained in:
Katherine 2024-05-21 10:31:01 +08:00 committed by GitHub
parent 8fbfd830c9
commit 60ac758b68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View File

@ -23,7 +23,7 @@ export class UnixTimestampFieldInterface extends CollectionFieldInterface {
type: 'number',
'x-component': 'UnixTimestamp',
'x-component-props': {
accuracy: 'millisecond',
accuracy: 'second',
showTime: true,
},
},
@ -37,7 +37,7 @@ export class UnixTimestampFieldInterface extends CollectionFieldInterface {
title: '{{t("Accuracy")}}',
'x-component': 'Radio.Group',
'x-decorator': 'FormItem',
default: 'millisecond',
default: 'second',
enum: [
{ value: 'millisecond', label: '{{t("Millisecond")}}' },
{ value: 'second', label: '{{t("Second")}}' },

View File

@ -42,7 +42,7 @@ interface UnixTimestampProps {
export const UnixTimestamp = connect(
(props: UnixTimestampProps) => {
const { value, onChange, accuracy } = props;
const { value, onChange, accuracy = 'second' } = props;
const v = useMemo(() => toValue(value, accuracy), [value]);
return (
<DatePicker

View File

@ -14,6 +14,9 @@ describe('UnixTimestamp', () => {
it('renders without errors', async () => {
const { container } = await renderApp({
Component: UnixTimestamp,
props: {
accuracy: 'millisecond',
},
value: 0,
});
expect(container).toMatchInlineSnapshot(`
@ -70,6 +73,9 @@ describe('UnixTimestamp', () => {
await renderApp({
Component: UnixTimestamp,
value: 1712819630000,
props: {
accuracy: 'millisecond',
},
});
await waitFor(() => {
expect(screen.getByRole('textbox')).toHaveValue('2024-04-11');
@ -94,6 +100,9 @@ describe('UnixTimestamp', () => {
await renderApp({
Component: UnixTimestamp,
value: '2024-04-11',
props: {
accuracy: 'millisecond',
},
});
await waitFor(() => {
@ -107,6 +116,9 @@ describe('UnixTimestamp', () => {
Component: UnixTimestamp,
value: '2024-04-11',
onChange,
props: {
accuracy: 'millisecond',
},
});
await userEvent.click(screen.getByRole('textbox'));
@ -126,6 +138,9 @@ describe('UnixTimestamp', () => {
const { container } = await renderReadPrettyApp({
Component: UnixTimestamp,
value: '2024-04-11',
props: {
accuracy: 'millisecond',
},
});
expect(screen.getByText('2024-04-11')).toBeInTheDocument();