mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.4 KiB
56 lines
1.4 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { ElementRef } from '@angular/core';
|
|
import { FocusOnInitDirective } from './focus-on-init.directive';
|
|
|
|
describe('FocusOnInitDirective', () => {
|
|
let isFocusCalled = false;
|
|
let isSelectCalled = false;
|
|
|
|
const element: ElementRef = {
|
|
nativeElement: {
|
|
focus: () => {
|
|
isFocusCalled = true;
|
|
},
|
|
select: () => {
|
|
isSelectCalled = true;
|
|
},
|
|
},
|
|
};
|
|
|
|
beforeEach(() => {
|
|
isFocusCalled = false;
|
|
isSelectCalled = false;
|
|
});
|
|
|
|
it('should call focus on element if init', (cb) => {
|
|
const directive = new FocusOnInitDirective(element);
|
|
directive.select = false;
|
|
directive.ngAfterViewInit();
|
|
|
|
setTimeout(() => {
|
|
expect(isFocusCalled).toBeTruthy();
|
|
expect(isSelectCalled).toBeFalsy();
|
|
|
|
cb();
|
|
}, 200);
|
|
});
|
|
|
|
it('should call select on element if init', (cb) => {
|
|
const directive = new FocusOnInitDirective(element);
|
|
directive.select = true;
|
|
directive.ngAfterViewInit();
|
|
|
|
setTimeout(() => {
|
|
expect(isFocusCalled).toBeTruthy();
|
|
expect(isSelectCalled).toBeTruthy();
|
|
|
|
cb();
|
|
}, 200);
|
|
});
|
|
});
|
|
|