@@ -82,6 +82,7 @@ class UiSuggestFixtureDirective {
82
82
readonly ?: boolean ;
83
83
enableCustomValue ?: boolean ;
84
84
items ?: ISuggestValue [ ] ;
85
+ headerItems ?: ISuggestValue [ ] ;
85
86
displayTemplateValue ?: boolean ;
86
87
direction : 'up' | 'down' = 'down' ;
87
88
displayPriority : 'default' | 'selected' = 'default' ;
@@ -287,14 +288,14 @@ const sharedSpecifications = (
287
288
expect ( itemListEntries . length ) . toEqual ( 0 ) ;
288
289
} ) ;
289
290
290
- it ( 'should render the list open and not close on selection if alwaysExpanded is true' , ( async ( ) => {
291
+ it ( 'should render the list open and not close on selection if alwaysExpanded is true' , ( fakeAsync ( ( ) => {
291
292
const items = generateSuggetionItemList ( 10 ) ;
292
293
293
294
component . alwaysExpanded = true ;
294
295
component . items = items ;
295
296
296
297
fixture . detectChanges ( ) ;
297
- await fixture . whenStable ( ) ;
298
+ tick ( 400 ) ;
298
299
299
300
const itemListEntries = fixture . debugElement . queryAll ( By . css ( '.mat-list-item' ) ) ;
300
301
@@ -308,10 +309,11 @@ const sharedSpecifications = (
308
309
309
310
currentListItem . nativeElement . dispatchEvent ( EventGenerator . click ) ;
310
311
fixture . detectChanges ( ) ;
312
+ tick ( 400 ) ;
311
313
312
314
expect ( itemListEntries ) . not . toBeNull ( ) ;
313
315
expect ( itemListEntries . length ) . toEqual ( items . length ) ;
314
- } ) ) ;
316
+ } ) ) ) ;
315
317
316
318
it ( 'should filter items if typed into' , ( done ) => {
317
319
let items = generateSuggetionItemList ( 40 ) ;
@@ -1321,6 +1323,66 @@ const sharedSpecifications = (
1321
1323
} ) ;
1322
1324
} ) ;
1323
1325
1326
+ describe ( 'Behavior: headerItems' , ( ) => {
1327
+ it ( 'should not work with custom value enabled' , ( ) => {
1328
+ const error = new Error ( 'enableCustomValue and headerItems are mutually exclusive options' ) ;
1329
+ component . enableCustomValue = true ;
1330
+
1331
+ expect ( ( ) => {
1332
+ component . headerItems = generateSuggetionItemList ( 5 ) ;
1333
+ fixture . detectChanges ( ) ;
1334
+ } ) . toThrow ( error ) ;
1335
+ } ) ;
1336
+
1337
+ it ( 'should display header items & fetched data in list' , fakeAsync ( ( ) => {
1338
+ const items = generateSuggetionItemList ( 10 ) ;
1339
+ const headerItems = items . slice ( 0 , 5 ) ;
1340
+ const regularItems = items . slice ( 5 , 10 ) ;
1341
+
1342
+ component . alwaysExpanded = true ;
1343
+ component . items = regularItems ;
1344
+ component . headerItems = headerItems ;
1345
+
1346
+ fixture . detectChanges ( ) ;
1347
+ tick ( 1000 ) ;
1348
+
1349
+ const itemListEntries = fixture . debugElement . queryAll ( By . css ( '.mat-list-item' ) ) ;
1350
+
1351
+ expect ( itemListEntries ) . not . toBeNull ( ) ;
1352
+ expect ( itemListEntries . length ) . toEqual ( items . length ) ;
1353
+ itemListEntries . forEach ( ( entry , idx ) => {
1354
+ expect ( entry . nativeElement . innerText ) . toBe ( items [ idx ] . text ) ;
1355
+ } ) ;
1356
+ } ) ) ;
1357
+
1358
+ it ( 'should hide elements on search' , fakeAsync ( ( ) => {
1359
+ const items = generateSuggetionItemList ( 10 , 'Item' ) ;
1360
+ const headerItems = items . slice ( 0 , 5 ) ;
1361
+ const regularItems = items . slice ( 5 , 10 ) ;
1362
+
1363
+ component . alwaysExpanded = true ;
1364
+ component . items = regularItems ;
1365
+ component . headerItems = headerItems ;
1366
+ component . searchable = true ;
1367
+
1368
+ fixture . detectChanges ( ) ;
1369
+ tick ( 1000 ) ;
1370
+
1371
+ searchFor ( 'Item' , fixture ) ;
1372
+
1373
+ fixture . detectChanges ( ) ;
1374
+ tick ( 1000 ) ;
1375
+
1376
+ const itemListEntries = fixture . debugElement . queryAll ( By . css ( '.mat-list-item' ) ) ;
1377
+
1378
+ expect ( itemListEntries ) . not . toBeNull ( ) ;
1379
+ expect ( itemListEntries . length ) . toEqual ( regularItems . length ) ;
1380
+ itemListEntries . forEach ( ( entry , idx ) => {
1381
+ expect ( entry . nativeElement . innerText ) . toBe ( regularItems [ idx ] . text ) ;
1382
+ } ) ;
1383
+ } ) ) ;
1384
+ } ) ;
1385
+
1324
1386
describe ( 'Selection: single value' , ( ) => {
1325
1387
it ( 'should have one list item entry for each item provided' , waitForAsync ( async ( ) => {
1326
1388
fixture . detectChanges ( ) ;
@@ -2324,6 +2386,7 @@ describe('Component: UiSuggest', () => {
2324
2386
[searchable]="searchable"
2325
2387
[enableCustomValue]="enableCustomValue"
2326
2388
[alwaysExpanded]="alwaysExpanded"
2389
+ [headerItems]="headerItems"
2327
2390
[items]="items"
2328
2391
[value]="value"
2329
2392
[direction]="direction"
@@ -2403,6 +2466,7 @@ describe('Component: UiSuggest', () => {
2403
2466
[clearable]="clearable"
2404
2467
[searchable]="searchable"
2405
2468
[enableCustomValue]="enableCustomValue"
2469
+ [headerItems]="headerItems"
2406
2470
[alwaysExpanded]="alwaysExpanded"
2407
2471
[items]="items"
2408
2472
[direction]="direction"
@@ -2592,6 +2656,7 @@ describe('Component: UiSuggest', () => {
2592
2656
[searchable]="searchable"
2593
2657
[enableCustomValue]="enableCustomValue"
2594
2658
[alwaysExpanded]="alwaysExpanded"
2659
+ [headerItems]="headerItems"
2595
2660
[items]="items"
2596
2661
[value]="value"
2597
2662
[direction]="direction"
0 commit comments