Skip to content

Commit

Permalink
fix(kit): fix CalendarRange defaultViewedMonth shows correct left a…
Browse files Browse the repository at this point in the history
…nd right calendars
  • Loading branch information
mdlufy committed Aug 7, 2024
1 parent 3408038 commit faa9a07
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@ describe('CalendarRange', () => {
await documentationPage.prepareApiPageBeforeScreenshot();
await expect(page).toHaveScreenshot('calendar-range-max-length-click.png');
});

test('When set defaultViewedMonth, calendar shows defaultViewedMonth', async ({
page,
}) => {
await tuiGoto(page, 'components/calendar-range/API?defaultViewedMonth$=2');

await documentationPage.prepareApiPageBeforeScreenshot();
await expect(page).toHaveScreenshot(
'calendar-range-default-viewed-month.png',
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export class TuiCalendarRangeComponent implements TuiWithOptionalMinMax<TuiDay>
this.value = this.previousValue;
}

readonly monthOffset: TuiTypedMapper<[TuiMonth, number], TuiMonth> = (value, month) =>
value.append({month});

readonly mapper: TuiTypedMapper<
[
readonly TuiDayRangePeriod[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
automation-id="tui-calendar-range__calendars"
tuiPreventDefault="mousedown"
[defaultViewedMonthFirst]="defaultViewedMonth"
[defaultViewedMonthSecond]="defaultViewedMonth | tuiMapper: monthOffset : 1"
[disabledItemHandler]="calculatedDisabledItemHandler"
[markerHandler]="markerHandler"
[max]="computedMax | tuiMapper: maxLengthMapper : value : maxLength : false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ describe('PrimitiveRangeCalendar component', () => {
component.ngOnInit();
expect(component.userViewedMonthFirst).toEqual(minDate);
});

it('When initialized with setted input defaultViewedMonthFirst, shows defaultViewedMonthFirst', () => {
const month = new TuiMonth(2020, 5);

component.defaultViewedMonthFirst = month;
component.ngOnInit();

expect(component.userViewedMonthFirst).toBe(month);
});
});

describe('viewedMonthSecond', () => {
Expand Down Expand Up @@ -105,6 +114,15 @@ describe('PrimitiveRangeCalendar component', () => {

expect(component.userViewedMonthSecond).toEqual(minDate.append({month: 1}));
});

it('When initialized with setted input defaultViewedMonthSecond, shows defaultViewedMonthSecond', () => {
const month = new TuiMonth(2020, 5);

component.defaultViewedMonthSecond = month;
component.ngOnInit();

expect(component.userViewedMonthSecond).toBe(month);
});
});

describe('cappedUserViewedMonthSecond', () => {
Expand Down

0 comments on commit faa9a07

Please sign in to comment.