Stabilize unit tests #1010

This commit is contained in:
piotrpekala7 2020-11-09 01:27:37 +01:00
parent 165ab06fde
commit 99b90db6ed
6 changed files with 42 additions and 3 deletions

1
debug.log Normal file
View File

@ -0,0 +1 @@
[1109/003452.026:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)

View File

@ -0,0 +1,33 @@
import { ConsoleWrapperComponent } from "./console-wrapper.component";
import { NodeConsoleService } from '../../../services/nodeConsole.service';
import { ThemeService } from '../../../services/theme.service';
import { MapSettingsService } from '../../../services/mapsettings.service';
describe('ConsoleWrapperComponent', () => {
it('should get actual theme', () => {
const consoleService = new NodeConsoleService();
const themeService = autoSpy(ThemeService);
themeService.getActualTheme.and.returnValue('light');
const mapSettingsService = autoSpy(MapSettingsService);
const component = new ConsoleWrapperComponent(consoleService, themeService, mapSettingsService);
component.ngOnInit();
expect(component.isLightThemeEnabled).toBe(true);
});
});
export type SpyOf<T> = T & { [k in keyof T]: jasmine.Spy };
export function autoSpy<T>(obj: new (...args: any[]) => T): SpyOf<T> {
const res: SpyOf<T> = {} as any;
const keys = Object.getOwnPropertyNames(obj.prototype);
keys.forEach((key) => {
res[key] = jasmine.createSpy(key);
});
return res;
}

View File

@ -17,7 +17,7 @@ import { Node } from '../../../cartography/models/node';
import { ConsoleDeviceActionComponent } from '../context-menu/actions/console-device-action/console-device-action.component';
import { ConsoleDeviceActionBrowserComponent } from '../context-menu/actions/console-device-action-browser/console-device-action-browser.component';
fdescribe('ContextConsoleMenuComponent', () => {
describe('ContextConsoleMenuComponent', () => {
let component: ContextConsoleMenuComponent;
let fixture: ComponentFixture<ContextConsoleMenuComponent>;
let toasterService: MockedToasterService = new MockedToasterService();

View File

@ -76,7 +76,7 @@ describe('LogConsoleComponent', () => {
component.handleCommand();
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Current version: 2020.3.0-beta.4'});
expect(component.showMessage).toHaveBeenCalledWith({type: 'command', message: 'Current version: 2.2.16'});
});
it('should call show message when unknown command entered', () => {

View File

@ -15,6 +15,8 @@ import { ToasterService } from '../../services/toaster.service';
import { MockedToasterService } from '../../services/toaster.service.spec';
import { ConsoleService } from '../../services/settings/console.service';
import { MapSettingsService } from '../../services/mapsettings.service';
import { UpdatesService } from '../../services/updates.service';
import { autoSpy } from '../project-map/console-wrapper/console-wrapper.component.spec';
describe('SettingsComponent', () => {
let component: SettingsComponent;
@ -25,6 +27,7 @@ describe('SettingsComponent', () => {
toggleIntegrateInterfaceLabels(val: boolean) {}
};
let consoleService;
let updatesService = autoSpy(UpdatesService);
beforeEach(async(() => {
consoleService = {
@ -37,7 +40,8 @@ describe('SettingsComponent', () => {
SettingsService,
{ provide: ToasterService, useClass: MockedToasterService },
{ provide: ConsoleService, useValue: consoleService },
{ provide: MapSettingsService, useValue: mapSettingsService }
{ provide: MapSettingsService, useValue: mapSettingsService },
{ provide: UpdatesService, useValue: updatesService }
],
declarations: [SettingsComponent]
}).compileComponents();

View File

@ -150,6 +150,7 @@ describe('ServerService', () => {
expectedServer.host = 'hostname';
expectedServer.port = 9999;
expectedServer.location = 'bundled';
expectedServer.protocol = 'http:';
service.getLocalServer('hostname', 9999).then(() => {
expect(service.create).toHaveBeenCalledWith(expectedServer);