mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-21 18:06:38 +00:00
Unit tests for new components added
This commit is contained in:
parent
32646889df
commit
af1957915b
@ -0,0 +1,53 @@
|
|||||||
|
import { DrawingAddingComponent } from "./drawing-adding.component";
|
||||||
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { DrawingsEventSource } from '../../events/drawings-event-source';
|
||||||
|
import { Context } from '../../models/context';
|
||||||
|
|
||||||
|
describe('DrawingAddingComponent', () => {
|
||||||
|
let component: DrawingAddingComponent;
|
||||||
|
let fixture: ComponentFixture<DrawingAddingComponent>;
|
||||||
|
let drawingsEventSource = new DrawingsEventSource();
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
NoopAnimationsModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: DrawingsEventSource, useValue: drawingsEventSource },
|
||||||
|
{ provide: Context, useClass: Context }
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
DrawingAddingComponent
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DrawingAddingComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should deactivate listener when none of the available drawings is selected', () => {
|
||||||
|
spyOn(component, 'deactivate');
|
||||||
|
|
||||||
|
drawingsEventSource.selected.emit("");
|
||||||
|
|
||||||
|
expect(component.deactivate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should activate listener when drawing is selected', () => {
|
||||||
|
spyOn(component, 'activate');
|
||||||
|
|
||||||
|
drawingsEventSource.selected.emit("rectangle");
|
||||||
|
|
||||||
|
expect(component.activate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
@ -2,6 +2,7 @@ import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
|||||||
import { Context } from '../../models/context';
|
import { Context } from '../../models/context';
|
||||||
import { DrawingsEventSource } from '../../events/drawings-event-source';
|
import { DrawingsEventSource } from '../../events/drawings-event-source';
|
||||||
import { AddedDataEvent } from '../../events/event-source';
|
import { AddedDataEvent } from '../../events/event-source';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -13,6 +14,7 @@ export class DrawingAddingComponent implements OnInit, OnDestroy {
|
|||||||
@Input('svg') svg: SVGSVGElement;
|
@Input('svg') svg: SVGSVGElement;
|
||||||
|
|
||||||
private mapListener: Function;
|
private mapListener: Function;
|
||||||
|
private drawingSelected: Subscription;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private drawingsEventSource: DrawingsEventSource,
|
private drawingsEventSource: DrawingsEventSource,
|
||||||
@ -20,7 +22,7 @@ export class DrawingAddingComponent implements OnInit, OnDestroy {
|
|||||||
){}
|
){}
|
||||||
|
|
||||||
ngOnInit(){
|
ngOnInit(){
|
||||||
this.drawingsEventSource.selected.subscribe((evt) => {
|
this.drawingSelected = this.drawingsEventSource.selected.subscribe((evt) => {
|
||||||
evt === "" ? this.deactivate() : this.activate();
|
evt === "" ? this.deactivate() : this.activate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -44,6 +46,6 @@ export class DrawingAddingComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(){
|
ngOnDestroy(){
|
||||||
this.drawingsEventSource.selected.unsubscribe();
|
this.drawingSelected.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ export class DrawingWidgetMock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('DrawizngResizingComponent', () => {
|
describe('DrawingResizingComponent', () => {
|
||||||
let component: DrawingResizingComponent;
|
let component: DrawingResizingComponent;
|
||||||
let fixture: ComponentFixture<DrawingResizingComponent>;
|
let fixture: ComponentFixture<DrawingResizingComponent>;
|
||||||
let drawingsWidgetMock = new DrawingWidgetMock;
|
let drawingsWidgetMock = new DrawingWidgetMock;
|
||||||
@ -47,15 +47,15 @@ describe('DrawizngResizingComponent', () => {
|
|||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(DrawingResizingComponent);
|
fixture = TestBed.createComponent(DrawingResizingComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit event after size changes', () => {
|
it('should emit event after size changes', () => {
|
||||||
spyOn(drawingsEventSource.resized, 'emit');
|
spyOn(drawingsEventSource.resized, 'emit');
|
||||||
|
@ -6,6 +6,7 @@ import { MapDrawing } from '../../models/map/map-drawing';
|
|||||||
import { ResizedDataEvent } from '../../events/event-source';
|
import { ResizedDataEvent } from '../../events/event-source';
|
||||||
import { ResizingEnd } from '../../events/resizing';
|
import { ResizingEnd } from '../../events/resizing';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-drawing-resizing',
|
selector: 'app-drawing-resizing',
|
||||||
template: `<ng-content></ng-content>`,
|
template: `<ng-content></ng-content>`,
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
import { DrawingAddedComponent } from "./drawing-added.component";
|
||||||
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
import { DrawingService } from '../../../services/drawing.service';
|
||||||
|
import { DrawingsDataSource } from '../../../cartography/datasources/drawings-datasource';
|
||||||
|
import { DrawingsEventSource } from '../../../cartography/events/drawings-event-source';
|
||||||
|
import { DefaultDrawingsFactory } from '../../../cartography/helpers/default-drawings-factory';
|
||||||
|
import { MapDrawingToSvgConverter } from '../../../cartography/converters/map/map-drawing-to-svg-converter';
|
||||||
|
import { MockedDrawingService, MockedDrawingsDataSource } from '../../project-map/project-map.component.spec';
|
||||||
|
import { TextElementFactory } from '../../../cartography/helpers/drawings-factory/text-element-factory';
|
||||||
|
import { EllipseElementFactory } from '../../../cartography/helpers/drawings-factory/ellipse-element-factory';
|
||||||
|
import { RectangleElementFactory } from '../../../cartography/helpers/drawings-factory/rectangle-element-factory';
|
||||||
|
import { LineElementFactory } from '../../../cartography/helpers/drawings-factory/line-element-factory';
|
||||||
|
import { Project } from '../../../models/project';
|
||||||
|
import { AddedDataEvent } from '../../../cartography/events/event-source';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
describe('DrawingAddedComponent', () => {
|
||||||
|
let component: DrawingAddedComponent;
|
||||||
|
let fixture: ComponentFixture<DrawingAddedComponent>;
|
||||||
|
let mockedDrawingService = new MockedDrawingService;
|
||||||
|
let mockedDrawingsDataSource = new MockedDrawingsDataSource;
|
||||||
|
let mockedDrawingsEventSource = new DrawingsEventSource;
|
||||||
|
let mockedDrawingsFactory = new DefaultDrawingsFactory(new TextElementFactory,
|
||||||
|
new EllipseElementFactory, new RectangleElementFactory, new LineElementFactory);
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
{ provide: DrawingService, useValue: mockedDrawingService },
|
||||||
|
{ provide: DrawingsDataSource, useValue: mockedDrawingsDataSource },
|
||||||
|
{ provide: DrawingsEventSource, useValue: mockedDrawingsEventSource },
|
||||||
|
{ provide: DefaultDrawingsFactory, useValue: mockedDrawingsFactory },
|
||||||
|
{ provide: MapDrawingToSvgConverter, useClass: MapDrawingToSvgConverter }
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
DrawingAddedComponent
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DrawingAddedComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call drawing service when point to add drawing selected', () => {
|
||||||
|
component.project = { project_id: "sampleId" } as Project;
|
||||||
|
component.selectedDrawing = "rectangle";
|
||||||
|
const pointToAddSelectedDataEvent = new AddedDataEvent(0, 0);
|
||||||
|
spyOn(mockedDrawingService, 'add').and.returnValue( Observable.of({}));
|
||||||
|
|
||||||
|
mockedDrawingsEventSource.pointToAddSelected.emit(pointToAddSelectedDataEvent);
|
||||||
|
|
||||||
|
expect(mockedDrawingService.add).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
@ -6,7 +6,6 @@ import { Server } from '../../../models/server';
|
|||||||
import { Project } from '../../../models/project';
|
import { Project } from '../../../models/project';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { DrawingService } from '../../../services/drawing.service';
|
import { DrawingService } from '../../../services/drawing.service';
|
||||||
import { Context } from '../../../cartography/models/context';
|
|
||||||
import { Drawing } from '../../../cartography/models/drawing';
|
import { Drawing } from '../../../cartography/models/drawing';
|
||||||
import { MapDrawingToSvgConverter } from '../../../cartography/converters/map/map-drawing-to-svg-converter';
|
import { MapDrawingToSvgConverter } from '../../../cartography/converters/map/map-drawing-to-svg-converter';
|
||||||
import { AddedDataEvent } from '../../../cartography/events/event-source';
|
import { AddedDataEvent } from '../../../cartography/events/event-source';
|
||||||
@ -29,8 +28,7 @@ export class DrawingAddedComponent implements OnInit, OnDestroy{
|
|||||||
private drawingsDataSource: DrawingsDataSource,
|
private drawingsDataSource: DrawingsDataSource,
|
||||||
private drawingsEventSource: DrawingsEventSource,
|
private drawingsEventSource: DrawingsEventSource,
|
||||||
private drawingsFactory: DefaultDrawingsFactory,
|
private drawingsFactory: DefaultDrawingsFactory,
|
||||||
private mapDrawingToSvgConverter: MapDrawingToSvgConverter,
|
private mapDrawingToSvgConverter: MapDrawingToSvgConverter
|
||||||
private context: Context
|
|
||||||
){}
|
){}
|
||||||
|
|
||||||
ngOnInit(){
|
ngOnInit(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user