/* Migreringsbeslut: detta test behöver Chrome headless eller PhantomJs + es6-shim för att kunna köras */
/**
* @ngdoc fbInfoTooltipSpec
* @name fasit.tests.#fbInfoTooltipSpec
* @fbInfoTooltipSpec
*
* @description
* Test för directivet fbInfoTooltipSpec
*
*/
import { FbInfoTooltipComponent } from './fb-info-tooltip.component';
import { ComponentFixture, TestBed, ComponentFixtureAutoDetect, async } from '@angular/core/testing';
import { DebugElement, NO_ERRORS_SCHEMA, Component } from '@angular/core';
import { By } from '@angular/platform-browser';
declare const angular: angular.IAngularStatic;
const headline: string = undefined;
const TIMEOUT_COUNT: number = 503;
@Component({
selector: 'fb-test-component-wrapper',
template: `
`
})
class TestComponentWrapperComponent {
headlineVar: string = headline;
}
let comp: FbInfoTooltipComponent;
let fixture: ComponentFixture;
let de: DebugElement;
let deComp: TestComponentWrapperComponent;
let el: HTMLElement;
let $scope: ng.IScope;
let fbInfoComp: DebugElement;
let fbInfoTooltipComp: DebugElement;
describe('FbInfoTooltipComponent', description);
function description(): void {
beforeEach(async(initAngularJs));
beforeEach(initAngular);
beforeEach(init);
beforeEach(() => {
jasmine.clock().uninstall(); // Av någon anledning verkar uninstall inte köras korrekt vid afterEach
jasmine.clock().install();
});
afterEach(() => {
$scope.$destroy();
jasmine.clock().uninstall();
});
run();
}
function initAngularJs(): void {
angular.mock.module('fasit', 'fbMocks');
angular.mock.inject(($rootScope: fb.IRootScope) => {
$scope = $rootScope.$new();
});
}
function initAngular(): void {
TestBed.configureTestingModule({
imports: [
],
declarations: [
TestComponentWrapperComponent,
FbInfoTooltipComponent
],
providers: [
{
provide: ComponentFixtureAutoDetect,
useValue: true
}
],
schemas: [NO_ERRORS_SCHEMA]
});
}
function init(): void {
fixture = TestBed.createComponent(TestComponentWrapperComponent);
comp = fixture.debugElement.children[0].componentInstance;
de = fixture.debugElement;
el = de.nativeElement;
deComp = fixture.debugElement.componentInstance;
fixture.detectChanges();
fbInfoComp = fixture.debugElement.query(By.css('.fb-info'));
fbInfoTooltipComp = fixture.debugElement.query(By.css('.fb-info-tooltip'));
}
function run(): void {
describe('initial state', () => {
it('borde inte visas', () => {
expect(comp.isTooltipVisible).toBe(false);
});
});
describe('mouse hover', () => {
it('borde visas efter 501 ms', () => {
doMouseOver();
expect(comp.isTooltipVisible).toBe(false);
jasmine.clock().tick(TIMEOUT_COUNT);
expect(comp.isTooltipVisible).toBe(true);
});
it('borde inte visas innan 501 ms om mouse out', () => {
doMouseOver();
expect(comp.isTooltipVisible).toBe(false);
doMouseOut();
jasmine.clock().tick(TIMEOUT_COUNT);
expect(comp.isTooltipVisible).toBe(false);
});
it('borde dölja efter visats vid mouseover och sedan mouseout', () => {
doMouseOver();
jasmine.clock().tick(TIMEOUT_COUNT);
expect(comp.isTooltipVisible).toBe(true);
doMouseOut();
expect(comp.isTooltipVisible).toBe(false);
});
it('öppnar tooltip vid mouseover och fastnar efter första klicket', () => {
doMouseOver();
jasmine.clock().tick(TIMEOUT_COUNT);
doMousedown();
doMouseOut();
expect(comp.isTooltipVisible).toBe(true);
});
it('stänga tooltip vid mouseover och fastnar efter första klicket för att sedan stängas efter andra klicket', () => {
doMouseOver();
jasmine.clock().tick(TIMEOUT_COUNT);
doMousedown();
doMouseOut();
expect(comp.isTooltipVisible).toBe(true);
doMousedown();
expect(comp.isTooltipVisible).toBe(false);
});
});
describe('Headline, text och label', () => {
it('borde inte visa headline', () => {
expect(comp.showHeadline).toBe(false);
});
// TODO frha
// it('borde visa headline', () => {
// // beforeEach(() => {
// // // $scope.$destroy();
// // headline = 'En fin headline';
// // });
// // beforeEach(init);
// expect(!!deComp.headlineVar).toBe(true);
// expect(comp.showHeadline).toBe(true);
// });
});
describe('klick öppnar/stänger tooltip', () => {
it('borde visas vid klick', () => {
doMousedown();
expect(comp.isTooltipVisible).toBe(true);
});
it('borde visas vid klick och mouseover', () => {
doMousedown();
doMouseOver();
jasmine.clock().tick(TIMEOUT_COUNT);
expect(comp.isTooltipVisible).toBe(true);
});
it('borde fortf visas efter klick och mouse out', () => {
doMouseOver();
doMousedown();
doMouseOut();
jasmine.clock().tick(TIMEOUT_COUNT);
expect(comp.isTooltipVisible).toBe(true);
});
// TODO frha, denna smäller
// it('borde fortf visas efter klick på tooltip och mouse out', () => {
// doMouseOver();
// jasmine.clock().tick(TIMEOUT_COUNT);
// doMousedownOnTooltip();
// doMouseOut();
// expect(comp.isTooltipVisible).toBe(true);
// });
it('stänga tooltip', () => {
comp.isTooltipVisible = true;
doMousedown();
expect(comp.isTooltipVisible).toBe(false);
});
});
function doMouseOver(): void {
fbInfoComp.triggerEventHandler('mouseenter', null);
// fixture.detectChanges();
}
function doMouseOut(): void {
fbInfoComp.triggerEventHandler('mouseleave', null);
}
function doMousedown(): void {
fbInfoComp.triggerEventHandler('mousedown', null);
}
// function doMousedownOnTooltip() {
// fbInfoTooltipComp.triggerEventHandler('mousedown', { button: 0 }); // leftclickevent
// }
}