Skip to content

Commit

Permalink
unit test cases for date adapter added
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharyar-shamshi committed Feb 29, 2024
1 parent c873b53 commit 8f31c76
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/x-date-pickers/src/AdapterDateFns/AdapterDateFns.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,30 @@ describe('<AdapterDateFns />', () => {
});
});
});

// 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');
// });
// });
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,30 @@ describe('<AdapterDateFnsJalali />', () => {
});
});
});

// 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');
// });
// });
});
26 changes: 26 additions & 0 deletions packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,31 @@ describe('<AdapterDayjs />', () => {
});
});
});

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');
});
});
});
});
26 changes: 26 additions & 0 deletions packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,31 @@ describe('<AdapterLuxon />', () => {
});
});
});

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');
});
});
});
});
26 changes: 26 additions & 0 deletions packages/x-date-pickers/src/AdapterMoment/AdapterMoment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,30 @@ describe('<AdapterMoment />', () => {
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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,31 @@ describe('<AdapterMomentHijri />', () => {
});
});
});

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('2020-01-01T23:44:00.000Z')!;
const newDate = adapter.setMonthYearDate(initialDate, 2018, 4, 15);

const v7Response = renderWithProps({
enableAccessibleFieldDOMStructure: true,
value: newDate,
});
expectFieldValueV7(v7Response.getSectionsContainer(), '١٤٣٩/٠٨/٢٩ ٠٩:٣٥');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('<AdapterMomentJalaali />', () => {

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);
};

Expand Down Expand Up @@ -100,4 +101,30 @@ describe('<AdapterMomentJalaali />', () => {
});
});
});

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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

0 comments on commit 8f31c76

Please sign in to comment.