Skip to content

Commit 9ff2721

Browse files
CarlosAlmeida01alinelariguet
authored andcommitted
feat(po-dynamic-view): aprimora exibição de booleans
1 parent 43f3186 commit 9ff2721

File tree

3 files changed

+74
-23
lines changed

3 files changed

+74
-23
lines changed

projects/ui/src/lib/components/po-dynamic/po-dynamic-view/po-dynamic-view-field.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,10 @@ export interface PoDynamicViewField extends PoDynamicField {
230230
* [guia de API do PO UI](https://po-ui.io/guides/api).
231231
*/
232232
searchService?: string | PoDynamicViewRequest;
233+
234+
/** Texto exibido quando o valor do componente for *true*. */
235+
booleanTrue?: string;
236+
237+
/** Texto exibido quando o valor do componente for *false*. */
238+
booleanFalse?: string;
233239
}

projects/ui/src/lib/components/po-dynamic/po-dynamic-view/po-dynamic-view.component.spec.ts

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,32 +247,75 @@ describe('PoDynamicViewComponent:', () => {
247247
expect(component['getVisibleFields']).toHaveBeenCalled();
248248
});
249249

250-
it(`setFieldValue: should return the label of the selected option if options exist and a match is found`, () => {
251-
const field = {
252-
value: 'value1',
253-
options: [
254-
{ value: 'value1', label: 'label1' },
255-
{ value: 'value2', label: 'label2' },
256-
{ value: 'value3', label: 'label3' }
257-
]
258-
};
250+
describe('setFieldValue:', () => {
251+
it(`should return the label of the selected option if options exist and a match is found`, () => {
252+
const field = {
253+
value: 'value1',
254+
options: [
255+
{ value: 'value1', label: 'label1' },
256+
{ value: 'value2', label: 'label2' },
257+
{ value: 'value3', label: 'label3' }
258+
]
259+
};
260+
261+
field.value = 'value2';
262+
expect(component.setFieldValue(field)).toEqual('label2');
263+
});
259264

260-
field.value = 'value2';
261-
expect(component.setFieldValue(field)).toEqual('label2');
262-
});
265+
it(`should return the field value if options exist but no match is found'`, () => {
266+
const field = {
267+
value: 'value1',
268+
options: [
269+
{ value: 'value1', label: 'label1' },
270+
{ value: 'value2', label: 'label2' },
271+
{ value: 'value3', label: 'label3' }
272+
]
273+
};
274+
275+
field.value = 'value4';
276+
expect(component.setFieldValue(field)).toEqual('value4');
277+
});
278+
it('should return the value of booleanTrue when the field value is true', () => {
279+
const field = {
280+
property: 'active',
281+
type: 'boolean',
282+
value: true,
283+
booleanTrue: 'Ativo',
284+
booleanFalse: 'Inativo'
285+
};
286+
expect(component.setFieldValue(field)).toEqual('Ativo');
287+
});
263288

264-
it(`setFieldValue: should return the field value if options exist but no match is found'`, () => {
265-
const field = {
266-
value: 'value1',
267-
options: [
268-
{ value: 'value1', label: 'label1' },
269-
{ value: 'value2', label: 'label2' },
270-
{ value: 'value3', label: 'label3' }
271-
]
272-
};
289+
it('should return the value of booleanFalse when the field value is false', () => {
290+
const field = {
291+
property: 'active',
292+
type: 'boolean',
293+
value: false,
294+
booleanTrue: 'Ativo',
295+
booleanFalse: 'Inativo'
296+
};
297+
expect(component.setFieldValue(field)).toEqual('Inativo');
298+
});
273299

274-
field.value = 'value4';
275-
expect(component.setFieldValue(field)).toEqual('value4');
300+
it('should return "True" when the field value is true and booleanTrue is undefined', () => {
301+
const field = {
302+
property: 'active',
303+
type: 'boolean',
304+
value: true,
305+
booleanFalse: 'Inativo'
306+
};
307+
expect(component.setFieldValue(field)).toEqual(true);
308+
});
309+
310+
it('should return "False" when the field value is false and booleanFalse is undefined', () => {
311+
const field = {
312+
property: 'active',
313+
type: 'boolean',
314+
value: false,
315+
booleanTrue: 'Ativo'
316+
};
317+
expect(component.setFieldValue(field)).toEqual(false);
318+
});
276319
});
277320
});
278321

projects/ui/src/lib/components/po-dynamic/po-dynamic-view/po-dynamic-view.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export class PoDynamicViewComponent extends PoDynamicViewBaseComponent implement
6666
if (field.options) {
6767
const selectedOption = field.options.find(option => option.value === field.value);
6868
return selectedOption ? selectedOption.label : field.value;
69+
} else if (field.type === 'boolean' && 'booleanTrue' in field && 'booleanFalse' in field) {
70+
return field.value ? field.booleanTrue : field.booleanFalse;
6971
} else {
7072
return field.value;
7173
}

0 commit comments

Comments
 (0)