11import { async , ComponentFixture , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
22import { Component , DebugElement , QueryList } from '@angular/core' ;
33import { By } from '@angular/platform-browser' ;
4+ import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
45import { MdChip , MdChipList , MdChipsModule } from './index' ;
56import { FocusKeyManager } from '../core/a11y/focus-key-manager' ;
6- import { SPACE , LEFT_ARROW , RIGHT_ARROW , TAB } from '../core/keyboard/keycodes' ;
77import { createKeyboardEvent } from '../core/testing/event-objects' ;
88
99import { MdInputModule } from '../input/index' ;
10- import { FakeEvent } from '../core/a11y/list-key-manager.spec' ;
11- import { LEFT_ARROW , RIGHT_ARROW , BACKSPACE , DELETE } from '../core/keyboard/keycodes' ;
10+ import { LEFT_ARROW , RIGHT_ARROW , BACKSPACE , DELETE , SPACE , TAB } from '../core/keyboard/keycodes' ;
1211import { Dir } from '../core/rtl/dir' ;
1312
14- export class FakeKeyboardEvent extends FakeEvent {
15- constructor ( keyCode : number , protected target : HTMLElement ) {
16- super ( keyCode ) ;
17-
18- this . target = target ;
19- }
20- }
21-
2213describe ( 'MdChipList' , ( ) => {
2314 let fixture : ComponentFixture < any > ;
2415 let chipListDebugElement : DebugElement ;
@@ -32,9 +23,9 @@ describe('MdChipList', () => {
3223
3324 beforeEach ( async ( ( ) => {
3425 TestBed . configureTestingModule ( {
35- imports : [ MdChipsModule , MdInputModule ] ,
26+ imports : [ MdChipsModule , MdInputModule , NoopAnimationsModule ] ,
3627 declarations : [
37- StaticChipList , StandardChipList , InputContainerChipList
28+ StandardChipList , InputContainerChipList
3829 ] ,
3930 providers : [ {
4031 provide : Dir , useFactory : ( ) => {
@@ -103,10 +94,6 @@ describe('MdChipList', () => {
10394 expect ( manager . activeItemIndex ) . toEqual ( 2 ) ;
10495 } ) ;
10596
106- let LEFT_EVENT = createKeyboardEvent ( 'keydown' , LEFT_ARROW , lastNativeChip ) ;
107- let array = chips . toArray ( ) ;
108- let lastIndex = array . length - 1 ;
109- let lastItem = array [ lastIndex ] ;
11097
11198 it ( 'focuses the previous item' , ( ) => {
11299 let array = chips . toArray ( ) ;
@@ -134,15 +121,11 @@ describe('MdChipList', () => {
134121 manager = chipListInstance . _keyManager ;
135122 } ) ) ;
136123
137- let RIGHT_EVENT = createKeyboardEvent ( 'keydown' , RIGHT_ARROW , firstNativeChip ) ;
138- let array = chips . toArray ( ) ;
139- let firstItem = array [ 0 ] ;
140-
141124 it ( 'LEFT ARROW focuses previous item' , ( ) => {
142125 let nativeChips = chipListNativeElement . querySelectorAll ( 'md-chip' ) ;
143126 let lastNativeChip = nativeChips [ nativeChips . length - 1 ] as HTMLElement ;
144127
145- let LEFT_EVENT = new FakeKeyboardEvent ( LEFT_ARROW , lastNativeChip ) as any ;
128+ let LEFT_EVENT = createKeyboardEvent ( 'keydown' , LEFT_ARROW , lastNativeChip ) ;
146129 let array = chips . toArray ( ) ;
147130 let lastIndex = array . length - 1 ;
148131 let lastItem = array [ lastIndex ] ;
@@ -164,7 +147,7 @@ describe('MdChipList', () => {
164147 let firstNativeChip = nativeChips [ 0 ] as HTMLElement ;
165148
166149 let RIGHT_EVENT : KeyboardEvent =
167- new FakeKeyboardEvent ( RIGHT_ARROW , firstNativeChip ) as any ;
150+ createKeyboardEvent ( 'keydown' , RIGHT_ARROW , firstNativeChip ) ;
168151 let array = chips . toArray ( ) ;
169152 let firstItem = array [ 0 ] ;
170153
@@ -189,17 +172,12 @@ describe('MdChipList', () => {
189172 manager = chipListInstance . _keyManager ;
190173 } ) ) ;
191174
192- let SPACE_EVENT = createKeyboardEvent ( 'keydown' , SPACE , firstNativeChip ) ;
193- let firstChip : MdChip = chips . toArray ( ) [ 0 ] ;
194-
195175 it ( 'RIGHT ARROW focuses previous item' , ( ) => {
196- fixture . detectChanges ( ) ;
197-
198176 let nativeChips = chipListNativeElement . querySelectorAll ( 'md-chip' ) ;
199177 let lastNativeChip = nativeChips [ nativeChips . length - 1 ] as HTMLElement ;
200178
201179 let RIGHT_EVENT : KeyboardEvent =
202- new FakeKeyboardEvent ( RIGHT_ARROW , lastNativeChip ) as any ;
180+ createKeyboardEvent ( 'keydown' , RIGHT_ARROW , lastNativeChip ) ;
203181 let array = chips . toArray ( ) ;
204182 let lastIndex = array . length - 1 ;
205183 let lastItem = array [ lastIndex ] ;
@@ -220,7 +198,8 @@ describe('MdChipList', () => {
220198 let nativeChips = chipListNativeElement . querySelectorAll ( 'md-chip' ) ;
221199 let firstNativeChip = nativeChips [ 0 ] as HTMLElement ;
222200
223- let LEFT_EVENT : KeyboardEvent = new FakeKeyboardEvent ( LEFT_ARROW , firstNativeChip ) as any ;
201+ let LEFT_EVENT : KeyboardEvent =
202+ createKeyboardEvent ( 'keydown' , LEFT_ARROW , firstNativeChip ) ;
224203 let array = chips . toArray ( ) ;
225204 let firstItem = array [ 0 ] ;
226205
@@ -236,18 +215,17 @@ describe('MdChipList', () => {
236215 expect ( manager . activeItemIndex ) . toEqual ( 1 ) ;
237216 } ) ;
238217
239- } ) ;
240-
241- it ( 'allow focus to escape when tabbing away' , fakeAsync ( ( ) => {
242- chipListInstance . _keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , TAB ) ) ;
218+ it ( 'allow focus to escape when tabbing away' , fakeAsync ( ( ) => {
219+ chipListInstance . _keyManager . onKeydown ( createKeyboardEvent ( 'keydown' , TAB ) ) ;
243220
244- expect ( chipListInstance . _tabIndex )
221+ expect ( chipListInstance . _tabIndex )
245222 . toBe ( - 1 , 'Expected tabIndex to be set to -1 temporarily.' ) ;
246223
247- tick ( ) ;
224+ tick ( ) ;
248225
249- expect ( chipListInstance . _tabIndex ) . toBe ( 0 , 'Expected tabIndex to be reset back to 0' ) ;
250- } ) ) ;
226+ expect ( chipListInstance . _tabIndex ) . toBe ( 0 , 'Expected tabIndex to be reset back to 0' ) ;
227+ } ) ) ;
228+ } ) ;
251229 } ) ;
252230 } ) ;
253231
@@ -271,7 +249,8 @@ describe('MdChipList', () => {
271249
272250 it ( 'DELETE focuses the last chip' , ( ) => {
273251 let nativeInput = chipListNativeElement . querySelector ( 'input' ) ;
274- let DELETE_EVENT : KeyboardEvent = new FakeKeyboardEvent ( DELETE , nativeInput ) as any ;
252+ let DELETE_EVENT : KeyboardEvent =
253+ createKeyboardEvent ( 'keydown' , DELETE , nativeInput ) ;
275254
276255 // Focus the input
277256 nativeInput . focus ( ) ;
@@ -287,7 +266,8 @@ describe('MdChipList', () => {
287266
288267 it ( 'BACKSPACE focuses the last chip' , ( ) => {
289268 let nativeInput = chipListNativeElement . querySelector ( 'input' ) ;
290- let BACKSPACE_EVENT : KeyboardEvent = new FakeKeyboardEvent ( BACKSPACE , nativeInput ) as any ;
269+ let BACKSPACE_EVENT : KeyboardEvent =
270+ createKeyboardEvent ( 'keydown' , BACKSPACE , nativeInput ) ;
291271
292272 // Focus the input
293273 nativeInput . focus ( ) ;
@@ -360,7 +340,6 @@ class StandardChipList {
360340 <md-chip>Chip 1</md-chip>
361341 <md-chip>Chip 1</md-chip>
362342 <md-chip>Chip 1</md-chip>
363-
364343 <input mdInput name="test" />
365344 </md-chip-list>
366345 </md-input-container>
0 commit comments