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 @@ -330,5 +330,98 @@ describe('PoCalendarBaseComponent:', () => {
expect((component as any).applySizeBasedOnA11y).toHaveBeenCalled();
});
});

describe('p-year-range:', () => {
it('should set yearRange with valid positive value', () => {
component.yearRange = 100;
expect(component.yearRange).toBe(100);
});

it('should default to 150 when value is 0', () => {
component.yearRange = 0;
expect(component.yearRange).toBe(150);
});

it('should default to 150 when value is negative', () => {
component.yearRange = -10;
expect(component.yearRange).toBe(150);
});

it('should default to 150 when value is null', () => {
component.yearRange = null;
expect(component.yearRange).toBe(150);
});

it('should default to 150 when value is undefined', () => {
component.yearRange = undefined;
expect(component.yearRange).toBe(150);
});
});

describe('isMonthYear:', () => {
it('should return true when mode is MonthYear', () => {
component['_mode'] = PoCalendarMode.MonthYear;
expect(component.isMonthYear).toBeTrue();
});

it('should return false when mode is Range', () => {
component['_mode'] = PoCalendarMode.Range;
expect(component.isMonthYear).toBeFalse();
});

it('should return false when mode is undefined', () => {
component['_mode'] = undefined;
expect(component.isMonthYear).toBeFalse();
});
});

describe('isYearOnly:', () => {
it('should return true when mode is Year', () => {
component['_mode'] = PoCalendarMode.Year;
expect(component.isYearOnly).toBeTrue();
});

it('should return false when mode is MonthYear', () => {
component['_mode'] = PoCalendarMode.MonthYear;
expect(component.isYearOnly).toBeFalse();
});

it('should return false when mode is Range', () => {
component['_mode'] = PoCalendarMode.Range;
expect(component.isYearOnly).toBeFalse();
});
});

describe('p-range-presets:', () => {
it('should accept boolean true', () => {
component.rangePresets = true;
expect(component.rangePresets).toBeTrue();
});

it('should accept string "true"', () => {
component.rangePresets = 'true';
expect(component.rangePresets).toBeTrue();
});

it('should accept empty string as true', () => {
component.rangePresets = '';
expect(component.rangePresets).toBeTrue();
});

it('should accept boolean false', () => {
component.rangePresets = false;
expect(component.rangePresets).toBeFalse();
});

it('should accept array of strings', () => {
component.rangePresets = ['today', '7days'];
expect(component.rangePresets).toEqual(['today', '7days']);
});

it('should set to false for invalid values', () => {
component.rangePresets = 'invalid' as any;
expect(component.rangePresets).toBeFalse();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class PoCalendarBaseComponent {
private _mode: PoCalendarMode;
private _size?: string;
private _initialSize?: string;
private _yearRange: number = 150;

/**
* @optional
Expand Down Expand Up @@ -243,9 +244,34 @@ export class PoCalendarBaseComponent {
return this.mode === PoCalendarMode.Range;
}

get isMonthYear() {
return this.mode === PoCalendarMode.MonthYear;
}

get isYearOnly() {
return this.mode === PoCalendarMode.Year;
}

// Propriedade que permite integrar o po-combo no componente de calendar. Implementa o template de header com `PoCombo`.
@Input('p-header-template') headerTemplate?: TemplateRef<any>;

/**
* @optional
*
* @description
*
* Define o intervalo de anos exibidos nas variações `MonthYear` e `Year`.
* O valor representa a quantidade de anos anteriores e posteriores ao ano atual.
*
* @default `150`
*/
@Input('p-year-range') set yearRange(value: number) {
this._yearRange = value && value > 0 ? value : 150;
}
get yearRange(): number {
return this._yearRange;
}

/**
* @optional
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
*/
export enum PoCalendarMode {
/** Modo de seleção de intervalo (data inicial e final). */
Range = 'range'
Range = 'range',

/** Modo de seleção de mês e ano. */
MonthYear = 'monthYear',

/** Modo de seleção apenas de ano. */
Year = 'year'
}
Loading
Loading