alfresco-ng2-components/lib/insights/diagram/components/tooltip/diagram-tooltip.component.spec.ts
Denys Vuika 6b24bfb1d4 [ADF-3299] and [ADF-3300] upgrade to Angular and Material 6 (#3579)
* upgrade to HttpClient

* upgrade to Renderer2

* upgrade Document reference

* remove useless test with deprecated ReflectiveInjector

* upgrade to latest typescript

* upgrade libs

* upgrade package scripts

* remove rxjs blacklists and duplicate rules

* add rxjs compat to help with migration

* fix breaking changes

* fix breaking changes in material

* fix breaking changes (material 6)

* upgrade rxjs, ngx-translate and flex layout

* update unit tests

* restore providers

* upgrade deprecated Observable.error

* rebase
fix first configuration problems

* fix style issues commented

* fix core build

* fix lib template errors

* move lib test execution in angular.json

* ignore

* karma conf files

* fix import statement test

* single run option

* update packages reporter

* restore report

* increase timeout

* improve karma conf test configuration

* fix test issues about lint

* fix test analytics

* fix process service test

* content service fix test

* fix logout directive test

* fix core test

* fix build

* update node-sass to latest

* update angular cli dependencies

* improve build script

create directorites and move files only if previous command succeded

* upgrade individual libs to 6.0

* remove old webpack files

* revert sass change

* fix type issues
fix style issues

* fix tslint demo shell issue

* fix peerdependencies

* fix test e2e BC

* package upate

* fix style import issue

* extract-text-webpack-plugin beta

* fix test dist build command

* remove alpha js-api

* fix tslint issue
add banner tslint rule

* upload service fix

* change BC script

* fix test dist script

* increase demo shell timeout test

* verbose copy

* path absolute

* fix script bc

* fix copy part

* fix path warning
fix monaco editor

* remove duplicate header

* remove unused import

* fix align and check ago tests

* add missing import

* fix notification button selector

* [ANGULAR6] fixed core tests

* fix CS test

* fix cs test step 2

* increase travis_wait for dist

* fix attachment PS

* fix checklist test

* use pdf min
2018-08-14 15:42:43 +01:00

182 lines
7.0 KiB
TypeScript

/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DiagramTooltipComponent } from './diagram-tooltip.component';
@Component({
template: `
<div id="diagram-element-id">Hover me</div>
<diagram-tooltip [data]="data"></diagram-tooltip>`
})
class TestHostComponent {
data = {
id: 'diagram-element-id'
};
}
describe('DiagramTooltipComponent', () => {
describe('Template', () => {
let fixture: ComponentFixture<DiagramTooltipComponent>;
let component: DiagramTooltipComponent;
let data;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DiagramTooltipComponent ]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DiagramTooltipComponent);
component = fixture.componentInstance;
data = {
type: 'awesome-diagram-element',
name: 'diagram-element-name',
id: 'diagram-element-id',
properties: []
};
component.data = data;
fixture.detectChanges();
});
it('should render with type and name if name is defined', () => {
let tooltipHeader = fixture.debugElement.query(By.css('.adf-diagram-tooltip-header'));
expect(tooltipHeader.nativeElement.innerText).toBe('awesome-diagram-element diagram-element-name');
});
it('should render with type and id if name is NOT defined', () => {
data.name = '';
fixture.detectChanges();
let tooltipHeader = fixture.debugElement.query(By.css('.adf-diagram-tooltip-header'));
expect(tooltipHeader.nativeElement.innerText).toBe('awesome-diagram-element diagram-element-id');
});
it('should render the name if name is defined in the tooltip body', () => {
let nameProperty = fixture.debugElement.query(By.css('.adf-diagram-name-property'));
expect(nameProperty).not.toBeNull();
expect(nameProperty.nativeElement.innerText).toBe('Name:diagram-element-name');
});
it('should NOT render the name if name is NOT defined in the tooltip body', () => {
data.name = '';
fixture.detectChanges();
let nameProperty = fixture.debugElement.query(By.css('.adf-diagram-name-property'));
expect(nameProperty).toBeNull();
});
it('should render the properties, if there is any', () => {
data.properties = [
{ name: 'property-1-name', value: 'property-1-value' },
{ name: 'property-2-name', value: 'property-2-value' }
];
fixture.detectChanges();
let propertyNames = fixture.debugElement.queryAll(By.css('.adf-diagram-general-property > .adf-diagram-propertyName')),
propertyValues = fixture.debugElement.queryAll(By.css('.adf-diagram-general-property > .adf-diagram-propertyValue'));
expect(propertyNames.length).toBe(2);
expect(propertyValues.length).toBe(2);
expect(propertyNames[0].nativeElement.innerText).toBe('property-1-name:');
expect(propertyNames[1].nativeElement.innerText).toBe('property-2-name:');
expect(propertyValues[0].nativeElement.innerText).toBe('property-1-value');
expect(propertyValues[1].nativeElement.innerText).toBe('property-2-value');
});
});
describe('Tooltip functionality', () => {
let fixture: ComponentFixture<TestHostComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DiagramTooltipComponent, TestHostComponent ]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestHostComponent);
fixture.detectChanges();
});
it('should NOT show the tooltip by default', () => {
const tooltip = fixture.debugElement.query(By.css('.adf-diagram-tooltip.is-active'));
expect(tooltip).toBeNull();
});
it('should show the tooltip on hovering the target element', () => {
const tooltipTarget = fixture.debugElement.query(By.css('#diagram-element-id'));
tooltipTarget.nativeElement.dispatchEvent(new MouseEvent('mouseenter'));
let tooltip = fixture.debugElement.query(By.css('.adf-diagram-tooltip.is-active'));
expect(tooltip).not.toBeNull();
});
it('should show the tooltip on touchend the target element', () => {
const tooltipTarget = fixture.debugElement.query(By.css('#diagram-element-id'));
tooltipTarget.nativeElement.dispatchEvent(new MouseEvent('touchend'));
let tooltip = fixture.debugElement.query(By.css('.adf-diagram-tooltip.is-active'));
expect(tooltip).not.toBeNull();
});
it('should hide the tooltip on leaving the target element', () => {
const tooltipTarget = fixture.debugElement.query(By.css('#diagram-element-id'));
tooltipTarget.nativeElement.dispatchEvent(new MouseEvent('mouseenter'));
tooltipTarget.nativeElement.dispatchEvent(new MouseEvent('mouseleave'));
let tooltip = fixture.debugElement.query(By.css('.adf-diagram-tooltip.is-active'));
expect(tooltip).toBeNull();
});
it('should hide the tooltip on windows\'s scroll element', () => {
const tooltipTarget = fixture.debugElement.query(By.css('#diagram-element-id'));
tooltipTarget.nativeElement.dispatchEvent(new MouseEvent('mouseenter'));
window.dispatchEvent(new CustomEvent('scroll'));
let tooltip = fixture.debugElement.query(By.css('.adf-diagram-tooltip.is-active'));
expect(tooltip).toBeNull();
});
it('should hide the tooltip on windows\'s touchstart element', () => {
const tooltipTarget = fixture.debugElement.query(By.css('#diagram-element-id'));
tooltipTarget.nativeElement.dispatchEvent(new MouseEvent('touchend'));
window.dispatchEvent(new CustomEvent('touchstart'));
let tooltip = fixture.debugElement.query(By.css('.adf-diagram-tooltip.is-active'));
expect(tooltip).toBeNull();
});
});
});