Unit test added

This commit is contained in:
Piotr Pekala 2019-06-26 02:48:02 -07:00
parent 4b60041f8f
commit e905a91fd1
2 changed files with 76 additions and 33 deletions

View File

@ -0,0 +1,67 @@
import { ProjectMapMenuComponent } from "./project-map-menu.component";
import { ComponentFixture, async, TestBed } from '@angular/core/testing';
import { MockedDrawingService } from '../project-map.component.spec';
import { MapSettingService } from '../../../services/mapsettings.service';
import { MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule } from '@angular/material';
import { CommonModule } from '@angular/common';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { DrawingService } from '../../../services/drawing.service';
import { ToolsService } from '../../../services/tools.service';
import { D3MapComponent } from '../../../cartography/components/d3-map/d3-map.component';
import { ANGULAR_MAP_DECLARATIONS } from '../../../cartography/angular-map.imports';
import { NO_ERRORS_SCHEMA } from '@angular/core';
describe('ProjectMapMenuComponent', () => {
let component: ProjectMapMenuComponent;
let fixture: ComponentFixture<ProjectMapMenuComponent>;
let drawingService = new MockedDrawingService();
let mapSettingService = new MapSettingService();
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule],
providers: [
{ provide: DrawingService, useValue: drawingService },
{ provide: ToolsService },
{ provide: MapSettingService, useValue: mapSettingService }
],
declarations: [ProjectMapMenuComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProjectMapMenuComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should reset choice on draw menu after saving drawing', () => {
spyOn(component, 'resetDrawToolChoice');
component.onDrawingSaved();
expect(component.resetDrawToolChoice).toHaveBeenCalled();
});
it('should call map settings service when lock value was changed', () => {
spyOn(mapSettingService, 'changeMapLockValue');
component.changeLockValue();
expect(mapSettingService.changeMapLockValue).toHaveBeenCalled();
});
it('should call map settings service with proper value', () => {
spyOn(mapSettingService, 'changeMapLockValue');
component.changeLockValue();
expect(mapSettingService.changeMapLockValue).toHaveBeenCalledWith(true);
component.changeLockValue();
expect(mapSettingService.changeMapLockValue).toHaveBeenCalledWith(false);
});
});

View File

@ -44,6 +44,7 @@ import { CapturingSettings } from '../../models/capturingSettings';
import { LinkWidget } from '../../cartography/widgets/link';
import { NodeCreatedLabelStylesFixer } from './helpers/node-created-label-styles-fixer';
import { MapSettingService } from '../../services/mapsettings.service';
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
export class MockedProgressService {
public activate() {}
@ -185,7 +186,6 @@ describe('ProjectMapComponent', () => {
let nodesDataSource = new MockedNodesDataSource();
let linksDataSource = new MockedLinksDataSource();
let nodeCreatedLabelStylesFixer;
let mapSettingService = new MapSettingService();
beforeEach(async(() => {
nodeCreatedLabelStylesFixer = {
@ -222,10 +222,9 @@ describe('ProjectMapComponent', () => {
provide: RecentlyOpenedProjectService,
useClass: RecentlyOpenedProjectService
},
{ provide: NodeCreatedLabelStylesFixer, useValue: nodeCreatedLabelStylesFixer},
{ provide: MapSettingService, useValue: mapSettingService }
{ provide: NodeCreatedLabelStylesFixer, useValue: nodeCreatedLabelStylesFixer}
],
declarations: [ProjectMapComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
declarations: [ProjectMapComponent, ProjectMapMenuComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
@ -233,6 +232,9 @@ describe('ProjectMapComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ProjectMapComponent);
component = fixture.componentInstance;
component.projectMapMenuComponent = {
resetDrawToolChoice(){}
} as ProjectMapMenuComponent;
});
afterEach(() => {
@ -246,38 +248,12 @@ describe('ProjectMapComponent', () => {
it('should hide draw tools when hide menu is called', () => {
var dummyElement = document.createElement('map');
document.getElementsByClassName = jasmine.createSpy('HTML element').and.callFake(() => {
return [dummyElement];
return [dummyElement];
});
spyOn(component, 'resetDrawToolChoice');
spyOn(component.projectMapMenuComponent, 'resetDrawToolChoice').and.returnValue();
component.hideMenu();
expect(component.resetDrawToolChoice).toHaveBeenCalled();
});
it('should reset choice on draw menu after saving drawing', () => {
spyOn(component, 'resetDrawToolChoice');
component.onDrawingSaved();
expect(component.resetDrawToolChoice).toHaveBeenCalled();
});
it('should call map settings service when lock value was changed', () => {
spyOn(mapSettingService, 'changeMapLockValue');
component.changeLockValue();
expect(mapSettingService.changeMapLockValue).toHaveBeenCalled();
});
it('should call map settings service with proper value', () => {
spyOn(mapSettingService, 'changeMapLockValue');
component.changeLockValue();
expect(mapSettingService.changeMapLockValue).toHaveBeenCalledWith(true);
component.changeLockValue();
expect(mapSettingService.changeMapLockValue).toHaveBeenCalledWith(false);
expect(component.projectMapMenuComponent.resetDrawToolChoice).toHaveBeenCalled();
});
});