import { ENTER } from 'ngx-tethys/util' ; import { Component , ElementRef , ViewChild } from '@angular/core' ; import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ; import { dispatchKeyboardEvent } from '../../testing' ; import { ThySharedModule } from '../shared.module' ; @ Component ( { selector : 'thy-autofocus-test' , template : `
        <input #enter (thyCtrlEnter)="ok($event)" />
    ` } ) class ThyCtrlEnterTestComponent { @ ViewChild ( 'enter' ) input : ElementRef ; ok ( event ) { } } describe ( 'ThyCtrlEnterDirective' , ( ) => { let fixture ; let testComponent ; let enterSpy ; beforeEach ( waitForAsync ( ( ) => { TestBed . configureTestingModule ( { imports : [ ThySharedModule ] , declarations : [ ThyCtrlEnterTestComponent ] } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( ThyCtrlEnterTestComponent ) ; testComponent = fixture . componentInstance ; fixture . detectChanges ( ) ; enterSpy = spyOn ( testComponent , 'ok' ) ; } ) ; it ( 'should call thyCtrlEnter when enter' , ( ) => { const event = dispatchKeyboardEvent ( testComponent . input . nativeElement , 'keydown' , ENTER , '' , { control : true , meta : true } ) ; fixture . detectChanges ( ) ; expect ( enterSpy ) . toHaveBeenCalled ( ) ; expect ( enterSpy ) . toHaveBeenCalledWith ( event ) ; } ) ; } ) ;