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

65 lines
2.5 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';
2019-01-15 10:15:54 +00:00
import { MatIconModule } from '@angular/material';
import { SettingsService } from './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({
2019-01-15 10:15:54 +00:00
declarations: [AppComponent],
imports: [RouterTestingModule, MatIconModule, NgxElectronModule],
providers: [SettingsService, PersistenceService]
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();
2018-04-09 07:19:35 +00:00
expect(spy.send.calls.mostRecent().args[0]).toEqual('settings.changed');
expect(spy.send.calls.mostRecent().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
});