Unit tests added

This commit is contained in:
Piotr Pekala 2019-08-12 05:40:40 -07:00
parent 528842b713
commit cd365798bb
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,66 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BringToFrontActionComponent } from './bring-to-front-action.component';
import { MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule } from '@angular/material';
import { CommonModule } from '@angular/common';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MockedDrawingService, MockedDrawingsDataSource, MockedNodesDataSource, MockedNodeService } from '../../../project-map.component.spec';
import { DrawingService } from '../../../../../services/drawing.service';
import { NodesDataSource } from '../../../../../cartography/datasources/nodes-datasource';
import { DrawingsDataSource } from '../../../../../cartography/datasources/drawings-datasource';
import { NodeService } from '../../../../../services/node.service';
import { Node } from '../../../../../cartography/models/node';
import { of } from 'rxjs';
import { ComponentFactoryResolver } from '@angular/core';
import { Drawing } from '../../../../../cartography/models/drawing';
describe('BringToFrontActionComponent', () => {
let component: BringToFrontActionComponent;
let fixture: ComponentFixture<BringToFrontActionComponent>;
let drawingService = new MockedDrawingService();
let drawingsDataSource = new MockedDrawingsDataSource();
let nodeService = new MockedNodeService();
let nodesDataSource = new MockedNodesDataSource();
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatIconModule, MatToolbarModule, MatMenuModule, MatCheckboxModule, CommonModule, NoopAnimationsModule],
providers: [
{ provide: DrawingService, useValue: drawingService },
{ provide: DrawingsDataSource, useValue: drawingsDataSource },
{ provide: NodeService, useValue: nodeService },
{ provide: NodesDataSource, useValue: nodesDataSource },
],
declarations: [BringToFrontActionComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BringToFrontActionComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call node service when bring to front action called', () => {
spyOn(nodeService, 'update').and.returnValue(of());
component.nodes = [{z: 0} as Node];
component.drawings = [];
component.bringToFront();
expect(nodeService.update).toHaveBeenCalled();
});
it('should call drawing service when bring to front action called', () => {
spyOn(drawingService, 'update').and.returnValue(of());
component.nodes = [];
component.drawings = [{z: 0} as Drawing];
component.bringToFront();
expect(drawingService.update).toHaveBeenCalled();
});
});

View File

@ -94,6 +94,10 @@ export class MockedNodeService {
duplicate(server: Server, node: Node) {
return of(node);
}
update(server: Server, node: Node) {
return of(node);
}
}
export class MockedDrawingService {