@@ -2,7 +2,7 @@ import {async, TestBed, ComponentFixture, inject} from '@angular/core/testing';
2
2
import { Component , DebugElement } from '@angular/core' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
import { MdSelectionList , MdListOption , MdListModule } from './index' ;
5
- import { createKeyboardEvent } from '@angular/cdk/testing' ;
5
+ import { createKeyboardEvent , dispatchFakeEvent } from '@angular/cdk/testing' ;
6
6
import { UP_ARROW , DOWN_ARROW , SPACE } from '@angular/material/core' ;
7
7
import { Platform } from '@angular/material/core' ;
8
8
@@ -40,11 +40,11 @@ describe('MdSelectionList', () => {
40
40
it ( 'should add and remove focus class on focus/blur' , ( ) => {
41
41
expect ( listItemEl . nativeElement . classList ) . not . toContain ( 'mat-list-item-focus' ) ;
42
42
43
- listOption [ 0 ] . componentInstance . _handleFocus ( ) ;
43
+ dispatchFakeEvent ( listOption [ 0 ] . nativeElement , 'focus' ) ;
44
44
fixture . detectChanges ( ) ;
45
45
expect ( listItemEl . nativeElement . className ) . toContain ( 'mat-list-item-focus' ) ;
46
46
47
- listOption [ 0 ] . componentInstance . _handleBlur ( ) ;
47
+ dispatchFakeEvent ( listOption [ 0 ] . nativeElement , 'blur' ) ;
48
48
fixture . detectChanges ( ) ;
49
49
expect ( listItemEl . nativeElement . className ) . not . toContain ( 'mat-list-item-focus' ) ;
50
50
} ) ;
@@ -140,12 +140,9 @@ describe('MdSelectionList', () => {
140
140
let SPACE_EVENT : KeyboardEvent =
141
141
createKeyboardEvent ( 'keydown' , SPACE , testListItem ) ;
142
142
let selectList = selectionList . injector . get < MdSelectionList > ( MdSelectionList ) . selectedOptions ;
143
- let options = selectionList . componentInstance . options ;
144
- let array = options . toArray ( ) ;
145
- let focusItem = array [ 1 ] ;
146
143
expect ( selectList . selected . length ) . toBe ( 0 ) ;
147
144
148
- focusItem . focus ( ) ;
145
+ dispatchFakeEvent ( listOption [ 0 ] . nativeElement , ' focus' ) ;
149
146
selectionList . componentInstance . _keydown ( SPACE_EVENT ) ;
150
147
151
148
fixture . detectChanges ( ) ;
@@ -159,25 +156,20 @@ describe('MdSelectionList', () => {
159
156
listOption [ 3 ] . componentInstance . _handleFocus ( ) ;
160
157
161
158
expect ( manager . activeItemIndex ) . toBe ( 3 ) ;
162
- expect ( listOption [ 3 ] . componentInstance . _hasFocus ) . toBe ( true ) ;
163
159
164
160
fixture . componentInstance . showLastOption = false ;
165
161
fixture . detectChanges ( ) ;
166
162
167
163
expect ( manager . activeItemIndex ) . toBe ( 2 ) ;
168
- expect ( listOption [ 2 ] . componentInstance . _hasFocus ) . toBe ( true ) ;
169
164
} ) ;
170
165
171
166
it ( 'should focus previous item when press UP ARROW' , ( ) => {
172
167
let testListItem = listOption [ 2 ] . nativeElement as HTMLElement ;
173
168
let UP_EVENT : KeyboardEvent =
174
169
createKeyboardEvent ( 'keydown' , UP_ARROW , testListItem ) ;
175
- let options = selectionList . componentInstance . options ;
176
- let array = options . toArray ( ) ;
177
- let focusItem = array [ 2 ] ;
178
170
let manager = selectionList . componentInstance . _keyManager ;
179
171
180
- focusItem . focus ( ) ;
172
+ dispatchFakeEvent ( listOption [ 2 ] . nativeElement , ' focus' ) ;
181
173
expect ( manager . activeItemIndex ) . toEqual ( 2 ) ;
182
174
183
175
selectionList . componentInstance . _keydown ( UP_EVENT ) ;
@@ -191,12 +183,9 @@ describe('MdSelectionList', () => {
191
183
let testListItem = listOption [ 2 ] . nativeElement as HTMLElement ;
192
184
let DOWN_EVENT : KeyboardEvent =
193
185
createKeyboardEvent ( 'keydown' , DOWN_ARROW , testListItem ) ;
194
- let options = selectionList . componentInstance . options ;
195
- let array = options . toArray ( ) ;
196
- let focusItem = array [ 2 ] ;
197
186
let manager = selectionList . componentInstance . _keyManager ;
198
187
199
- focusItem . focus ( ) ;
188
+ dispatchFakeEvent ( listOption [ 2 ] . nativeElement , ' focus' ) ;
200
189
expect ( manager . activeItemIndex ) . toEqual ( 2 ) ;
201
190
202
191
selectionList . componentInstance . _keydown ( DOWN_EVENT ) ;
0 commit comments