mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:06:22 +00:00
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:
parent
8fbfd830c9
commit
60ac758b68
@ -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")}}' },
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user