@@ -13,30 +13,36 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
==============================================================================*/
15
15
import { TestBed } from '@angular/core/testing' ;
16
+ import { HarnessLoader } from '@angular/cdk/testing' ;
17
+ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
16
18
import { DataTableModule } from './data_table_module' ;
17
19
import { FilterDialog } from './filter_dialog_component' ;
18
20
import { DiscreteFilter , DomainType , IntervalFilter } from './types' ;
19
21
import { By } from '@angular/platform-browser' ;
20
22
import { RangeInputComponent } from '../range_input/range_input_component' ;
21
23
import { RangeInputModule } from '../range_input/range_input_module' ;
22
- import { MatLegacyCheckboxModule } from '@angular/material/legacy-checkbox' ;
24
+ import { MatCheckboxModule } from '@angular/material/checkbox' ;
25
+ import { MatCheckboxHarness } from '@angular/material/checkbox/testing' ;
23
26
24
27
describe ( 'filter dialog' , ( ) => {
28
+ let rootLoader : HarnessLoader ;
29
+
25
30
beforeEach ( async ( ) => {
26
31
await TestBed . configureTestingModule ( {
27
32
declarations : [ FilterDialog ] ,
28
- imports : [ DataTableModule , RangeInputModule , MatLegacyCheckboxModule ] ,
33
+ imports : [ DataTableModule , RangeInputModule , MatCheckboxModule ] ,
29
34
} ) . compileComponents ( ) ;
30
35
} ) ;
31
36
32
37
function createComponent ( input : { filter : DiscreteFilter | IntervalFilter } ) {
33
38
const fixture = TestBed . createComponent ( FilterDialog ) ;
34
39
fixture . componentInstance . filter = input . filter ;
40
+ rootLoader = TestbedHarnessEnvironment . documentRootLoader ( fixture ) ;
35
41
fixture . detectChanges ( ) ;
36
42
return fixture ;
37
43
}
38
44
39
- it ( 'dispatches event when an interval filter value is changed' , ( ) => {
45
+ it ( 'dispatches event when an interval filter value is changed' , async ( ) => {
40
46
const fixture = createComponent ( {
41
47
filter : {
42
48
type : DomainType . INTERVAL ,
@@ -66,16 +72,15 @@ describe('filter dialog', () => {
66
72
fixture . componentInstance . includeUndefinedToggled ,
67
73
'emit'
68
74
) ;
69
- const includeUndefinedCheckbox = Array . from (
70
- fixture . debugElement . queryAll ( By . css ( 'mat-checkbox' ) )
71
- ) . find ( ( elem ) =>
72
- elem . nativeElement . innerHTML . includes ( 'Include Undefined' )
73
- ) ! ;
74
- includeUndefinedCheckbox . query ( By . css ( 'label' ) ) . nativeElement . click ( ) ;
75
+
76
+ const includeUndefinedCheckbox = await rootLoader . getHarness (
77
+ MatCheckboxHarness . with ( { label : 'Include Undefined' } )
78
+ ) ;
79
+ await includeUndefinedCheckbox . check ( ) ;
75
80
expect ( includeUndefinedSpy ) . toHaveBeenCalled ( ) ;
76
81
} ) ;
77
82
78
- it ( 'dispatches event when an discrete filter value is changed' , ( ) => {
83
+ it ( 'dispatches event when an discrete filter value is changed' , async ( ) => {
79
84
const fixture = createComponent ( {
80
85
filter : {
81
86
type : DomainType . DISCRETE ,
@@ -84,29 +89,32 @@ describe('filter dialog', () => {
84
89
filterValues : [ 2 , 4 , 6 ] ,
85
90
} ,
86
91
} ) ;
87
- const discreteFilterChagnedSpy = spyOn (
92
+ const discreteFilterChangedSpy = spyOn (
88
93
fixture . componentInstance . discreteFilterChanged ,
89
94
'emit'
90
95
) ;
96
+ const checkbox = await rootLoader . getHarness (
97
+ MatCheckboxHarness . with ( { label : '2' } )
98
+ ) ;
99
+ await checkbox . uncheck ( ) ;
91
100
fixture . debugElement
92
101
. query ( By . css ( 'mat-checkbox label' ) )
93
102
. nativeElement . click ( ) ;
94
- expect ( discreteFilterChagnedSpy ) . toHaveBeenCalled ( ) ;
103
+ expect ( discreteFilterChangedSpy ) . toHaveBeenCalled ( ) ;
95
104
96
105
const includeUndefinedSpy = spyOn (
97
106
fixture . componentInstance . includeUndefinedToggled ,
98
107
'emit'
99
108
) ;
100
- const includeUndefinedCheckbox = Array . from (
101
- fixture . debugElement . queryAll ( By . css ( 'mat-checkbox' ) )
102
- ) . find ( ( elem ) =>
103
- elem . nativeElement . innerHTML . includes ( 'Include Undefined' )
104
- ) ! ;
105
- includeUndefinedCheckbox . query ( By . css ( 'label' ) ) . nativeElement . click ( ) ;
109
+
110
+ const includeUndefinedCheckbox = await rootLoader . getHarness (
111
+ MatCheckboxHarness . with ( { label : 'Include Undefined' } )
112
+ ) ;
113
+ await includeUndefinedCheckbox . check ( ) ;
106
114
expect ( includeUndefinedSpy ) . toHaveBeenCalled ( ) ;
107
115
} ) ;
108
116
109
- it ( 'filters discrete values' , ( ) => {
117
+ it ( 'filters discrete values' , async ( ) => {
110
118
const fixture = createComponent ( {
111
119
filter : {
112
120
type : DomainType . DISCRETE ,
@@ -116,19 +124,19 @@ describe('filter dialog', () => {
116
124
} ,
117
125
} ) ;
118
126
expect (
119
- fixture . debugElement . queryAll ( By . css ( 'mat-checkbox' ) ) . length
127
+ ( await rootLoader . getAllHarnesses ( MatCheckboxHarness ) ) . length
120
128
) . toEqual ( 5 ) ; // 4 options + the include undefined checkbox
121
129
122
130
fixture . componentInstance . discreteValueFilter = 'ba' ;
123
131
fixture . detectChanges ( ) ;
124
132
expect (
125
- fixture . debugElement . queryAll ( By . css ( 'mat-checkbox' ) ) . length
133
+ ( await rootLoader . getAllHarnesses ( MatCheckboxHarness ) ) . length
126
134
) . toEqual ( 3 ) ; // 2 options + the include undefined checkbox
127
135
128
136
fixture . componentInstance . discreteValueFilter = 'nothing matches me' ;
129
137
fixture . detectChanges ( ) ;
130
138
expect (
131
- fixture . debugElement . queryAll ( By . css ( 'mat-checkbox' ) ) . length
139
+ ( await rootLoader . getAllHarnesses ( MatCheckboxHarness ) ) . length
132
140
) . toEqual ( 1 ) ; // 0 options + the include undefined checkbox
133
141
expect ( fixture . nativeElement . innerHTML ) . toContain ( 'No Matching Values' ) ;
134
142
} ) ;
0 commit comments