Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ describe('PoCalendarBaseComponent:', () => {
expect(component.yearRangeLimit).toBe(50);
});

it('p-year-range-limit: should truncate a positive fractional number', () => {
component.yearRangeLimit = 25.9;

expect(component.yearRangeLimit).toBe(25);
});

it('p-year-range-limit: should fallback to 150 for invalid numbers', () => {
const invalidValues = [-1, NaN, Infinity, -Infinity];

expectPropertiesValues(component, 'yearRangeLimit', invalidValues, 150);
});

it('p-year-range-limit: should fallback to 150 when value is null', () => {
component.yearRangeLimit = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { PoCalendarRangePreset } from './interfaces/po-calendar-range-preset.int
*
* **Importante:**
* - Datas fora do intervalo (`p-min-date` / `p-max-date`) aparecem desabilitadas sem alterar o *model*.
* - São aceitos anos entre 0000 e 9999. No seletor de ano do cabeçalho é possível digitar qualquer ano com
* 4 dígitos, mesmo que não esteja listado, e a navegação é bloqueada nos limites desse intervalo.
*
* #### Boas práticas
*
Expand Down Expand Up @@ -343,7 +345,9 @@ export class PoCalendarBaseComponent {
// O valor informado determina o intervalo de anos anterior e posterior
// à data corrente que será disponibilizado para seleção.
@Input('p-year-range-limit') set yearRangeLimit(value: number) {
this._yearRangeLimit = value ?? 150;
const rangeLimit = value === null || value === undefined ? Number.NaN : Number(value);

this._yearRangeLimit = Number.isFinite(rangeLimit) && rangeLimit >= 0 ? Math.floor(rangeLimit) : 150;
}

get yearRangeLimit(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
(keydown.enter)="previous.emit(); $event.preventDefault()"
[p-aria-label]="previousMonthLabel"
p-icon="ICON_ARROW_LEFT"
[p-disabled]="disablePrevious()"
[p-size]="size"
></po-button>
}
Expand All @@ -22,6 +23,7 @@
(keydown.enter)="next.emit(); $event.preventDefault()"
[p-aria-label]="nextMonthLabel"
p-icon="ICON_ARROW_RIGHT"
[p-disabled]="disableNext()"
[p-size]="size"
></po-button>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ describe('PoCalendarHeaderComponent', () => {
expect(component).toBeTruthy();
});

it('should initialize disablePrevious and disableNext with false', () => {
expect(component.disablePrevious()).toBeFalse();
expect(component.disableNext()).toBeFalse();
});

it('should update disablePrevious and disableNext from `p-disable-previous` and `p-disable-next`', () => {
fixture.componentRef.setInput('p-disable-previous', true);
fixture.componentRef.setInput('p-disable-next', true);
fixture.detectChanges();

expect(component.disablePrevious()).toBeTrue();
expect(component.disableNext()).toBeTrue();
});

it('should call markForCheck and detectChanges when templateContext changes', () => {
const cdr = (component as any).cdr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OnChanges,
SimpleChanges,
inject,
input,
ChangeDetectorRef,
OnInit
} from '@angular/core';
Expand All @@ -26,6 +27,8 @@ export class PoCalendarHeaderComponent implements OnInit, OnChanges {

@Input('p-hide-previous') hidePrevious = false;
@Input('p-hide-next') hideNext = false;
disablePrevious = input<boolean>(false, { alias: 'p-disable-previous' });
disableNext = input<boolean>(false, { alias: 'p-disable-next' });
@Input('p-display-month') displayMonth!: number;
@Input('p-display-year') displayYear!: number;
@Input('p-display-month-label') displayMonthLabel: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { configureTestSuite } from '../../../util-test/util-expect.spec';

import { PoButtonModule } from '../../po-button/po-button.module';
import { PoCalendarPresetListComponent } from './po-calendar-preset-list.component';
import { PoCalendarRangePreset } from '../interfaces/po-calendar-range-preset.interface';
Expand All @@ -12,7 +10,7 @@ describe('PoCalendarPresetListComponent:', () => {
let fixture: ComponentFixture<PoCalendarPresetListComponent>;
let nativeElement: HTMLElement;

configureTestSuite(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [PoButtonModule],
declarations: [PoCalendarPresetListComponent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<po-calendar-header
(p-previous)="onPreviousMonth()"
(p-next)="onNextMonth()"
[p-disable-previous]="isPreviousMonthDisabled"
[p-disable-next]="isNextMonthDisabled"
[p-display-month]="displayMonth"
[p-display-year]="displayYear"
[p-template-context]="templateContext"
Expand Down Expand Up @@ -53,6 +55,8 @@
<po-calendar-header
(p-previous)="updateYear(-1)"
(p-next)="updateYear(1)"
[p-disable-previous]="isPreviousYearDisabled(1)"
[p-disable-next]="isNextYearDisabled(1)"
[p-template-context]="templateContext"
[p-header-template]="headerTemplate || internalComboTemplate"
[p-size]="size"
Expand Down Expand Up @@ -89,6 +93,8 @@
<po-calendar-header
(p-previous)="updateYear(-10)"
(p-next)="updateYear(10)"
[p-disable-previous]="isPreviousYearDisabled(10)"
[p-disable-next]="isNextYearDisabled(10)"
[p-template-context]="templateContext"
[p-header-template]="headerTemplate || internalComboTemplate"
[p-size]="size"
Expand Down Expand Up @@ -158,6 +164,7 @@
[p-remove-initial-filter]="true"
[ngModel]="combo.year"
[p-options]="combo.yearsOptions"
(p-input-change)="combo.onYearInputChange($event, yearCombo)"
(p-change)="combo.updateDate($event, combo.monthIndex)"
(p-blur)="combo.onComboBlur(yearCombo)"
[p-size]="size"
Expand Down
Loading
Loading