11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
22
3+ import { HarnessLoader } from '@angular/cdk/testing' ;
4+ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
35import { HttpHandler , provideHttpClient } from '@angular/common/http' ;
6+ import { MatSelectHarness } from '@angular/material/select/testing' ;
47import { By } from '@angular/platform-browser' ;
58import { PostService } from '../../service/rest/post/post.service' ;
69import { SearchComponent } from './search.component' ;
710
811describe ( 'SearchComponent' , ( ) => {
912 let component : SearchComponent ;
1013 let fixture : ComponentFixture < SearchComponent > ;
14+ let loader : HarnessLoader ;
1115
1216 beforeEach ( async ( ) => {
1317 await TestBed . configureTestingModule ( {
@@ -18,46 +22,47 @@ describe('SearchComponent', () => {
1822 fixture = TestBed . createComponent ( SearchComponent ) ;
1923 component = fixture . componentInstance ;
2024 fixture . detectChanges ( ) ;
25+ loader = TestbedHarnessEnvironment . loader ( fixture ) ;
2126 } ) ;
2227
2328 it ( 'should create' , ( ) => {
2429 expect ( component ) . toBeTruthy ( ) ;
2530 } ) ;
2631
27- it ( 'should ensure default state on creation' , ( ) => {
28- const searchBy : HTMLElement = fixture . debugElement . query (
29- By . css ( '#search-by' )
30- ) . nativeElement ;
32+ it ( 'should ensure default state on creation' , async ( ) => {
3133 const searchText = fixture . debugElement . query (
3234 By . css ( '#search-text' )
3335 ) . nativeElement ;
3436 const searchButton = fixture . debugElement . query (
3537 By . css ( '#search' )
3638 ) . nativeElement ;
3739
38- expect ( searchBy . getAttribute ( 'ng-reflect-value' ) ) . toBe ( 'All' ) ;
40+ const selectHarness = await loader . getHarness ( MatSelectHarness ) ;
41+ const selectedValue = await selectHarness . getValueText ( ) ;
42+
43+ expect ( selectedValue ) . toBe ( 'All' ) ;
3944 expect ( searchText . disabled ) . toBeTrue ( ) ;
4045 expect ( searchButton . disabled ) . toBeFalse ( ) ;
4146 } ) ;
4247
43- it ( 'should ensure correct state on selection change' , ( ) => {
48+ it ( 'should ensure correct state on selection change' , async ( ) => {
4449 // Change selection value
4550 component . selected = 'Id' ;
4651 component . onSelectionChanged ( component . selected ) ;
4752
4853 fixture . detectChanges ( ) ;
4954
50- const searchBy : HTMLElement = fixture . debugElement . query (
51- By . css ( '#search-by' )
52- ) . nativeElement ;
5355 const searchText = fixture . debugElement . query (
5456 By . css ( '#search-text' )
5557 ) . nativeElement ;
5658 const searchButton = fixture . debugElement . query (
5759 By . css ( '#search' )
5860 ) . nativeElement ;
5961
60- expect ( searchBy . getAttribute ( 'ng-reflect-value' ) ) . toBe ( 'Id' ) ;
62+ const selectHarness = await loader . getHarness ( MatSelectHarness ) ;
63+ const selectedValue = await selectHarness . getValueText ( ) ;
64+
65+ expect ( selectedValue ) . toBe ( 'Id' ) ;
6166 expect ( searchText . disabled ) . toBeFalse ( ) ;
6267 expect ( searchButton . disabled ) . toBeTrue ( ) ;
6368
0 commit comments