From f29c705bba4dbed9d79e238f83a24d6d150c762b Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Fri, 29 Mar 2019 02:31:01 -0700 Subject: [PATCH] Unit tests added --- .../moving-mode/moving-mode.component.spec.ts | 72 +++++++++++++++++++ .../project-map/project-map.component.spec.ts | 2 + .../project-map/project-map.component.ts | 1 - 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/app/cartography/components/moving-mode/moving-mode.component.spec.ts b/src/app/cartography/components/moving-mode/moving-mode.component.spec.ts index e69de29b..e94ffc4a 100644 --- a/src/app/cartography/components/moving-mode/moving-mode.component.spec.ts +++ b/src/app/cartography/components/moving-mode/moving-mode.component.spec.ts @@ -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; + 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(); + }); +}); diff --git a/src/app/components/project-map/project-map.component.spec.ts b/src/app/components/project-map/project-map.component.spec.ts index 1a3d2c4e..bc06a497 100644 --- a/src/app/components/project-map/project-map.component.spec.ts +++ b/src/app/components/project-map/project-map.component.spec.ts @@ -40,6 +40,7 @@ import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProje import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter'; import { Link } from '../../models/link'; import { Project } from '../../models/project'; +import { MovingEventSource } from '../../cartography/events/moving-event-source'; export class MockedProgressService { public activate() {} @@ -191,6 +192,7 @@ describe('ProjectMapComponent', () => { { provide: ToolsService }, { provide: SelectionManager }, { provide: SelectionTool }, + { provide: MovingEventSource }, { provide: RecentlyOpenedProjectService, useClass: RecentlyOpenedProjectService diff --git a/src/app/components/project-map/project-map.component.ts b/src/app/components/project-map/project-map.component.ts index e2d701e4..fc8e9993 100644 --- a/src/app/components/project-map/project-map.component.ts +++ b/src/app/components/project-map/project-map.component.ts @@ -295,7 +295,6 @@ export class ProjectMapComponent implements OnInit, OnDestroy { public toggleMovingMode() { this.tools.moving = !this.tools.moving; this.movingEventSource.movingModeState.emit(this.tools.moving); - //this.toolsService.movingToolActivation(this.tools.moving); if (!this.readonly) { this.tools.selection = !this.tools.moving;