Skip to content

Commit c710527

Browse files
jcorrea97rafaellmarques
authored andcommitted
feat(combo): implementa definições do AnimaliaDS
Implementa definições do AnimaliaDS no Breadcrumb fixes DTHFUI-7500
1 parent f78548e commit c710527

File tree

7 files changed

+220
-56
lines changed

7 files changed

+220
-56
lines changed

projects/ui/src/lib/components/po-field/po-combo/interfaces/po-combo-literals-default.interface.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import { PoComboLiterals } from './po-combo-literals.interface';
33
export const poComboLiteralsDefault = {
44
en: <PoComboLiterals>{
55
noData: 'No data found',
6-
chooseOption: 'Choose an option'
6+
chooseOption: 'Choose an option',
7+
clear: 'Clear'
78
},
89
es: <PoComboLiterals>{
910
noData: 'Datos no encontrados',
10-
chooseOption: 'Elija una opción'
11+
chooseOption: 'Elija una opción',
12+
clear: 'limpia'
1113
},
1214
pt: <PoComboLiterals>{
1315
noData: 'Nenhum dado encontrado',
14-
chooseOption: 'Escolha uma opção'
16+
chooseOption: 'Escolha uma opção',
17+
clear: 'Apagar'
1518
},
1619
ru: <PoComboLiterals>{
1720
noData: 'Данные не найдены',
18-
chooseOption: 'Выберите опцию'
21+
chooseOption: 'Выберите опцию',
22+
clear: 'чистый'
1923
}
2024
};

projects/ui/src/lib/components/po-field/po-combo/interfaces/po-combo-literals.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ export interface PoComboLiterals {
1111

1212
/** Texto exibido quando o combo estiver vazio. */
1313
chooseOption?: string;
14+
15+
/** Texto do aria-label do botão de limpar */
16+
clean?: string;
1417
}

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.html

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
[p-required]="required"
77
[p-show-required]="showRequired"
88
>
9-
<div cdkOverlayOrigin #trigger="cdkOverlayOrigin" class="po-field-container-content">
9+
<div cdkOverlayOrigin #trigger="cdkOverlayOrigin" class="po-field-container-content po-combo-container-content">
1010
<div *ngIf="icon" class="po-field-icon-container-left">
1111
<po-icon class="po-field-icon po-icon-input" [class.po-field-icon-disabled]="disabled" [p-icon]="icon"></po-icon>
1212
</div>
1313

1414
<input
1515
#inp
16-
class="po-input po-combo-input"
16+
class="po-combo-input"
1717
[ngClass]="clean && inp.value ? 'po-input-double-icon-right' : 'po-input-icon-right'"
1818
[class.po-input-icon-left]="icon"
1919
autocomplete="off"
@@ -26,24 +26,35 @@
2626
(click)="toggleComboVisibility()"
2727
(keyup)="onKeyUp($event)"
2828
(blur)="onBlur()"
29-
(keyup.enter)="searchOnEnter($event.target.value)"
29+
(keyup)="searchOnEnterOrArrow($event, $event.target.value)"
3030
(keydown)="onKeyDown($event)"
3131
/>
3232

3333
<div class="po-field-icon-container-right">
34-
<po-clean
35-
class="po-icon-input"
36-
*ngIf="clean && !disabled"
37-
(p-change-event)="clear($event)"
38-
[p-element-ref]="inputEl"
34+
<div
35+
tabindex="0"
36+
role="button"
37+
[attr.aria-label]="literals.clean"
38+
*ngIf="clean && !disabled && inp.value"
39+
class="po-combo-clean"
40+
(click)="clear(null); $event.preventDefault()"
41+
(keydown.enter)="clearAndFocus(); $event.preventDefault()"
3942
>
40-
</po-clean>
43+
<span
44+
[class.po-border-focused]="!disabled && comboOpen"
45+
class="po-icon po-field-icon po-icon-clear-content"
46+
></span>
47+
</div>
4148
<span
4249
#iconArrow
43-
class="po-icon po-field-icon {{ comboIcon }} po-icon-input"
50+
class="po-icon po-field-icon po-icon-input"
4451
[class.po-field-icon-disabled]="disabled"
52+
[class.po-icon-arrow-up]="comboOpen"
53+
[class.po-icon-arrow-down]="!comboOpen"
4554
[class.po-field-icon]="!disabled"
46-
(click)="toggleComboVisibility()"
55+
[class.po-combo-default-border]="!disabled && inp.value"
56+
[class.po-combo-background-arrow-up]="!disabled && comboOpen"
57+
(click)="toggleComboVisibility(true)"
4758
>
4859
</span>
4960
</div>

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts

Lines changed: 113 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('PoComboComponent:', () => {
9292
component.isProcessingValueByTab = false;
9393
spyOn(component, 'applyFilter');
9494
component.controlApplyFilter('valor');
95-
expect(component.applyFilter).toHaveBeenCalledWith('valor', true);
95+
expect(component.applyFilter).toHaveBeenCalledWith('valor', true, undefined);
9696
});
9797

9898
it('shouldn`t call apply filter when is processing "getObjectByValue"', () => {
@@ -208,9 +208,9 @@ describe('PoComboComponent:', () => {
208208
spyOn(component, 'controlComboVisibility');
209209
component.comboOpen = true;
210210
component.disabled = false;
211-
212-
component.toggleComboVisibility();
213-
expect(component.controlComboVisibility).toHaveBeenCalledWith(false);
211+
fixture.detectChanges();
212+
component.toggleComboVisibility(false);
213+
expect(component.controlComboVisibility).toHaveBeenCalledWith(false, false, false);
214214
});
215215

216216
it('should call applyFilterInFirstClick', () => {
@@ -571,12 +571,8 @@ describe('PoComboComponent:', () => {
571571
focus: () => {}
572572
}
573573
};
574-
component.poListbox = {
575-
setFocus: () => {}
576-
} as any;
577574

578575
spyOn(component.contentElement.nativeElement, 'focus');
579-
spyOn(component.poListbox, 'setFocus');
580576
component.visibleOptions = [{ value: 'item 1', label: 'item 1' }];
581577
component.comboOpen = true;
582578
component.changeOnEnter = true;
@@ -586,15 +582,13 @@ describe('PoComboComponent:', () => {
586582

587583
expect(component.controlComboVisibility).toHaveBeenCalledWith(true);
588584
expect(component.isFiltering).toBe(false);
589-
expect(component.poListbox.setFocus).toHaveBeenCalled();
590585
});
591586

592587
it('shouldn`t call `selectNextOption` and call `controlComboVisibility` if `comboOpen` with false', () => {
593588
const event = { ...fakeEvent, keyCode: 40 };
594589

595590
component.comboOpen = false;
596591
component.visibleOptions = [{ value: '1', label: '1' }];
597-
598592
spyOn(component, 'controlComboVisibility');
599593

600594
component.onKeyDown(event);
@@ -683,6 +677,36 @@ describe('PoComboComponent:', () => {
683677
expect(component.updateComboList).toHaveBeenCalled();
684678
});
685679

680+
it('should call `clear` if esc is double clicked', () => {
681+
const event = { ...fakeEvent, keyCode: 27 };
682+
683+
component.service = undefined;
684+
component.selectedValue = 'Test1';
685+
component.comboOpen = true;
686+
component['lastKey'] = 27;
687+
688+
spyOn(component, 'clearAndFocus');
689+
690+
component.onKeyDown(event);
691+
692+
expect(component.clearAndFocus).toHaveBeenCalled();
693+
});
694+
695+
it('should call `onCloseCombo` if esc is clicked', () => {
696+
const event = { ...fakeEvent, keyCode: 27 };
697+
698+
component.service = undefined;
699+
component.selectedValue = 'Test1';
700+
component.comboOpen = true;
701+
component['lastKey'] = 20;
702+
703+
spyOn(component, 'onCloseCombo');
704+
705+
component.onKeyDown(event);
706+
707+
expect(component.onCloseCombo).toHaveBeenCalled();
708+
});
709+
686710
it('shouldn`t call `updateComboList` if itens service is not undefined', () => {
687711
const event = { ...fakeEvent, keyCode: 13 };
688712

@@ -724,6 +748,16 @@ describe('PoComboComponent:', () => {
724748
expect(component.inputEl.nativeElement.focus).toHaveBeenCalled();
725749
});
726750

751+
it('should call inputEl.nativeElement and clear', () => {
752+
spyOn(component.inputEl.nativeElement, 'focus');
753+
spyOn(component, 'clear');
754+
755+
component.clearAndFocus();
756+
757+
expect(component.inputEl.nativeElement.focus).toHaveBeenCalled();
758+
expect(component.clear).toHaveBeenCalled();
759+
});
760+
727761
it('onOptionClick: should call `stopPropagation` if has an event parameter', () => {
728762
const option: PoComboOption = { value: 'value', label: 'label' };
729763

@@ -949,6 +983,22 @@ describe('PoComboComponent:', () => {
949983
expect(component.comboOpen).toBe(true);
950984
});
951985

986+
it('should open the input element', () => {
987+
const focusSpy = spyOn(component.inputEl.nativeElement, 'focus');
988+
989+
component['open'](true);
990+
991+
expect(focusSpy).toHaveBeenCalled();
992+
});
993+
994+
it('should add class to input element when isButton is true', () => {
995+
const addClassSpy = spyOn(component.renderer, 'addClass');
996+
997+
component['open'](false, true);
998+
999+
expect(addClassSpy).toHaveBeenCalledWith(component.inputEl.nativeElement, 'po-combo-input-focus');
1000+
});
1001+
9521002
it('open: should set page and options when has inifity scroll', () => {
9531003
component.infiniteScroll = true;
9541004
spyOn(component, 'getInputValue').and.returnValue(undefined);
@@ -1156,18 +1206,19 @@ describe('PoComboComponent:', () => {
11561206
it('should show po-clean if `clean` is true and `disabled` is false', () => {
11571207
component.clean = true;
11581208
component.disabled = false;
1209+
component.inputEl.nativeElement.value = 'Test';
11591210

11601211
fixture.detectChanges();
11611212

1162-
expect(nativeElement.querySelector('po-clean')).toBeTruthy();
1213+
expect(nativeElement.querySelector('.po-combo-clean')).toBeTruthy();
11631214
});
11641215

11651216
it('shouldn`t show po-clean if `clean` is true and `disabled` is true', () => {
11661217
component.clean = true;
11671218
component.disabled = true;
11681219

11691220
fixture.detectChanges();
1170-
expect(nativeElement.querySelector('po-clean')).toBe(null);
1221+
expect(nativeElement.querySelector('.po-combo-clean')).toBe(null);
11711222
});
11721223

11731224
it('shouldn`t show po-clean if `clean` is false', () => {
@@ -1316,11 +1367,14 @@ describe('PoComboComponent - with service:', () => {
13161367
it('applyFilter: should call PoComboFilterService.getFilteredData() with param and filterParams', () => {
13171368
const filterParams = 'filter';
13181369
const applyFilterValue = 'value';
1370+
const isArrowDown = true;
13191371
const param = { property: 'label', value: applyFilterValue };
13201372
const fakeThis: any = {
13211373
controlComboVisibility: () => {},
13221374
setOptionsByApplyFilter: () => {},
1375+
focusItem: () => {},
13231376
fieldLabel: 'label',
1377+
isArrowDown: true,
13241378
filterParams: filterParams,
13251379
service: {
13261380
getFilteredData: () => {}
@@ -1332,11 +1386,23 @@ describe('PoComboComponent - with service:', () => {
13321386

13331387
spyOn(fakeThis.service, 'getFilteredData').and.returnValue({ subscribe: callback => callback() });
13341388

1335-
component.applyFilter.apply(fakeThis, [applyFilterValue]);
1389+
component.applyFilter.apply(fakeThis, [applyFilterValue, isArrowDown]);
13361390

13371391
expect(fakeThis.service.getFilteredData).toHaveBeenCalledWith(param, filterParams);
13381392
});
13391393

1394+
it('applyFilter: should call focusItem if param `isArrowDown` is true', () => {
1395+
spyOn(component.service, 'getFilteredData').and.returnValue(of([{ value: 'test' }]));
1396+
spyOn(component, 'setOptionsByApplyFilter');
1397+
spyOn(component, <any>'focusItem');
1398+
1399+
component.defaultService.hasNext = true;
1400+
component.applyFilter('test', false, true);
1401+
1402+
expect(component.setOptionsByApplyFilter).toHaveBeenCalled();
1403+
expect(component['focusItem']).toHaveBeenCalled();
1404+
});
1405+
13401406
it('applyFilter: shouldn´t call PoComboFilterService.getFilteredData() if hasNext is false', () => {
13411407
const filterParams = 'filter';
13421408
const applyFilterValue = 'value';
@@ -1539,49 +1605,60 @@ describe('PoComboComponent - with service:', () => {
15391605
expect(component['initInputObservable']).not.toHaveBeenCalled();
15401606
});
15411607

1542-
it(`searchOnEnter: should call 'controlApplyFilter' if has a service,
1608+
it(`searchOnEnterOrArrow: should call 'controlApplyFilter' if has a service,
15431609
not has selectedView and value.length is greater than 'filterMinlength'`, () => {
15441610
const value = 'newValue';
1611+
const event = {
1612+
key: 'Enter'
1613+
};
15451614
component.selectedView = undefined;
15461615
component.filterMinlength = 2;
15471616

15481617
spyOn(component, 'controlApplyFilter');
15491618

1550-
component.searchOnEnter(value);
1619+
component.searchOnEnterOrArrow(event, value);
15511620

1552-
expect(component.controlApplyFilter).toHaveBeenCalledWith(value);
1621+
expect(component.controlApplyFilter).toHaveBeenCalledWith(value, false);
15531622
});
15541623

1555-
it(`searchOnEnter: shouldn't call 'controlApplyFilter' if has a service and has selectedView`, () => {
1624+
it(`searchOnEnterOrArrow: shouldn't call 'controlApplyFilter' if has a service and has selectedView`, () => {
15561625
const value = 'value';
15571626
component.selectedView = { label: 'Option 1', value: '1' };
1558-
1627+
const event = {
1628+
key: 'Enter'
1629+
};
15591630
spyOn(component, 'controlApplyFilter');
15601631

1561-
component.searchOnEnter(value);
1632+
component.searchOnEnterOrArrow(event, value);
15621633

15631634
expect(component.controlApplyFilter).not.toHaveBeenCalled();
15641635
});
15651636

1566-
it(`searchOnEnter: shouldn't call 'controlApplyFilter' if doesn't have a service`, () => {
1637+
it(`searchOnEnterOrArrow: shouldn't call 'controlApplyFilter' if doesn't have a service`, () => {
15671638
const value = 'value';
15681639
component.service = undefined;
1640+
const event = {
1641+
key: 'Enter'
1642+
};
15691643

15701644
spyOn(component, 'controlApplyFilter');
15711645

1572-
component.searchOnEnter(value);
1646+
component.searchOnEnterOrArrow(event, value);
15731647

15741648
expect(component.controlApplyFilter).not.toHaveBeenCalled();
15751649
});
15761650

1577-
it(`searchOnEnter: shouldn't call 'controlApplyFilter' if value.length is less than 'filterMinlength'`, () => {
1651+
it(`searchOnEnterOrArrow: shouldn't call 'controlApplyFilter' if value.length is less than 'filterMinlength'`, () => {
15781652
const value = 'value';
15791653
component.selectedView = { label: 'Option 1', value: '1' };
15801654
component.filterMinlength = 8;
1655+
const event = {
1656+
key: 'Enter'
1657+
};
15811658

15821659
spyOn(component, 'controlApplyFilter');
15831660

1584-
component.searchOnEnter(value);
1661+
component.searchOnEnterOrArrow(event, value);
15851662

15861663
expect(component.controlApplyFilter).not.toHaveBeenCalled();
15871664
});
@@ -1719,6 +1796,19 @@ describe('PoComboComponent - with service:', () => {
17191796

17201797
expect(component.visibleOptions).toEqual(mockOptions);
17211798
});
1799+
1800+
it('should focus on the listbox item when selectedValue is true', fakeAsync(() => {
1801+
const listboxItem = document.createElement('div');
1802+
listboxItem.setAttribute('aria-selected', 'true');
1803+
spyOn(document, 'querySelector').and.returnValue(listboxItem);
1804+
1805+
const focusSpy = spyOn(listboxItem, 'focus');
1806+
1807+
component.selectedValue = true;
1808+
component['focusItem']();
1809+
tick(100);
1810+
expect(focusSpy).toHaveBeenCalled();
1811+
}));
17221812
});
17231813
});
17241814

0 commit comments

Comments
 (0)