1
1
import { MutationObserverFactory } from '@angular/cdk/observers' ;
2
2
import { dispatchFakeEvent } from '@angular/cdk/testing/private' ;
3
- import { Component } from '@angular/core' ;
3
+ import { Component , DebugElement } from '@angular/core' ;
4
4
import {
5
5
ComponentFixture ,
6
6
fakeAsync ,
@@ -731,15 +731,18 @@ describe('MatSlideToggle with forms', () => {
731
731
let fixture : ComponentFixture < SlideToggleWithFormControl > ;
732
732
733
733
let testComponent : SlideToggleWithFormControl ;
734
+ let slideToggleDebug : DebugElement ;
734
735
let slideToggle : MatSlideToggle ;
735
736
let inputElement : HTMLInputElement ;
736
737
737
738
beforeEach ( ( ) => {
738
739
fixture = TestBed . createComponent ( SlideToggleWithFormControl ) ;
739
740
fixture . detectChanges ( ) ;
740
741
742
+ slideToggleDebug = fixture . debugElement . query ( By . directive ( MatSlideToggle ) ) ! ;
743
+
741
744
testComponent = fixture . debugElement . componentInstance ;
742
- slideToggle = fixture . debugElement . query ( By . directive ( MatSlideToggle ) ) ! . componentInstance ;
745
+ slideToggle = slideToggleDebug . componentInstance ;
743
746
inputElement = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
744
747
} ) ;
745
748
@@ -759,6 +762,15 @@ describe('MatSlideToggle with forms', () => {
759
762
expect ( slideToggle . disabled ) . toBe ( false ) ;
760
763
expect ( inputElement . disabled ) . toBe ( false ) ;
761
764
} ) ;
765
+
766
+ it ( 'should not change focus origin if origin not specified' , ( ) => {
767
+ slideToggle . focus ( 'mouse' ) ;
768
+ slideToggle . focus ( ) ;
769
+ fixture . detectChanges ( ) ;
770
+
771
+ expect ( slideToggleDebug . nativeElement . classList ) . toContain ( 'cdk-focused' ) ;
772
+ expect ( slideToggleDebug . nativeElement . classList ) . toContain ( 'cdk-mouse-focused' ) ;
773
+ } ) ;
762
774
} ) ;
763
775
764
776
describe ( 'with form element' , ( ) => {
0 commit comments