11import { Component } from '@angular/core' ;
22import { ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
3- import { Platform , PlatformModule } from '@angular/cdk/platform' ;
3+ import { Platform } from '@angular/cdk/platform' ;
44import { HarnessLoader , parallel } from '@angular/cdk/testing' ;
55import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
66import { MatButtonModule } from '../module' ;
@@ -14,19 +14,12 @@ describe('MatButtonHarness', () => {
1414 let platform : Platform ;
1515
1616 beforeEach ( ( ) => {
17- TestBed . configureTestingModule ( {
18- imports : [ MatButtonModule , MatIconModule , PlatformModule , ButtonHarnessTest ] ,
19- } ) ;
20-
2117 fixture = TestBed . createComponent ( ButtonHarnessTest ) ;
2218 fixture . detectChanges ( ) ;
2319 loader = TestbedHarnessEnvironment . loader ( fixture ) ;
20+ platform = TestBed . inject ( Platform ) ;
2421 } ) ;
2522
26- beforeEach ( inject ( [ Platform ] , ( p : Platform ) => {
27- platform = p ;
28- } ) ) ;
29-
3023 it ( 'should load all button harnesses' , async ( ) => {
3124 const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
3225 expect ( buttons . length ) . toBe ( 15 ) ;
@@ -53,24 +46,24 @@ describe('MatButtonHarness', () => {
5346 } ) ;
5447
5548 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} ) ,
5952 ) ;
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} ) ,
6255 ) ;
6356
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 ) ;
6861 } ) ;
6962
7063 it ( 'should get button text' , async ( ) => {
7164 const [ firstButton , secondButton ] = await loader . getAllHarnesses ( MatButtonHarness ) ;
7265 expect ( await firstButton . getText ( ) ) . toBe ( 'Basic button' ) ;
73- expect ( await secondButton . getText ( ) ) . toBe ( 'Flat button' ) ;
66+ expect ( await secondButton . getText ( ) ) . toBe ( 'Filled button' ) ;
7467 } ) ;
7568
7669 it ( 'should focus and blur a button' , async ( ) => {
@@ -99,7 +92,7 @@ describe('MatButtonHarness', () => {
9992 return ;
10093 }
10194
102- const button = await loader . getHarness ( MatButtonHarness . with ( { text : 'Flat button' } ) ) ;
95+ const button = await loader . getHarness ( MatButtonHarness . with ( { text : 'Filled button' } ) ) ;
10396 await button . click ( ) ;
10497
10598 expect ( fixture . componentInstance . clicked ) . toBe ( false ) ;
@@ -116,65 +109,93 @@ describe('MatButtonHarness', () => {
116109 expect ( await favIcon . getName ( ) ) . toBe ( 'favorite' ) ;
117110 } ) ;
118111
119- it ( 'should load all button harnesses ' , async ( ) => {
112+ it ( 'should be able to ge the type variant of the button ' , async ( ) => {
120113 const buttons = await loader . getAllHarnesses ( MatButtonHarness ) ;
121114 const variants = await parallel ( ( ) => buttons . map ( button => button . getVariant ( ) ) ) ;
122115
123116 expect ( variants ) . toEqual ( [
124117 'basic' ,
125- 'flat ' ,
126- 'raised ' ,
127- 'stroked ' ,
118+ 'basic ' ,
119+ 'basic ' ,
120+ 'basic ' ,
128121 'icon' ,
129122 'icon' ,
130123 'fab' ,
131124 'mini-fab' ,
132125 'basic' ,
133- 'flat ' ,
134- 'raised ' ,
135- 'stroked ' ,
126+ 'basic ' ,
127+ 'basic ' ,
128+ 'basic ' ,
136129 'icon' ,
137130 'fab' ,
138131 'mini-fab' ,
139132 ] ) ;
140133 } ) ;
141134
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+
142158 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' ) ;
145166 } ) ;
146167} ) ;
147168
148169@Component ( {
149170 // Include one of each type of button selector to ensure that they're all captured by
150171 // the harness's selector.
151172 template : `
152- <button id="basic" type="button" mat-button (click)="clicked = true">
173+ <button id="basic" type="button" matButton (click)="clicked = true">
153174 Basic button
154175 </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
157178 </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 >
161182 <mat-icon>home</mat-icon>
162183 </button>
163- <button id="favorite-icon" type="button" mat-icon-button >
184+ <button id="favorite-icon" type="button" matIconButton >
164185 <mat-icon>favorite</mat-icon>
165186 </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>
176197 ` ,
177- imports : [ MatButtonModule , MatIconModule , PlatformModule ] ,
198+ imports : [ MatButtonModule , MatIconModule ] ,
178199} )
179200class ButtonHarnessTest {
180201 disabled = true ;
0 commit comments