mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-15 21:56:18 -08:00
test: increase test coverage
This commit is contained in:
1 parent
c0255c8a48
commit
21316cef3d
11 files changed
+216
-110
No files matched your search
@@ -2,7 +2,7 @@ import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { StorageMap } from '@ngx-pwa/local-storage';
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import { ElectronService } from './../services/electron.service';
|
||||
import { ElectronServiceStub } from './../home/home.component.spec';
|
||||
import { ElectronServiceStub } from '../services/electron.service.stub';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
@@ -21,6 +21,10 @@ import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { EPG_FETCH } from '../../../shared/ipc-commands';
|
||||
import { Router } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
import { VideoPlayer } from './settings.interface';
|
||||
import { Language } from './language.enum';
|
||||
import { Theme } from './theme.enum';
|
||||
|
||||
class MatSnackBarStub {
|
||||
open(): void {}
|
||||
@@ -32,11 +36,21 @@ export class MockRouter {
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
player: VideoPlayer.VideoJs,
|
||||
epgUrl: '',
|
||||
language: Language.ENGLISH,
|
||||
showCaptions: false,
|
||||
theme: Theme.LightTheme
|
||||
}
|
||||
|
||||
describe('SettingsComponent', () => {
|
||||
let component: SettingsComponent;
|
||||
let fixture: ComponentFixture<SettingsComponent>;
|
||||
let electronService: ElectronService;
|
||||
let router: Router;
|
||||
let storage: StorageMap;
|
||||
let translate: TranslateService;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
@@ -80,7 +94,9 @@ describe('SettingsComponent', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SettingsComponent);
|
||||
electronService = TestBed.inject(ElectronService);
|
||||
storage = TestBed.inject(StorageMap);
|
||||
router = TestBed.inject(Router);
|
||||
translate = TestBed.inject(TranslateService);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
@@ -89,10 +105,63 @@ describe('SettingsComponent', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('Get and set settings on component init', () => {
|
||||
const settings = {player: 'test', showCaptions: true};
|
||||
let spyOnStorageGet;
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnStorageGet = spyOn(storage, 'get');
|
||||
})
|
||||
|
||||
it('should init default settings if previous config was not saved', () => {
|
||||
spyOnStorageGet.and.returnValue(of(null));
|
||||
spyOn(component.settingsForm, 'setValue');
|
||||
component.ngOnInit();
|
||||
expect(storage.get).toHaveBeenCalled();
|
||||
expect(component.settingsForm.setValue).toHaveBeenCalledTimes(0);
|
||||
expect(component.settingsForm.value).toEqual(DEFAULT_SETTINGS);
|
||||
});
|
||||
|
||||
it('should call set value function if custom config exists', () => {
|
||||
spyOnStorageGet.and.returnValue(of(settings));
|
||||
spyOn(component.settingsForm, 'setValue');
|
||||
component.ngOnInit();
|
||||
expect(component.settingsForm.setValue).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should get and apply custom settings', () => {
|
||||
spyOnStorageGet.and.returnValue(of(settings));
|
||||
component.ngOnInit();
|
||||
expect(storage.get).toHaveBeenCalled();
|
||||
expect(component.settingsForm.value).toEqual({...DEFAULT_SETTINGS, ...settings});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe.only('Version check', () => {
|
||||
const latestVersion = '1.0.0';
|
||||
const currentVersion = '0.1.0';
|
||||
|
||||
it('should return true if version is outdated', () => {
|
||||
spyOn(electronService, 'getAppVersion').and.returnValue(currentVersion);
|
||||
const isOutdated = component.isCurrentVersionOutdated(latestVersion);
|
||||
expect(isOutdated).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should update notification message if version is outdated', () => {
|
||||
spyOn(translate, 'instant');
|
||||
spyOn(electronService, 'getAppVersion').and.returnValue(currentVersion);
|
||||
component.showVersionInformation(currentVersion);
|
||||
fixture.detectChanges();
|
||||
expect(translate.instant).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should send epg fetch command', () => {
|
||||
spyOn(electronService.ipcRenderer, 'send');
|
||||
spyOn(electronService, 'sendIpcEvent');
|
||||
component.fetchEpg();
|
||||
expect(electronService.ipcRenderer.send).toHaveBeenCalledWith(
|
||||
expect(electronService.sendIpcEvent).toHaveBeenCalledWith(
|
||||
EPG_FETCH,
|
||||
{ url: '' }
|
||||
);
|
||||
@@ -103,4 +172,10 @@ describe('SettingsComponent', () => {
|
||||
component.backToHome();
|
||||
expect(router.navigateByUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should save settings on submit', () => {
|
||||
spyOn(storage, 'set').and.returnValue(of([]));
|
||||
component.onSubmit();
|
||||
expect(storage.set).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user