gns3-web-ui/src/app/app.component.spec.ts

75 lines
2.6 KiB
TypeScript
Raw Normal View History

import { TestBed, async, ComponentFixture } from '@angular/core/testing';
2017-10-19 10:16:59 +00:00
import { RouterTestingModule } from '@angular/router/testing';
2017-09-25 11:07:52 +00:00
import { AppComponent } from './app.component';
import { MatIconModule } from "@angular/material";
import { SettingsService } from "./shared/services/settings.service";
import { PersistenceService } from "angular-persistence";
import { ElectronService, NgxElectronModule } from "ngx-electron";
import createSpyObj = jasmine.createSpyObj;
2017-09-25 11:07:52 +00:00
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let electronService: ElectronService;
let settingsService: SettingsService;
2017-09-25 11:07:52 +00:00
beforeEach(async(() => {
TestBed.configureTestingModule({
2017-10-19 10:16:59 +00:00
declarations: [
AppComponent
2017-10-19 10:16:59 +00:00
],
imports: [
RouterTestingModule,
MatIconModule,
NgxElectronModule
],
providers: [
SettingsService,
PersistenceService,
2017-10-19 10:16:59 +00:00
]
2017-09-25 11:07:52 +00:00
}).compileComponents();
electronService = TestBed.get(ElectronService);
settingsService = TestBed.get(SettingsService);
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create the app', async(() => {
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it('should have footer', async(() => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('router-outlet').textContent).toEqual('');
2017-09-25 11:07:52 +00:00
}));
it('should receive changed settings and forward to electron', async(() => {
const spy = createSpyObj('Electron.IpcRenderer', ['send']);
spyOnProperty(electronService, 'isElectronApp').and.returnValue(true);
spyOnProperty(electronService, 'ipcRenderer').and.returnValue(spy);
settingsService.set('crash_reports', true);
component.ngOnInit();
settingsService.set('crash_reports', false);
expect(spy.send).toHaveBeenCalled();
expect(spy.send.calls.first().args[0]).toEqual('settings.changed');
expect(spy.send.calls.first().args[1].crash_reports).toEqual(false);
}));
it('should receive changed settings and do not forward to electron', async(() => {
const spy = createSpyObj('Electron.IpcRenderer', ['send']);
spyOnProperty(electronService, 'isElectronApp').and.returnValue(false);
settingsService.set('crash_reports', true);
component.ngOnInit();
settingsService.set('crash_reports', false);
expect(spy.send).not.toHaveBeenCalled();
}));
2017-09-25 11:07:52 +00:00
});