From 05799065d0f607b15b4a3948204c54a603f933f7 Mon Sep 17 00:00:00 2001 From: Shaharyar Shamshi Date: Fri, 1 Mar 2024 01:48:26 +0530 Subject: [PATCH] unit test cases for date adapter added --- .../AdapterDateFns/AdapterDateFns.test.tsx | 26 ++++++++++++++++++ .../AdapterDateFnsJalali.test.tsx | 26 ++++++++++++++++++ .../src/AdapterDayjs/AdapterDayjs.test.tsx | 26 ++++++++++++++++++ .../src/AdapterLuxon/AdapterLuxon.test.tsx | 26 ++++++++++++++++++ .../src/AdapterMoment/AdapterMoment.test.tsx | 26 ++++++++++++++++++ .../AdapterMomentHijri.test.tsx | 26 ++++++++++++++++++ .../AdapterMomentHijri/AdapterMomentHijri.ts | 2 +- .../AdapterMomentJalaali.test.tsx | 27 +++++++++++++++++++ .../AdapterMomentJalaali.ts | 2 +- 9 files changed, 185 insertions(+), 2 deletions(-) diff --git a/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx b/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx index 130c14f288215..346b81aea695a 100644 --- a/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx +++ b/packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx @@ -128,4 +128,30 @@ describe('', () => { }); }); }); + + // describe('Test setMonthYearDate', () => { + // const localeObject = { code: 'en' }; + // const { render, clock, adapter } = createPickerRenderer({ + // clock: 'fake', + // adapterName: 'date-fns', + // locale: localeObject, + // }); + + // const { renderWithProps } = buildFieldInteractions({ + // render, + // clock, + // Component: DateTimeField, + // }); + + // it('should set month, year, and date correctly', () => { + // const initialDate = adapter.date('2022-01-15T09:35:00')!; + // const newDate = adapter.setMonthYearDate(initialDate, 1400, 0, 25); + + // const v7Response = renderWithProps({ + // enableAccessibleFieldDOMStructure: true, + // value: newDate, + // }); + // expectFieldValueV7(v7Response.getSectionsContainer(), '1400/01/25 09:35'); + // }); + // }); }); diff --git a/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx b/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx index a49981020364b..b3a43d58c4801 100644 --- a/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx +++ b/packages/x-date-pickers/src/AdapterDateFnsJalali/AdapterDateFnsJalali.test.tsx @@ -92,4 +92,30 @@ describe('', () => { }); }); }); + + // describe('Test setMonthYearDate', () => { + // const localeObject = { code: 'en' }; + // const { render, clock, adapter } = createPickerRenderer({ + // clock: 'fake', + // adapterName: 'date-fns-jalali', + // locale: localeObject, + // }); + + // const { renderWithProps } = buildFieldInteractions({ + // render, + // clock, + // Component: DateTimeField, + // }); + + // it('should set month, year, and date correctly', () => { + // const initialDate = adapter.date('2022-01-15T09:35:00')!; + // const newDate = adapter.setMonthYearDate(initialDate, 1400, 0, 25); + + // const v7Response = renderWithProps({ + // enableAccessibleFieldDOMStructure: true, + // value: newDate, + // }); + // expectFieldValueV7(v7Response.getSectionsContainer(), '1400/01/25 09:35'); + // }); + // }); }); diff --git a/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx b/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx index e9345793b08db..508bcc50a26bf 100644 --- a/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx +++ b/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx @@ -155,5 +155,31 @@ describe('', () => { }); }); }); + + describe('Test setMonthYearDate', () => { + const localeObject = { code: 'en' }; + const { render, clock, adapter } = createPickerRenderer({ + clock: 'fake', + adapterName: 'dayjs', + locale: localeObject, + }); + + const { renderWithProps } = buildFieldInteractions({ + render, + clock, + Component: DateTimeField, + }); + + it('should set month, year, and date correctly', () => { + const initialDate = adapter.date('2022-01-15T09:35:00')!; + const newDate = adapter.setMonthYearDate(initialDate, 1400, 4, 25); + + const v7Response = renderWithProps({ + enableAccessibleFieldDOMStructure: true, + value: newDate, + }); + expectFieldValueV7(v7Response.getSectionsContainer(), '05/25/1400 09:35 AM'); + }); + }); }); }); diff --git a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx index 7fca1db9ba2a7..da32f566cf50c 100644 --- a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx +++ b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx @@ -188,5 +188,31 @@ describe('', () => { }); }); }); + + describe('Test setMonthYearDate', () => { + const localeObject = { code: 'en' }; + const { render, clock, adapter } = createPickerRenderer({ + clock: 'fake', + adapterName: 'luxon', + locale: localeObject, + }); + + const { renderWithProps } = buildFieldInteractions({ + render, + clock, + Component: DateTimeField, + }); + + it('should set month, year, and date correctly', () => { + const initialDate = adapter.date('2022-01-15T09:35:00')!; + const newDate = adapter.setMonthYearDate(initialDate, 1400, 1, 25); + + const v7Response = renderWithProps({ + enableAccessibleFieldDOMStructure: true, + value: newDate, + }); + expectFieldValueV7(v7Response.getSectionsContainer(), '01/25/1400 09:35 AM'); + }); + }); }); }); diff --git a/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx b/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx index 0d5c15689d0a3..c7ea4c2d82375 100644 --- a/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx +++ b/packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx @@ -188,4 +188,30 @@ describe('', () => { adapter.date()!; expect(spiedInstance.callCount).to.equal(1); }); + + describe('Test setMonthYearDate', () => { + const localeObject = { code: 'en' }; + const { render, clock, adapter } = createPickerRenderer({ + clock: 'fake', + adapterName: 'moment', + locale: localeObject, + }); + + const { renderWithProps } = buildFieldInteractions({ + render, + clock, + Component: DateTimeField, + }); + + it('should set month, year, and date correctly', () => { + const initialDate = adapter.date('2022-01-15T09:35:00')!; + const newDate = adapter.setMonthYearDate(initialDate, 1400, 0, 25); + + const v7Response = renderWithProps({ + enableAccessibleFieldDOMStructure: true, + value: newDate, + }); + expectFieldValueV7(v7Response.getSectionsContainer(), '01/25/1400 09:35 AM'); + }); + }); }); diff --git a/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx b/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx index 1e0b2499d0c5a..03cf1332fc75f 100644 --- a/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx +++ b/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.test.tsx @@ -93,5 +93,31 @@ describe('', () => { }); }); }); + + describe('Test setMonthYearDate', () => { + const localeObject = { code: 'ar' }; + const { render, clock, adapter } = createPickerRenderer({ + clock: 'fake', + adapterName: 'moment-hijri', + locale: localeObject, + }); + + const { renderWithProps } = buildFieldInteractions({ + render, + clock, + Component: DateTimeField, + }); + + it('should set month, year, and date correctly', () => { + const initialDate = adapter.date('2022-01-15T09:35:00')!; + const newDate = adapter.setMonthYearDate(initialDate, 1439, 4, 15); + + const v7Response = renderWithProps({ + enableAccessibleFieldDOMStructure: true, + value: newDate, + }); + expectFieldValueV7(v7Response.getSectionsContainer(), '١٤٣٩/٠٨/٢٩ ٠٩:٣٥'); + }); + }); }); }); diff --git a/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.ts b/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.ts index 322f77c4b2684..07a6f4312f0c0 100644 --- a/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.ts +++ b/packages/x-date-pickers/src/AdapterMomentHijri/AdapterMomentHijri.ts @@ -239,7 +239,7 @@ export class AdapterMomentHijri extends AdapterMoment implements MuiPickersAdapt return super.getYearRange([start, end]); }; - public setMonthYearDate = (value: Moment, month: number, year: number, date: number) => { + public setMonthYearDate = (value: Moment, year: number, month: number, date: number) => { return value.clone().iYear(year).iMonth(month).iDate(date); }; } diff --git a/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx b/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx index cc50559fe01f0..8dd4365c7d761 100644 --- a/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx +++ b/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.test.tsx @@ -36,6 +36,7 @@ describe('', () => { const expectDate = (format: keyof AdapterFormats, expectedWithFaIR: string) => { const date = adapter.date('2020-02-01T23:44:00.000Z')!; + expect(adapter.format(date, format)).to.equal(expectedWithFaIR); }; @@ -100,4 +101,30 @@ describe('', () => { }); }); }); + + describe('Test setMonthYearDate', () => { + const localeObject = { code: 'en' }; + const { render, clock, adapter } = createPickerRenderer({ + clock: 'fake', + adapterName: 'moment-jalaali', + locale: localeObject, + }); + + const { renderWithProps } = buildFieldInteractions({ + render, + clock, + Component: DateTimeField, + }); + + it('should set month, year, and date correctly', () => { + const initialDate = adapter.date('2022-01-15T09:35:00')!; + const newDate = adapter.setMonthYearDate(initialDate, 1400, 0, 25); + + const v7Response = renderWithProps({ + enableAccessibleFieldDOMStructure: true, + value: newDate, + }); + expectFieldValueV7(v7Response.getSectionsContainer(), '1400/01/25 09:35'); + }); + }); }); diff --git a/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.ts b/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.ts index 81624ed1bd05f..76a189e966b5a 100644 --- a/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.ts +++ b/packages/x-date-pickers/src/AdapterMomentJalaali/AdapterMomentJalaali.ts @@ -248,7 +248,7 @@ export class AdapterMomentJalaali return value.jWeek(); }; - public setMonthYearDate = (value: Moment, year: number, month: number, date: number) => { + public setMonthYearDate = (value: Moment, year: number, month: number, date: number): Moment => { return value.clone().jYear(year).jMonth(month).jDate(date); }; }