mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-22 08:30:09 +00:00
Fix for unit tests
This commit is contained in:
@ -71,10 +71,19 @@ export class MockedDrawingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('ProjectMapComponent', () => {
|
export class MockedDrawingsDataSource {
|
||||||
|
add() {}
|
||||||
|
|
||||||
|
get() { return of({})}
|
||||||
|
|
||||||
|
update() { return of({})}
|
||||||
|
}
|
||||||
|
|
||||||
|
fdescribe('ProjectMapComponent', () => {
|
||||||
let component: ProjectMapComponent;
|
let component: ProjectMapComponent;
|
||||||
let fixture: ComponentFixture<ProjectMapComponent>;
|
let fixture: ComponentFixture<ProjectMapComponent>;
|
||||||
let drawingService = new MockedDrawingService;
|
let drawingService = new MockedDrawingService;
|
||||||
|
let drawingsDataSource = new MockedDrawingsDataSource;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -102,9 +111,7 @@ describe('ProjectMapComponent', () => {
|
|||||||
{ provide: MapPortToPortConverter },
|
{ provide: MapPortToPortConverter },
|
||||||
{ provide: NodesDataSource },
|
{ provide: NodesDataSource },
|
||||||
{ provide: LinksDataSource },
|
{ provide: LinksDataSource },
|
||||||
{ provide: DrawingsDataSource, useValue: {
|
{ provide: DrawingsDataSource, useValue: drawingsDataSource},
|
||||||
get: () => { return new Drawing }
|
|
||||||
} },
|
|
||||||
{ provide: NodesEventSource },
|
{ provide: NodesEventSource },
|
||||||
{ provide: DrawingsEventSource },
|
{ provide: DrawingsEventSource },
|
||||||
{ provide: LinksEventSource },
|
{ provide: LinksEventSource },
|
||||||
@ -134,8 +141,7 @@ describe('ProjectMapComponent', () => {
|
|||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
//cannot read subscribe of undefined need to be fixed
|
it('should update position on resizing event', () => {
|
||||||
xit('should update position on resizing event', () => {
|
|
||||||
let drawingElement: DrawingElement;
|
let drawingElement: DrawingElement;
|
||||||
let rect = new RectElement();
|
let rect = new RectElement();
|
||||||
rect.fill = "#ffffff";
|
rect.fill = "#ffffff";
|
||||||
@ -155,26 +161,25 @@ describe('ProjectMapComponent', () => {
|
|||||||
mapDrawing.z = 0;
|
mapDrawing.z = 0;
|
||||||
mapDrawing.element = drawingElement;
|
mapDrawing.element = drawingElement;
|
||||||
let event = new ResizedDataEvent<MapDrawing>(mapDrawing,0,0,100,100);
|
let event = new ResizedDataEvent<MapDrawing>(mapDrawing,0,0,100,100);
|
||||||
spyOn(drawingService, 'updateSizeAndPosition');
|
spyOn(drawingService, 'updateSizeAndPosition').and.returnValue( Observable.of({}));
|
||||||
|
|
||||||
component.onDrawingResized(event);
|
component.onDrawingResized(event);
|
||||||
|
|
||||||
expect(drawingService.updateSizeAndPosition).toHaveBeenCalled();
|
expect(drawingService.updateSizeAndPosition).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
//cannot read subscribe of undefined need to be fixed
|
it('should add selected drawing', () => {
|
||||||
xit('should add selected drawing', () => {
|
|
||||||
component.mapChild = { context: {} } as D3MapComponent;
|
component.mapChild = { context: {} } as D3MapComponent;
|
||||||
component.project = { project_id: "1" } as Project;
|
component.project = { project_id: "1" } as Project;
|
||||||
component.mapChild.context.getZeroZeroTransformationPoint = jasmine.createSpy('HTML element').and.callFake(() => { return {x: 0, y: 0}});
|
component.mapChild.context.getZeroZeroTransformationPoint = jasmine.createSpy('HTML element').and.callFake(() => { return {x: 0, y: 0}});
|
||||||
var dummyElement = document.createElement('map');
|
var dummyElement = document.createElement('map');
|
||||||
document.getElementsByClassName = jasmine.createSpy('HTML element').and.callFake(() => { return ([dummyElement])});
|
document.getElementsByClassName = jasmine.createSpy('HTML element').and.callFake(() => { return ([dummyElement])});
|
||||||
spyOn(drawingService, 'add');
|
spyOn(drawingsDataSource, 'add');
|
||||||
|
|
||||||
component.addDrawing("rectangle");
|
component.addDrawing("rectangle");
|
||||||
dummyElement.click();
|
dummyElement.click();
|
||||||
|
|
||||||
expect(drawingService.add).toHaveBeenCalled();
|
expect(drawingsDataSource.add).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should hide draw tools when hide menu is called', () => {
|
it('should hide draw tools when hide menu is called', () => {
|
||||||
|
@ -40,7 +40,7 @@ describe('DrawingService', () => {
|
|||||||
|
|
||||||
it('should be created', inject([DrawingService], (service: DrawingService) => {
|
it('should be created', inject([DrawingService], (service: DrawingService) => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should updatePosition of drawing', inject([DrawingService], (service: DrawingService) => {
|
it('should updatePosition of drawing', inject([DrawingService], (service: DrawingService) => {
|
||||||
const drawing = new Drawing();
|
const drawing = new Drawing();
|
||||||
@ -74,7 +74,7 @@ describe('DrawingService', () => {
|
|||||||
'y': 100,
|
'y': 100,
|
||||||
'svg': svgSample
|
'svg': svgSample
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should update drawing', inject([DrawingService], (service: DrawingService) => {
|
it('should update drawing', inject([DrawingService], (service: DrawingService) => {
|
||||||
const drawing = new Drawing();
|
const drawing = new Drawing();
|
||||||
|
Reference in New Issue
Block a user