Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy committed Nov 15, 2024
1 parent b541da8 commit beba044
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ describe('<DesktopDateTimeRangePicker />', () => {
expect(expectFieldValueV7(startSectionsContainer, '01/11/2018 04:05 PM'));
expect(expectFieldValueV7(endSectionsContainer, '01/11/2018 05:10 PM'));
});

it('should use time from `referenceDate` when selecting the day', () => {
render(
<DesktopDateTimeRangePicker referenceDate={adapterToUse.date('2022-04-14T14:15:00')} />,
);

openPicker({ type: 'date-time-range', variant: 'desktop', initialFocus: 'start' });

fireEvent.click(screen.getByRole('gridcell', { name: '11' }));

expect(screen.getByRole('option', { name: '2 hours', selected: true })).not.to.equal(null);
expect(screen.getByRole('option', { name: '15 minutes', selected: true })).not.to.equal(null);
expect(screen.getByRole('option', { name: 'PM', selected: true })).not.to.equal(null);
const startSectionsContainer = getFieldSectionsContainer(0);
expect(expectFieldValueV7(startSectionsContainer, '04/11/2022 02:15 PM'));
});
});

describe('disabled dates', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ describe('date-range-manager', () => {
expectedRange: [start2018, null],
expectedNextSelection: 'end' as const,
},
{
range: [null, null],
rangePosition: 'start' as const,
newDate: start2018,
expectedRange: [start2018At4PM, null],
expectedNextSelection: 'end' as const,
shouldMergeDateAndTime: true,
referenceDate: start2018At4PM,
},
{
range: [start2018, null],
rangePosition: 'start' as const,
Expand Down Expand Up @@ -99,7 +108,16 @@ describe('date-range-manager', () => {
expectedNextSelection: 'start' as const,
},
].forEach(
({ range, rangePosition, newDate, expectedRange, allowRangeFlip, expectedNextSelection }) => {
({
range,
rangePosition,
newDate,
expectedRange,
allowRangeFlip,
expectedNextSelection,
shouldMergeDateAndTime,
referenceDate,
}) => {
it(`calculateRangeChange should return ${expectedRange} when selecting ${rangePosition} of ${range} with user input ${newDate}`, () => {
expect(
calculateRangeChange({
Expand All @@ -108,6 +126,8 @@ describe('date-range-manager', () => {
newDate,
rangePosition,
allowRangeFlip,
shouldMergeDateAndTime,
referenceDate,
}),
).to.deep.equal({
nextSelection: expectedNextSelection,
Expand Down

0 comments on commit beba044

Please sign in to comment.