Skip to content

Commit

Permalink
fix(kit): fix calendar range presets filtration (#9777)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladyslav Bondar <[email protected]>
Co-authored-by: mdlufy <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent ae83d2d commit bfeb254
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export class TuiCalendarRange implements OnInit, OnChanges {
...items.filter(
(item) =>
(minLength === null ||
item.range.from.append(minLength).daySameOrBefore(item.range.to)) &&
item.range.from
.append(minLength)
.append({day: -1})
.daySameOrBefore(item.range.to)) &&
(min === null || item.range.to.daySameOrAfter(min)) &&
(max === null || item.range.from.daySameOrBefore(max)),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {FormControl, NgControl} from '@angular/forms';
import {By} from '@angular/platform-browser';
import type {TuiDayLike} from '@taiga-ui/cdk';
import {
TUI_LAST_DAY,
tuiControlValue,
Expand Down Expand Up @@ -40,7 +41,9 @@ describe('rangeCalendarComponent', () => {
[items]="items"
[markerHandler]="markerHandler"
[max]="max"
[maxLength]="maxLength"
[min]="min"
[minLength]="minLength"
[value]="value"
(valueChange)="onRangeChange($event)"
/>
Expand Down Expand Up @@ -72,6 +75,10 @@ describe('rangeCalendarComponent', () => {

public max = TUI_LAST_DAY;

public minLength: TuiDayLike | null = null;

public maxLength: TuiDayLike | null = null;

public value: TuiDayRange | null = null;

public defaultViewedMonth = TuiMonth.currentLocal();
Expand Down Expand Up @@ -254,6 +261,23 @@ describe('rangeCalendarComponent', () => {
expect(items[1]?.nativeElement.contains(getCheckmark())).toBe(true);
});

it('show item if it matches with minLength and maxLength', () => {
const today = TuiDay.currentLocal();
const length = {day: 1};
const title = 'Период';

testComponent.minLength = length;
testComponent.maxLength = length;

testComponent.items = [
new TuiDayRangePeriod(new TuiDayRange(today, today), title),
];

fixture.detectChanges();

expect(getItems()[0]?.nativeElement.textContent.trim()).toBe(title);
});

it('should update selectedActivePeriod after onItemSelect', () => {
if (component.items[1]) {
component['onItemSelect'](component.items[1]);
Expand Down

0 comments on commit bfeb254

Please sign in to comment.