Unit tests added

This commit is contained in:
Piotr Pekala 2019-03-29 02:31:01 -07:00
parent b93490fbd2
commit f29c705bba
3 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,72 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Context } from '../../models/context';
import { MovingModeComponent } from './moving-mode.component';
import { MovingEventSource } from '../../events/moving-event-source';
class SvgMock {
addEventListener() {}
}
describe('MovingModeComponent', () => {
let component: MovingModeComponent;
let fixture: ComponentFixture<MovingModeComponent>;
let movingEventSource = new MovingEventSource();
let svg = new SvgMock();
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
providers: [
{ provide: MovingEventSource, useValue: movingEventSource },
{ provide: Context, useClass: Context }
],
declarations: [MovingModeComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MovingModeComponent);
component = fixture.componentInstance;
component.svg = svg as unknown as SVGSVGElement;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should activate listener when moving mode changed to true', () => {
spyOn(component, 'activate');
movingEventSource.movingModeState.emit(true);
expect(component.activate).toHaveBeenCalled();
});
it('should deactivate listener when moving mode changed to false', () => {
spyOn(component, 'deactivate');
movingEventSource.movingModeState.emit(false);
expect(component.deactivate).toHaveBeenCalled();
});
it('should add moousemove listener on activation', () => {
spyOn(component, 'addMoveListener');
spyOn(component.svg, 'addEventListener').and.returnValue({});
component.activate();
expect(component.addMoveListener).toHaveBeenCalled();
});
it('should add mousewheel listener on activation', () => {
spyOn(component, 'addZoomListener');
spyOn(component.svg, 'addEventListener').and.returnValue({});
component.activate();
expect(component.addZoomListener).toHaveBeenCalled();
});
});

View File

@ -40,6 +40,7 @@ import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProje
import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter'; import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter';
import { Link } from '../../models/link'; import { Link } from '../../models/link';
import { Project } from '../../models/project'; import { Project } from '../../models/project';
import { MovingEventSource } from '../../cartography/events/moving-event-source';
export class MockedProgressService { export class MockedProgressService {
public activate() {} public activate() {}
@ -191,6 +192,7 @@ describe('ProjectMapComponent', () => {
{ provide: ToolsService }, { provide: ToolsService },
{ provide: SelectionManager }, { provide: SelectionManager },
{ provide: SelectionTool }, { provide: SelectionTool },
{ provide: MovingEventSource },
{ {
provide: RecentlyOpenedProjectService, provide: RecentlyOpenedProjectService,
useClass: RecentlyOpenedProjectService useClass: RecentlyOpenedProjectService

View File

@ -295,7 +295,6 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
public toggleMovingMode() { public toggleMovingMode() {
this.tools.moving = !this.tools.moving; this.tools.moving = !this.tools.moving;
this.movingEventSource.movingModeState.emit(this.tools.moving); this.movingEventSource.movingModeState.emit(this.tools.moving);
//this.toolsService.movingToolActivation(this.tools.moving);
if (!this.readonly) { if (!this.readonly) {
this.tools.selection = !this.tools.moving; this.tools.selection = !this.tools.moving;