mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-19 04:57:51 +00:00
Unit tests added
This commit is contained in:
parent
c063620cbf
commit
1535166837
@ -6,16 +6,20 @@ import { NodesDataSource } from '../../../../../cartography/datasources/nodes-da
|
||||
import { DrawingsDataSource } from '../../../../../cartography/datasources/drawings-datasource';
|
||||
import { NodeService } from '../../../../../services/node.service';
|
||||
import { DrawingService } from '../../../../../services/drawing.service';
|
||||
import { MockedDrawingService, MockedNodeService } from '../../../project-map.component.spec';
|
||||
import { MockedDrawingService, MockedNodeService, MockedLinkService } from '../../../project-map.component.spec';
|
||||
import { Node } from '../../../../../cartography/models/node';
|
||||
import { Drawing } from '../../../../../cartography/models/drawing';
|
||||
import { of } from 'rxjs';
|
||||
import { LinksDataSource } from '../../../../../cartography/datasources/links-datasource';
|
||||
import { LinkService } from '../../../../../services/link.service';
|
||||
import { Link } from '../../../../../models/link';
|
||||
|
||||
describe('DeleteActionComponent', () => {
|
||||
let component: DeleteActionComponent;
|
||||
let fixture: ComponentFixture<DeleteActionComponent>;
|
||||
let mockedNodeService: MockedNodeService = new MockedNodeService();
|
||||
let mockedDrawingService: MockedDrawingService = new MockedDrawingService();
|
||||
let mockedLinkService: MockedLinkService = new MockedLinkService();
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@ -23,8 +27,10 @@ describe('DeleteActionComponent', () => {
|
||||
providers: [
|
||||
{ provide: NodesDataSource, useClass: NodesDataSource },
|
||||
{ provide: DrawingsDataSource, useClass: DrawingsDataSource },
|
||||
{ provide: LinksDataSource, useClass: LinksDataSource },
|
||||
{ provide: NodeService, useValue: mockedNodeService },
|
||||
{ provide: DrawingService, useValue: mockedDrawingService },
|
||||
{ provide: LinkService, useValue: mockedLinkService }
|
||||
],
|
||||
declarations: [DeleteActionComponent]
|
||||
}).compileComponents();
|
||||
@ -45,6 +51,7 @@ describe('DeleteActionComponent', () => {
|
||||
component.nodes = [node];
|
||||
let drawing = { drawing_id: '1' } as Drawing;
|
||||
component.drawings = [drawing];
|
||||
component.links = [];
|
||||
spyOn(mockedDrawingService, 'delete').and.returnValue(of());
|
||||
|
||||
component.delete();
|
||||
@ -57,10 +64,23 @@ describe('DeleteActionComponent', () => {
|
||||
component.nodes = [node];
|
||||
let drawing = { drawing_id: '1' } as Drawing;
|
||||
component.drawings = [drawing];
|
||||
component.links = [];
|
||||
spyOn(mockedNodeService, 'delete').and.returnValue(of());
|
||||
|
||||
component.delete();
|
||||
|
||||
expect(mockedNodeService.delete).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call delete action in link service', () => {
|
||||
component.nodes = [];
|
||||
component.drawings = [];
|
||||
let link = { link_id: '1', project_id: '1' } as Link;
|
||||
component.links = [link];
|
||||
spyOn(mockedLinkService, 'deleteLink').and.returnValue(of());
|
||||
|
||||
component.delete();
|
||||
|
||||
expect(mockedLinkService.deleteLink).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@ -70,7 +70,7 @@ describe('ContextMenuComponent', () => {
|
||||
component.contextMenu = { openMenu() {} } as MatMenuTrigger;
|
||||
var spy = spyOn<any>(component, 'resetCapabilities');
|
||||
spyOn(component, 'setPosition').and.callFake(() => {});
|
||||
component.openMenuForListOfElements([], [], [], 0, 0);
|
||||
component.openMenuForListOfElements([], [], [], [], 0, 0);
|
||||
|
||||
expect(spy.calls.any()).toBeTruthy();
|
||||
});
|
||||
|
@ -37,6 +37,8 @@ import { MapLabelToLabelConverter } from '../../cartography/converters/map/map-l
|
||||
import { SelectionManager } from '../../cartography/managers/selection-manager';
|
||||
import { SelectionTool } from '../../cartography/tools/selection-tool';
|
||||
import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProject.service';
|
||||
import { MapLinkToLinkConverter } from '../../cartography/converters/map/map-link-to-link-converter';
|
||||
import { Link } from '../../models/link';
|
||||
|
||||
export class MockedProgressService {
|
||||
public activate() {}
|
||||
@ -91,6 +93,10 @@ export class MockedDrawingService {
|
||||
export class MockedLinkService {
|
||||
constructor() {}
|
||||
|
||||
deleteLink(_server: Server, link: Link){
|
||||
return of({})
|
||||
}
|
||||
|
||||
createLink() {
|
||||
return of({});
|
||||
}
|
||||
@ -148,6 +154,7 @@ describe('ProjectMapComponent', () => {
|
||||
{ provide: MapNodeToNodeConverter },
|
||||
{ provide: MapDrawingToDrawingConverter },
|
||||
{ provide: MapLabelToLabelConverter },
|
||||
{ provide: MapLinkToLinkConverter },
|
||||
{ provide: NodesDataSource },
|
||||
{ provide: LinksDataSource },
|
||||
{ provide: DrawingsDataSource, useValue: drawingsDataSource },
|
||||
|
Loading…
Reference in New Issue
Block a user