Skip to content

Commit

Permalink
6236/date time picker default (keystonejs#6237)
Browse files Browse the repository at this point in the history
* remove empty timeValue validation

* changeset

* update unit test
  • Loading branch information
gwyneplaine authored and Nikitoring committed Sep 14, 2021
1 parent 272ebfc commit 635a354
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-guests-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields': patch
---

Updated timestamp field to default time to 00:00 when no time is selected.
14 changes: 9 additions & 5 deletions packages/fields/src/types/timestamp/views/__tests__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('controller', () => {
dateValue: formatISO(new Date(), { representation: 'date' }),
timeValue: '',
})
).toBe(false);
).toBe(true);
});
});
describe('serialize', () => {
Expand Down Expand Up @@ -61,11 +61,15 @@ describe('controller', () => {
[STUBCONFIG.path]: null,
});
});
it('should return null if no timeValue is specified', () => {
it('should return a valid ISO8601 string if no timeValue is specified but a valid date value is specified', () => {
const { serialize } = controller(STUBCONFIG);
expect(serialize({ dateValue: '2020-10-20', timeValue: '' })).toStrictEqual({
[STUBCONFIG.path]: null,
});
expect(
Boolean(
parseISO(
serialize({ dateValue: '2020-10-20', timeValue: '' })[STUBCONFIG.path]
).toISOString()
)
).toBe(true);
});
it('should return a valid ISO8601 string if a valid time and date value are specified', () => {
const { serialize } = controller(STUBCONFIG);
Expand Down
3 changes: 1 addition & 2 deletions packages/fields/src/types/timestamp/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const controller = (
return { dateValue: '', timeValue: '' };
},
serialize: ({ dateValue, timeValue }) => {
if (dateValue && timeValue && isValidISO({ dateValue, timeValue })) {
if (dateValue && isValidISO({ dateValue, timeValue })) {
let formattedDate = constructTimestamp({ dateValue, timeValue });
return { [config.path]: formattedDate };
}
Expand All @@ -164,7 +164,6 @@ export const controller = (
validate({ dateValue, timeValue }) {
if (!dateValue && !timeValue) return true;
if (!dateValue) return false;
if (!timeValue) return false;
return isValidISO({ dateValue, timeValue });
},
};
Expand Down

0 comments on commit 635a354

Please sign in to comment.