11import { HttpClientTestingModule } from '@angular/common/http/testing' ;
22import { fakeAsync , flush } from '@angular/core/testing' ;
3+ import { By } from '@angular/platform-browser' ;
34import { IconLibraryTestingModule , IconType } from '@hypertrace/assets-library' ;
45import { NavigationService } from '@hypertrace/common' ;
6+ import { IconComponent } from '@hypertrace/components' ;
57import { createHostFactory , mockProvider , SpectatorHost } from '@ngneat/spectator/jest' ;
8+ import { MockComponent } from 'ng-mocks' ;
69import { EMPTY } from 'rxjs' ;
710import { SelectControlOptionPosition } from './select-control-option.component' ;
811import { SelectJustify } from './select-justify' ;
@@ -14,6 +17,7 @@ describe('Select Component', () => {
1417 component : SelectComponent ,
1518 imports : [ SelectModule , HttpClientTestingModule , IconLibraryTestingModule ] ,
1619 declareComponent : false ,
20+ declarations : [ MockComponent ( IconComponent ) ] ,
1721 providers : [
1822 mockProvider ( NavigationService , {
1923 navigation$ : EMPTY ,
@@ -27,7 +31,7 @@ describe('Select Component', () => {
2731 const selectionOptions = [
2832 { label : 'first' , value : 'first-value' } ,
2933 { label : 'second' , value : 'second-value' } ,
30- { label : 'third' , value : 'third-value' , selectedLabel : 'Third Value!!!' }
34+ { label : 'third' , value : 'third-value' , selectedLabel : 'Third Value!!!' , icon : 'test-icon' , iconColor : 'red' }
3135 ] ;
3236
3337 test ( 'should display initial selection' , fakeAsync ( ( ) => {
@@ -146,12 +150,56 @@ describe('Select Component', () => {
146150 const optionElements = spectator . queryAll ( '.select-option' , { root : true } ) ;
147151 spectator . click ( optionElements [ 2 ] ) ;
148152
149- expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
150153 expect ( onChange ) . toHaveBeenCalledWith ( selectionOptions [ 2 ] . value ) ;
151154 expect ( spectator . query ( '.trigger-content' ) ) . toHaveText ( selectionOptions [ 2 ] . selectedLabel ! ) ;
152155 flush ( ) ;
153156 } ) ) ;
154157
158+ test ( 'should set trigger-prefix-icon correctly' , fakeAsync ( ( ) => {
159+ spectator = hostFactory (
160+ `
161+ <ht-select [icon]="icon">
162+ <ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value" [icon]="option.icon" [iconColor]="option.iconColor">
163+ </ht-select-option>
164+ </ht-select>` ,
165+ {
166+ hostProps : {
167+ options : selectionOptions ,
168+ icon : 'select-level-icon'
169+ }
170+ }
171+ ) ;
172+ spectator . tick ( ) ;
173+
174+ // No selection -> select component level icon and no color
175+ expect ( spectator . debugElement . query ( By . css ( '.trigger-prefix-icon' ) ) . componentInstance . icon ) . toBe (
176+ 'select-level-icon'
177+ ) ;
178+ // tslint:disable-next-line:no-null-keyword
179+ expect ( spectator . debugElement . query ( By . css ( '.trigger-prefix-icon' ) ) . componentInstance . color ) . toBe ( null ) ;
180+
181+ // Selection with no icon -> default icon and no color
182+ spectator . click ( '.trigger-content' ) ;
183+ let optionElements = spectator . queryAll ( '.select-option' , { root : true } ) ;
184+ spectator . click ( optionElements [ 1 ] ) ;
185+ spectator . tick ( ) ;
186+ expect ( spectator . debugElement . query ( By . css ( '.trigger-prefix-icon' ) ) . componentInstance . icon ) . toBe (
187+ 'select-level-icon'
188+ ) ;
189+ expect ( spectator . debugElement . query ( By . css ( '.trigger-prefix-icon' ) ) . componentInstance . color ) . toBe ( undefined ) ;
190+
191+ // Selection with icon and color
192+ spectator . click ( '.trigger-content' ) ;
193+ optionElements = spectator . queryAll ( '.select-option' , { root : true } ) ;
194+ spectator . click ( optionElements [ 2 ] ) ;
195+ spectator . tick ( ) ;
196+
197+ expect ( spectator . debugElement . query ( By . css ( '.trigger-prefix-icon' ) ) . componentInstance . icon ) . toBe ( 'test-icon' ) ;
198+ expect ( spectator . debugElement . query ( By . css ( '.trigger-prefix-icon' ) ) . componentInstance . color ) . toBe ( 'red' ) ;
199+
200+ flush ( ) ;
201+ } ) ) ;
202+
155203 test ( 'should set correct label alignment' , fakeAsync ( ( ) => {
156204 spectator = hostFactory (
157205 `
0 commit comments