2018-04-06 08:03:16 +00:00
|
|
|
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';
|
2018-04-06 08:03:16 +00:00
|
|
|
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', () => {
|
2018-04-06 08:03:16 +00:00
|
|
|
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: [
|
2018-04-06 08:03:16 +00:00
|
|
|
AppComponent
|
2017-10-19 10:16:59 +00:00
|
|
|
],
|
|
|
|
imports: [
|
2018-04-06 08:03:16 +00:00
|
|
|
RouterTestingModule,
|
|
|
|
MatIconModule,
|
|
|
|
NgxElectronModule
|
|
|
|
],
|
|
|
|
providers: [
|
|
|
|
SettingsService,
|
|
|
|
PersistenceService,
|
2017-10-19 10:16:59 +00:00
|
|
|
]
|
2017-09-25 11:07:52 +00:00
|
|
|
}).compileComponents();
|
2018-04-06 08:03:16 +00:00
|
|
|
|
|
|
|
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
|
|
|
}));
|
|
|
|
|
2018-04-06 08:03:16 +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
|
|
|
});
|