From 1535166837ec693422e898c8856845eb8a8dbf1a Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Mon, 25 Feb 2019 03:20:21 -0800 Subject: [PATCH] Unit tests added --- .../delete-action.component.spec.ts | 22 ++++++++++++++++++- .../context-menu.component.spec.ts | 2 +- .../project-map/project-map.component.spec.ts | 7 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.spec.ts b/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.spec.ts index 558026cb..ec6a8f5c 100644 --- a/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.spec.ts +++ b/src/app/components/project-map/context-menu/actions/delete-action/delete-action.component.spec.ts @@ -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; 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(); + }); }); diff --git a/src/app/components/project-map/context-menu/context-menu.component.spec.ts b/src/app/components/project-map/context-menu/context-menu.component.spec.ts index 30c60aef..7832fb7e 100644 --- a/src/app/components/project-map/context-menu/context-menu.component.spec.ts +++ b/src/app/components/project-map/context-menu/context-menu.component.spec.ts @@ -70,7 +70,7 @@ describe('ContextMenuComponent', () => { component.contextMenu = { openMenu() {} } as MatMenuTrigger; var spy = spyOn(component, 'resetCapabilities'); spyOn(component, 'setPosition').and.callFake(() => {}); - component.openMenuForListOfElements([], [], [], 0, 0); + component.openMenuForListOfElements([], [], [], [], 0, 0); expect(spy.calls.any()).toBeTruthy(); }); diff --git a/src/app/components/project-map/project-map.component.spec.ts b/src/app/components/project-map/project-map.component.spec.ts index 27574d81..f5805c56 100644 --- a/src/app/components/project-map/project-map.component.spec.ts +++ b/src/app/components/project-map/project-map.component.spec.ts @@ -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 },