Skip to content
Merged
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 @@ -381,22 +381,40 @@ describe('PoCheckboxGroupBaseComponent: ', () => {
});

describe('Properties: ', () => {
const trueValues = [true, 'true', 1, '', [], {}];
const falseValues = [false, 'false', 0, null, undefined, NaN];
it('p-disabled: should update with true value.', () => {
component.disabled = true;
expect(component.disabled).toBeTrue();
});

it('p-disabled: should be update with valid and invalid values.', () => {
expectPropertiesValues(component, 'disabled', trueValues, true);
expectPropertiesValues(component, 'disabled', falseValues, false);
it('p-disabled: should update with false value.', () => {
component.disabled = false;
expect(component.disabled).toBeFalse();
});

it('p-indeterminate: should be update with valid and invalid values.', () => {
expectPropertiesValues(component, 'indeterminate', trueValues, true);
expectPropertiesValues(component, 'indeterminate', falseValues, false);
it('p-disabled: should coerce empty string to true via Angular transform', () => {
fixture.componentRef.setInput('p-disabled', '');
fixture.detectChanges();
expect(component.disabled).toBeTrue();
});

it('p-required: should be update with valid and invalid values.', () => {
expectPropertiesValues(component, 'required', trueValues, true);
expectPropertiesValues(component, 'required', falseValues, false);
it('p-indeterminate: should update with true value.', () => {
component.indeterminate = true;
expect(component.indeterminate).toBeTrue();
});

it('p-indeterminate: should update with false value.', () => {
component.indeterminate = false;
expect(component.indeterminate).toBeFalse();
});

it('p-required: should update with true value.', () => {
component.required = true;
expect(component.required).toBeTrue();
});

it('p-required: should update with false value.', () => {
component.required = false;
expect(component.required).toBeFalse();
});

it('p-options: should be update with invalid values.', () => {
Expand Down Expand Up @@ -424,6 +442,7 @@ describe('PoCheckboxGroupBaseComponent: ', () => {
});

it('p-columns: should update property with `6` if invalid value', () => {
const falseValues = [false, 'false', 0, null, undefined, NaN];
expectPropertiesValues(component, 'columns', falseValues, 6);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ export class PoCheckboxGroupBaseComponent implements ControlValueAccessor, Valid
*
* @default `false`
*/
@Input('p-disabled') set disabled(value: boolean) {
this._disabled = convertToBoolean(value);
@Input({ alias: 'p-disabled', transform: convertToBoolean }) set disabled(value: boolean) {
this._disabled = value;

this.validateModel(this.checkIndeterminate());
}
Expand All @@ -322,8 +322,8 @@ export class PoCheckboxGroupBaseComponent implements ControlValueAccessor, Valid
*
* @default `false`
*/
@Input('p-indeterminate') set indeterminate(indeterminate: boolean) {
this._indeterminate = convertToBoolean(indeterminate);
@Input({ alias: 'p-indeterminate', transform: convertToBoolean }) set indeterminate(indeterminate: boolean) {
this._indeterminate = indeterminate;
}

get indeterminate() {
Expand Down Expand Up @@ -356,8 +356,8 @@ export class PoCheckboxGroupBaseComponent implements ControlValueAccessor, Valid
*
* @default `false`
*/
@Input('p-required') set required(required: boolean) {
this._required = convertToBoolean(required);
@Input({ alias: 'p-required', transform: convertToBoolean }) set required(required: boolean) {
this._required = required;

this.validateModel(this.checkIndeterminate());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ describe('PoCheckboxBaseComponent:', () => {

describe('Properties:', () => {
it('disabled: should update with true value', () => {
const booleanValidTrueValues = [true, 'true', 1, ''];

expectPropertiesValues(component, 'disabled', booleanValidTrueValues, true);
component.disabled = true;
expect(component.disabled).toBeTrue();
});

it('disabled: should update with false value', () => {
const booleanInvalidValues = [undefined, null, 2, 'string', 0, NaN, false];
component.disabled = false;
expect(component.disabled).toBeFalse();
});

expectPropertiesValues(component, 'disabled', booleanInvalidValues, false);
it('disabled: should coerce empty string to true via Angular transform', () => {
fixture.componentRef.setInput('p-disabled', '');
fixture.detectChanges();
expect(component.disabled).toBeTrue();
});

it('p-compact-label: should update property with `true` when input is true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ export abstract class PoCheckboxBaseComponent implements ControlValueAccessor {
*
* @default `false`
*/
@Input('p-disabled') set disabled(value: boolean) {
this._disabled = convertToBoolean(value);
@Input({ alias: 'p-disabled', transform: convertToBoolean }) set disabled(value: boolean) {
this._disabled = value;
}

get disabled(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,39 @@ describe('PoComboBaseComponent:', () => {
});

describe('Properties:', () => {
const trueValues = [true, 'true', 1, '', [], {}];
const falseValues = [false, 'false', 0, null, undefined, NaN];

it('p-compact-label: should have default value as false', () => {
expect(component.compactLabel()).toBe(false);
});

it('p-required: should be update with valid and invalid values and call validateModel with selectedValue.', () => {
it('p-required: should update with true value and call validateModel.', () => {
spyOn(component, <any>'validateModel');

expectPropertiesValues(component, 'required', trueValues, true);
expectPropertiesValues(component, 'required', falseValues, false);
component.required = true;
expect(component.required).toBeTrue();
expect(component['validateModel']).toHaveBeenCalledWith(component.selectedValue);
});

it('p-required: should update with false value and call validateModel.', () => {
spyOn(component, <any>'validateModel');

component.required = false;
expect(component.required).toBeFalse();
expect(component['validateModel']).toHaveBeenCalledWith(component.selectedValue);
});

it('p-disabled: should be update with valid and invalid values and call validateModel with selectedValue.', () => {
it('p-disabled: should update with true value and call validateModel.', () => {
spyOn(component, <any>'validateModel');

expectPropertiesValues(component, 'disabled', trueValues, true);
expectPropertiesValues(component, 'disabled', falseValues, false);
component.disabled = true;
expect(component.disabled).toBeTrue();
expect(component['validateModel']).toHaveBeenCalledWith(component.selectedValue);
});

it('p-disabled: should update with false value and call validateModel.', () => {
spyOn(component, <any>'validateModel');

component.disabled = false;
expect(component.disabled).toBeFalse();
expect(component['validateModel']).toHaveBeenCalledWith(component.selectedValue);
});

Expand Down Expand Up @@ -134,12 +145,14 @@ describe('PoComboBaseComponent:', () => {
expect(spycomboListDefinitions).toHaveBeenCalled();
});

it('p-infinite-scroll: should update property `p-infinite-scroll` with false.', () => {
expectPropertiesValues(component, 'infiniteScroll', falseValues, false);
it('p-infinite-scroll: should update property to false.', () => {
component.infiniteScroll = false;
expect(component.infiniteScroll).toBeFalse();
});

it('p-infinite-scroll: should update property `p-infinite-scroll` with true.', () => {
expectPropertiesValues(component, 'infiniteScroll', trueValues, true);
it('p-infinite-scroll: should update property to true.', () => {
component.infiniteScroll = true;
expect(component.infiniteScroll).toBeTrue();
});

it('p-infinite-scroll-distance: should update property `p-infinite-scroll-distance` with valid values .', () => {
Expand Down Expand Up @@ -205,15 +218,14 @@ describe('PoComboBaseComponent:', () => {
});

describe('p-sort: ', () => {
const booleanInvalidValues = [undefined, null, 2, 'string'];
const booleanValidTrueValues = [true, 'true', 1, ''];

it('should update property `p-sort` with valid values.', () => {
expectPropertiesValues(component, 'sort', booleanValidTrueValues, true);
it('should update property `p-sort` to true.', () => {
component.sort = true;
expect(component.sort).toBeTrue();
});

it('should update property `p-sort` with invalid values.', () => {
expectPropertiesValues(component, 'sort', booleanInvalidValues, false);
it('should update property `p-sort` to false.', () => {
component.sort = false;
expect(component.sort).toBeFalse();
});

it('should call `comboListDefinitions`', () => {
Expand Down Expand Up @@ -252,21 +264,6 @@ describe('PoComboBaseComponent:', () => {
expect(component.disabled).toBeTrue();
});

it('should set loading=true when input receives string empty', () => {
component.loading = '' as any;
expect(component.loading).toBeTrue();
});

it('should set loading=false when input receives string "false"', () => {
component.loading = 'false' as any;
expect(component.loading).toBeFalse();
});

it('should set loading=true when input receives string "true"', () => {
component.loading = 'true' as any;
expect(component.loading).toBeTrue();
});

it('should not throw when cd is undefined', () => {
component['cd'] = undefined;
expect(() => (component.loading = true)).not.toThrow();
Expand Down Expand Up @@ -411,16 +408,14 @@ describe('PoComboBaseComponent:', () => {
expectSettersMethod(component, 'filterMode', PoComboFilterMode.endsWith, 'filterMode', PoComboFilterMode.endsWith);
});

it('should update property `p-disabled-init-filter` with false when invalid values', () => {
const invalidValues = [undefined, null, 2, 'string'];

expectPropertiesValues(component, 'disabledInitFilter', invalidValues, false);
it('should update property `p-disabled-init-filter` to false', () => {
component.disabledInitFilter = false;
expect(component.disabledInitFilter).toBeFalse();
});

it('should update property `p-disabled-init-filter` with valid values', () => {
const validValues = [true, 'true', 1, ''];

expectPropertiesValues(component, 'disabledInitFilter', validValues, true);
it('should update property `p-disabled-init-filter` to true', () => {
component.disabledInitFilter = true;
expect(component.disabledInitFilter).toBeTrue();
});

it('should update property `p-filter-minlength` with 0 when invalid values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
*
* @default `false`
*/
@Input('p-infinite-scroll') set infiniteScroll(value: boolean) {
this._infiniteScroll = convertToBoolean(value);
@Input({ alias: 'p-infinite-scroll', transform: convertToBoolean }) set infiniteScroll(value: boolean) {
this._infiniteScroll = value;
}

get infiniteScroll() {
Expand Down Expand Up @@ -323,7 +323,7 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
*
* @default `false`
*/
@Input('p-remove-initial-filter')
@Input({ alias: 'p-remove-initial-filter', transform: convertToBoolean })
set removeInitialFilter(value: boolean) {
this._removeInitialFilter = value;
if (value) {
Expand Down Expand Up @@ -557,8 +557,8 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
* @default `false`
*
*/
@Input('p-disabled-init-filter') set disabledInitFilter(value: boolean) {
this._disabledInitFilter = convertToBoolean(value);
@Input({ alias: 'p-disabled-init-filter', transform: convertToBoolean }) set disabledInitFilter(value: boolean) {
this._disabledInitFilter = value;
}

get disabledInitFilter(): boolean {
Expand Down Expand Up @@ -647,8 +647,8 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
*
* @default `false`
*/
@Input('p-required') set required(required: boolean) {
this._required = convertToBoolean(required);
@Input({ alias: 'p-required', transform: convertToBoolean }) set required(required: boolean) {
this._required = required;

this.validateModel(this.selectedValue);
}
Expand Down Expand Up @@ -698,8 +698,8 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
*
* @default `false`
*/
@Input('p-change-on-enter') set changeOnEnter(changeOnEnter: boolean) {
this._changeOnEnter = convertToBoolean(changeOnEnter);
@Input({ alias: 'p-change-on-enter', transform: convertToBoolean }) set changeOnEnter(changeOnEnter: boolean) {
this._changeOnEnter = changeOnEnter;
}

get changeOnEnter() {
Expand All @@ -714,8 +714,8 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
*
* @default `false`
*/
@Input('p-disabled') set disabled(disabled: boolean) {
this._disabled = convertToBoolean(disabled);
@Input({ alias: 'p-disabled', transform: convertToBoolean }) set disabled(disabled: boolean) {
this._disabled = disabled;

this.validateModel(this.selectedValue);
}
Expand All @@ -733,9 +733,9 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
* @default `false`
*/
@HostBinding('attr.p-loading')
@Input('p-loading')
@Input({ alias: 'p-loading', transform: convertToBoolean })
set loading(value: boolean) {
this._loading = convertToBoolean(value);
this._loading = value;
this.changeDetector?.markForCheck();
}

Expand All @@ -748,8 +748,8 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
}

/** Indica que a lista definida na propriedade p-options será ordenada pela descrição. */
@Input('p-sort') set sort(sort: boolean) {
this._sort = convertToBoolean(sort);
@Input({ alias: 'p-sort', transform: convertToBoolean }) set sort(sort: boolean) {
this._sort = sort;
this.comboListDefinitions();
}

Expand Down
Loading
Loading