Browse Source

Testrunner fixed

pull/85/head
Sebastian Stehle 9 years ago
parent
commit
53234c33c5
  1. 10
      src/Squidex/app-config/karma.conf.js
  2. 26
      src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts
  3. 16
      src/Squidex/app/framework/angular/focus-on-init.directive.ts
  4. 3
      src/Squidex/package.json

10
src/Squidex/app-config/karma.conf.js

@ -33,11 +33,17 @@ module.exports = function (config) {
noInfo: true noInfo: true
}, },
/*
* leave Jasmine Spec Runner output visible in browser
*/
client: {
clearContext: false
},
/* /*
* Use a mocha style console reporter, html reporter and the code coverage reporter * Use a mocha style console reporter and html reporter.
*/ */
reporters: ['mocha'], reporters: ['kjhtml', 'mocha'],
/** /**

26
src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts

@ -10,15 +10,7 @@ import { ElementRef, Renderer } from '@angular/core';
import { FocusOnInitDirective } from './focus-on-init.directive'; import { FocusOnInitDirective } from './focus-on-init.directive';
describe('FocusOnInitDirective', () => { describe('FocusOnInitDirective', () => {
let originalTimeout = 0; it('should call focus on element when init', () => {
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 800;
});
it('should call focus on element when init', (done: any) => {
const calledMethods: string[] = []; const calledMethods: string[] = [];
const calledElements: any[] = []; const calledElements: any[] = [];
@ -35,19 +27,9 @@ describe('FocusOnInitDirective', () => {
const directive = new FocusOnInitDirective(element, renderer as Renderer); const directive = new FocusOnInitDirective(element, renderer as Renderer);
directive.select = true; directive.select = true;
directive.ngOnInit(); directive.ngAfterViewInit();
expect(calledMethods).toEqual([]);
setTimeout(() => {
expect(calledMethods).toEqual(['focus', 'select']);
expect(calledElements).toEqual([element.nativeElement, element.nativeElement]);
done();
}, 400);
});
afterEach(() => { expect(calledMethods).toEqual(['focus', 'select']);
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; expect(calledElements).toEqual([element.nativeElement, element.nativeElement]);
}); });
}); });

16
src/Squidex/app/framework/angular/focus-on-init.directive.ts

@ -5,12 +5,12 @@
* Copyright (c) Sebastian Stehle. All rights reserved * Copyright (c) Sebastian Stehle. All rights reserved
*/ */
import { Directive, ElementRef, Input, OnInit, Renderer } from '@angular/core'; import { AfterViewInit, Directive, ElementRef, Input, Renderer } from '@angular/core';
@Directive({ @Directive({
selector: '[sqxFocusOnInit]' selector: '[sqxFocusOnInit]'
}) })
export class FocusOnInitDirective implements OnInit { export class FocusOnInitDirective implements AfterViewInit {
@Input() @Input()
public select: boolean; public select: boolean;
@ -20,13 +20,11 @@ export class FocusOnInitDirective implements OnInit {
) { ) {
} }
public ngOnInit() { public ngAfterViewInit() {
setTimeout(() => { this.renderer.invokeElementMethod(this.element.nativeElement, 'focus', []);
this.renderer.invokeElementMethod(this.element.nativeElement, 'focus', []);
if (this.select) { if (this.select) {
this.renderer.invokeElementMethod(this.element.nativeElement, 'select', []); this.renderer.invokeElementMethod(this.element.nativeElement, 'select', []);
} }
});
} }
} }

3
src/Squidex/package.json

@ -71,6 +71,7 @@
"karma-coverage": "1.1.1", "karma-coverage": "1.1.1",
"karma-htmlfile-reporter": "0.3.5", "karma-htmlfile-reporter": "0.3.5",
"karma-jasmine": "1.1.0", "karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-mocha-reporter": "2.2.3", "karma-mocha-reporter": "2.2.3",
"karma-phantomjs-launcher": "1.0.4", "karma-phantomjs-launcher": "1.0.4",
"karma-sourcemap-loader": "0.3.7", "karma-sourcemap-loader": "0.3.7",
@ -93,4 +94,4 @@
"webpack-dev-server": "2.5.1", "webpack-dev-server": "2.5.1",
"webpack-merge": "4.1.0" "webpack-merge": "4.1.0"
} }
} }

Loading…
Cancel
Save