1
1
import { Component } from '@angular/core' ;
2
- import { ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
3
- import { Platform , PlatformModule } from '@angular/cdk/platform' ;
2
+ import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3
+ import { Platform } from '@angular/cdk/platform' ;
4
4
import { HarnessLoader , parallel } from '@angular/cdk/testing' ;
5
5
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
6
6
import { MatButtonModule } from '../module' ;
@@ -14,19 +14,12 @@ describe('MatButtonHarness', () => {
14
14
let platform : Platform ;
15
15
16
16
beforeEach ( ( ) => {
17
- TestBed . configureTestingModule ( {
18
- imports : [ MatButtonModule , MatIconModule , PlatformModule , ButtonHarnessTest ] ,
19
- } ) ;
20
-
21
17
fixture = TestBed . createComponent ( ButtonHarnessTest ) ;
22
18
fixture . detectChanges ( ) ;
23
19
loader = TestbedHarnessEnvironment . loader ( fixture ) ;
20
+ platform = TestBed . inject ( Platform ) ;
24
21
} ) ;
25
22
26
- beforeEach ( inject ( [ Platform ] , ( p : Platform ) => {
27
- platform = p ;
28
- } ) ) ;
29
-
30
23
it ( 'should load all button harnesses' , async ( ) => {
31
24
const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
32
25
expect ( buttons . length ) . toBe ( 15 ) ;
@@ -53,24 +46,24 @@ describe('MatButtonHarness', () => {
53
46
} ) ;
54
47
55
48
it ( 'should get disabled state' , async ( ) => {
56
- // Grab each combination of [enabled, disabled] ⨯ [button, anchor]
57
- const [ disabledFlatButton , enabledFlatAnchor ] = await loader . getAllHarnesses (
58
- MatButtonHarness . with ( { text : / f l a t / i} ) ,
49
+ // Grab each combination of [enabled, disabled] x [button, anchor]
50
+ const [ disabledFilledButton , enabledFilledAnchor ] = await loader . getAllHarnesses (
51
+ MatButtonHarness . with ( { text : / f i l l e d / i} ) ,
59
52
) ;
60
- const [ enabledRaisedButton , disabledRaisedAnchor ] = await loader . getAllHarnesses (
61
- MatButtonHarness . with ( { text : / r a i s e d / i} ) ,
53
+ const [ enabledElevatedButton , disabledElevatedAnchor ] = await loader . getAllHarnesses (
54
+ MatButtonHarness . with ( { text : / e l e v a t e d / i} ) ,
62
55
) ;
63
56
64
- expect ( await enabledFlatAnchor . isDisabled ( ) ) . toBe ( false ) ;
65
- expect ( await disabledFlatButton . isDisabled ( ) ) . toBe ( true ) ;
66
- expect ( await enabledRaisedButton . isDisabled ( ) ) . toBe ( false ) ;
67
- expect ( await disabledRaisedAnchor . isDisabled ( ) ) . toBe ( true ) ;
57
+ expect ( await enabledFilledAnchor . isDisabled ( ) ) . toBe ( false ) ;
58
+ expect ( await disabledFilledButton . isDisabled ( ) ) . toBe ( true ) ;
59
+ expect ( await enabledElevatedButton . isDisabled ( ) ) . toBe ( false ) ;
60
+ expect ( await disabledElevatedAnchor . isDisabled ( ) ) . toBe ( true ) ;
68
61
} ) ;
69
62
70
63
it ( 'should get button text' , async ( ) => {
71
64
const [ firstButton , secondButton ] = await loader . getAllHarnesses ( MatButtonHarness ) ;
72
65
expect ( await firstButton . getText ( ) ) . toBe ( 'Basic button' ) ;
73
- expect ( await secondButton . getText ( ) ) . toBe ( 'Flat button' ) ;
66
+ expect ( await secondButton . getText ( ) ) . toBe ( 'Filled button' ) ;
74
67
} ) ;
75
68
76
69
it ( 'should focus and blur a button' , async ( ) => {
@@ -99,7 +92,7 @@ describe('MatButtonHarness', () => {
99
92
return ;
100
93
}
101
94
102
- const button = await loader . getHarness ( MatButtonHarness . with ( { text : 'Flat button' } ) ) ;
95
+ const button = await loader . getHarness ( MatButtonHarness . with ( { text : 'Filled button' } ) ) ;
103
96
await button . click ( ) ;
104
97
105
98
expect ( fixture . componentInstance . clicked ) . toBe ( false ) ;
@@ -116,65 +109,93 @@ describe('MatButtonHarness', () => {
116
109
expect ( await favIcon . getName ( ) ) . toBe ( 'favorite' ) ;
117
110
} ) ;
118
111
119
- it ( 'should load all button harnesses ' , async ( ) => {
112
+ it ( 'should be able to ge the type variant of the button ' , async ( ) => {
120
113
const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
121
114
const variants = await parallel ( ( ) => buttons . map ( button => button . getVariant ( ) ) ) ;
122
115
123
116
expect ( variants ) . toEqual ( [
124
117
'basic' ,
125
- 'flat ' ,
126
- 'raised ' ,
127
- 'stroked ' ,
118
+ 'basic ' ,
119
+ 'basic ' ,
120
+ 'basic ' ,
128
121
'icon' ,
129
122
'icon' ,
130
123
'fab' ,
131
124
'mini-fab' ,
132
125
'basic' ,
133
- 'flat ' ,
134
- 'raised ' ,
135
- 'stroked ' ,
126
+ 'basic ' ,
127
+ 'basic ' ,
128
+ 'basic ' ,
136
129
'icon' ,
137
130
'fab' ,
138
131
'mini-fab' ,
139
132
] ) ;
140
133
} ) ;
141
134
135
+ it ( 'should be able to get the appearance of the button' , async ( ) => {
136
+ const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
137
+ const appearances = await parallel ( ( ) => buttons . map ( button => button . getAppearance ( ) ) ) ;
138
+
139
+ expect ( appearances ) . toEqual ( [
140
+ 'text' ,
141
+ 'filled' ,
142
+ 'elevated' ,
143
+ 'outlined' ,
144
+ null ,
145
+ null ,
146
+ null ,
147
+ null ,
148
+ 'text' ,
149
+ 'filled' ,
150
+ 'elevated' ,
151
+ 'outlined' ,
152
+ null ,
153
+ null ,
154
+ null ,
155
+ ] ) ;
156
+ } ) ;
157
+
142
158
it ( 'should be able to filter buttons based on their variant' , async ( ) => {
143
- const button = await loader . getHarness ( MatButtonHarness . with ( { variant : 'flat' } ) ) ;
144
- expect ( await button . getText ( ) ) . toBe ( 'Flat button' ) ;
159
+ const button = await loader . getHarness ( MatButtonHarness . with ( { variant : 'fab' } ) ) ;
160
+ expect ( await button . getText ( ) ) . toBe ( 'Fab button' ) ;
161
+ } ) ;
162
+
163
+ it ( 'should be able to filter buttons based on their appearance' , async ( ) => {
164
+ const button = await loader . getHarness ( MatButtonHarness . with ( { appearance : 'filled' } ) ) ;
165
+ expect ( await button . getText ( ) ) . toBe ( 'Filled button' ) ;
145
166
} ) ;
146
167
} ) ;
147
168
148
169
@Component ( {
149
170
// Include one of each type of button selector to ensure that they're all captured by
150
171
// the harness's selector.
151
172
template : `
152
- <button id="basic" type="button" mat-button (click)="clicked = true">
173
+ <button id="basic" type="button" matButton (click)="clicked = true">
153
174
Basic button
154
175
</button>
155
- <button id="flat" type="button" mat-flat-button disabled (click)="clicked = true">
156
- Flat button
176
+ <button id="flat" type="button" matButton="filled" disabled (click)="clicked = true">
177
+ Filled button
157
178
</button>
158
- <button id="raised" type="button" mat-raised-button>Raised button</button>
159
- <button id="stroked" type="button" mat-stroked-button>Stroked button</button>
160
- <button id="home-icon" type="button" mat-icon-button >
179
+ <button id="raised" type="button" matButton="elevated">Elevated button</button>
180
+ <button id="stroked" type="button" matButton="outlined">Outlined button</button>
181
+ <button id="home-icon" type="button" matIconButton >
161
182
<mat-icon>home</mat-icon>
162
183
</button>
163
- <button id="favorite-icon" type="button" mat-icon-button >
184
+ <button id="favorite-icon" type="button" matIconButton >
164
185
<mat-icon>favorite</mat-icon>
165
186
</button>
166
- <button id="fab" type="button" mat-fab >Fab button</button>
167
- <button id="mini-fab" type="button" mat-mini-fab >Mini Fab button</button>
168
-
169
- <a id="anchor-basic" mat-button >Basic anchor</a>
170
- <a id="anchor-flat" mat-flat-button>Flat anchor</a>
171
- <a id="anchor-raised" mat-raised-button disabled>Raised anchor</a>
172
- <a id="anchor-stroked" mat-stroked-button >Stroked anchor</a>
173
- <a id="anchor-icon" mat-icon-button >Icon anchor</a>
174
- <a id="anchor-fab" mat-fab >Fab anchor</a>
175
- <a id="anchor-mini-fab" mat-mini-fab >Mini Fab anchor</a>
187
+ <button id="fab" type="button" matFab >Fab button</button>
188
+ <button id="mini-fab" type="button" matMiniFab >Mini Fab button</button>
189
+
190
+ <a id="anchor-basic" matButton >Basic anchor</a>
191
+ <a id="anchor-flat" matButton="filled">Filled anchor</a>
192
+ <a id="anchor-raised" matButton="elevated" disabled>Elevated anchor</a>
193
+ <a id="anchor-stroked" matButton="outlined" >Stroked anchor</a>
194
+ <a id="anchor-icon" matIconButton >Icon anchor</a>
195
+ <a id="anchor-fab" matFab >Fab anchor</a>
196
+ <a id="anchor-mini-fab" matMiniFab >Mini Fab anchor</a>
176
197
` ,
177
- imports : [ MatButtonModule , MatIconModule , PlatformModule ] ,
198
+ imports : [ MatButtonModule , MatIconModule ] ,
178
199
} )
179
200
class ButtonHarnessTest {
180
201
disabled = true ;
0 commit comments