mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-22 08:30:09 +00:00
Unit test added
This commit is contained in:
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -44,6 +44,7 @@ import { CapturingSettings } from '../../models/capturingSettings';
|
|||||||
import { LinkWidget } from '../../cartography/widgets/link';
|
import { LinkWidget } from '../../cartography/widgets/link';
|
||||||
import { NodeCreatedLabelStylesFixer } from './helpers/node-created-label-styles-fixer';
|
import { NodeCreatedLabelStylesFixer } from './helpers/node-created-label-styles-fixer';
|
||||||
import { MapSettingService } from '../../services/mapsettings.service';
|
import { MapSettingService } from '../../services/mapsettings.service';
|
||||||
|
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
|
||||||
|
|
||||||
export class MockedProgressService {
|
export class MockedProgressService {
|
||||||
public activate() {}
|
public activate() {}
|
||||||
@ -185,7 +186,6 @@ describe('ProjectMapComponent', () => {
|
|||||||
let nodesDataSource = new MockedNodesDataSource();
|
let nodesDataSource = new MockedNodesDataSource();
|
||||||
let linksDataSource = new MockedLinksDataSource();
|
let linksDataSource = new MockedLinksDataSource();
|
||||||
let nodeCreatedLabelStylesFixer;
|
let nodeCreatedLabelStylesFixer;
|
||||||
let mapSettingService = new MapSettingService();
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
nodeCreatedLabelStylesFixer = {
|
nodeCreatedLabelStylesFixer = {
|
||||||
@ -222,10 +222,9 @@ describe('ProjectMapComponent', () => {
|
|||||||
provide: RecentlyOpenedProjectService,
|
provide: RecentlyOpenedProjectService,
|
||||||
useClass: RecentlyOpenedProjectService
|
useClass: RecentlyOpenedProjectService
|
||||||
},
|
},
|
||||||
{ provide: NodeCreatedLabelStylesFixer, useValue: nodeCreatedLabelStylesFixer},
|
{ provide: NodeCreatedLabelStylesFixer, useValue: nodeCreatedLabelStylesFixer}
|
||||||
{ provide: MapSettingService, useValue: mapSettingService }
|
|
||||||
],
|
],
|
||||||
declarations: [ProjectMapComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
|
declarations: [ProjectMapComponent, ProjectMapMenuComponent, D3MapComponent, ...ANGULAR_MAP_DECLARATIONS],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
@ -233,6 +232,9 @@ describe('ProjectMapComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ProjectMapComponent);
|
fixture = TestBed.createComponent(ProjectMapComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.projectMapMenuComponent = {
|
||||||
|
resetDrawToolChoice(){}
|
||||||
|
} as ProjectMapMenuComponent;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -248,36 +250,10 @@ describe('ProjectMapComponent', () => {
|
|||||||
document.getElementsByClassName = jasmine.createSpy('HTML element').and.callFake(() => {
|
document.getElementsByClassName = jasmine.createSpy('HTML element').and.callFake(() => {
|
||||||
return [dummyElement];
|
return [dummyElement];
|
||||||
});
|
});
|
||||||
spyOn(component, 'resetDrawToolChoice');
|
spyOn(component.projectMapMenuComponent, 'resetDrawToolChoice').and.returnValue();
|
||||||
|
|
||||||
component.hideMenu();
|
component.hideMenu();
|
||||||
|
|
||||||
expect(component.resetDrawToolChoice).toHaveBeenCalled();
|
expect(component.projectMapMenuComponent.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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user