Update log-console.component.spec.ts

This commit is contained in:
Piotr Pekala 2019-08-26 06:48:43 -07:00
parent 801b3ebfac
commit 40ef11edbe

View File

@ -1,6 +1,6 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserModule } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA, EventEmitter } from '@angular/core';
import { NO_ERRORS_SCHEMA, EventEmitter, inject } from '@angular/core';
import { MatMenuModule } from '@angular/material';
import { Server } from '../../../models/server';
import { LogConsoleComponent } from './log-console.component';
@ -10,6 +10,9 @@ import { MockedNodeService, MockedNodesDataSource } from '../project-map.compone
import { NodesDataSource } from '../../../cartography/datasources/nodes-datasource';
import { of } from 'rxjs';
import { LogEventsDataSource } from './log-events-datasource';
import { HttpServer, ServerErrorHandler } from '../../../services/http-server.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClient } from '@angular/common/http';
export class MockedProjectWebServiceHandler {
public nodeNotificationEmitter = new EventEmitter<WebServiceMessage>();
@ -25,14 +28,17 @@ describe('LogConsoleComponent', () => {
let mockedNodesDataSource: MockedNodesDataSource = new MockedNodesDataSource();
let mockedProjectWebServiceHandler: MockedProjectWebServiceHandler = new MockedProjectWebServiceHandler();
let httpServer = new HttpServer({} as HttpClient, {} as ServerErrorHandler);
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatMenuModule, BrowserModule],
imports: [HttpClientTestingModule, MatMenuModule, BrowserModule],
providers: [
{ provide: ProjectWebServiceHandler, useValue: mockedProjectWebServiceHandler },
{ provide: NodeService, useValue: mockedNodeService },
{ provide: NodesDataSource, useValue: mockedNodesDataSource },
{ provide: LogEventsDataSource, useClass: LogEventsDataSource }
{ provide: LogEventsDataSource, useClass: LogEventsDataSource },
{ provide: HttpServer, useValue: httpServer }
],
declarations: [LogConsoleComponent],
schemas: [NO_ERRORS_SCHEMA]
@ -56,7 +62,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Available commands: help, version, start all, start {node name}, stop all, stop {node name}, suspend all, suspend {node name}, reload all, reload {node name}, show {node name}.');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Available commands: help, version, start all, start {node name}, stop all, stop {node name}, suspend all, suspend {node name}, reload all, reload {node name}, show {node name}.'});
});
it('should call show message when version command entered', () => {
@ -65,7 +71,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Current version: 2019.2.0');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Current version: 2019.2.0'});
});
it('should call show message when unknown command entered', () => {
@ -74,7 +80,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Unknown syntax: xyz');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Unknown syntax: xyz'});
});
it('should call node service when start all entered', () => {
@ -84,7 +90,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Starting all nodes...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Starting all nodes...'});
expect(mockedNodeService.startAll).toHaveBeenCalled();
});
@ -95,7 +101,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Stopping all nodes...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Stopping all nodes...'});
expect(mockedNodeService.stopAll).toHaveBeenCalled();
});
@ -106,7 +112,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Suspending all nodes...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Suspending all nodes...'});
expect(mockedNodeService.suspendAll).toHaveBeenCalled();
});
@ -117,7 +123,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Reloading all nodes...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Reloading all nodes...'});
expect(mockedNodeService.reloadAll).toHaveBeenCalled();
});
@ -128,7 +134,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Starting node testNode...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Starting node testNode...'});
expect(mockedNodeService.start).toHaveBeenCalled();
});
@ -139,7 +145,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Stopping node testNode...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Stopping node testNode...'});
expect(mockedNodeService.stop).toHaveBeenCalled();
});
@ -150,7 +156,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Suspending node testNode...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Suspending node testNode...'});
expect(mockedNodeService.suspend).toHaveBeenCalled();
});
@ -161,7 +167,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith('Reloading node testNode...');
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Reloading node testNode...'});
expect(mockedNodeService.reload).toHaveBeenCalled();
});
});