diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index e2fddadae..11819a7e8 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -12,7 +12,6 @@ import { TranslatePipe, TranslateService, } from '@ngx-translate/core'; -import { ElectronService } from './services/electron.service'; import { ElectronServiceStub } from './services/electron.service.stub'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { MockModule, MockPipe } from 'ng-mocks'; @@ -24,6 +23,7 @@ import { Router } from '@angular/router'; import { ChannelStore } from './state'; import { STORE_KEY } from './shared/enums/store-keys.enum'; import { WhatsNewServiceStub } from './services/whats-new.service.stub'; +import { DataService } from './services/data.service'; jest.mock('custom-electron-titlebar', () => { return { @@ -42,7 +42,7 @@ class MatSnackBarStub { describe('AppComponent', () => { let component: AppComponent; - let electronService: ElectronService; + let electronService: DataService; let fixture: ComponentFixture; let settingsService: SettingsService; let translateService: TranslateService; @@ -54,11 +54,14 @@ describe('AppComponent', () => { TestBed.configureTestingModule({ declarations: [AppComponent, MockPipe(TranslatePipe)], providers: [ - { provide: ElectronService, useClass: ElectronServiceStub }, { provide: MatSnackBar, useClass: MatSnackBarStub }, { provide: WhatsNewService, useClass: WhatsNewServiceStub }, TranslateService, SettingsService, // TODO: stub + { + provide: DataService, + useClass: ElectronServiceStub, + }, ], imports: [ MockModule(MatSnackBarModule), @@ -71,7 +74,7 @@ describe('AppComponent', () => { ); beforeEach(() => { - electronService = TestBed.inject(ElectronService); + electronService = TestBed.inject(DataService); fixture = TestBed.createComponent(AppComponent); settingsService = TestBed.inject(SettingsService); translateService = TestBed.inject(TranslateService); @@ -227,7 +230,7 @@ describe('AppComponent', () => { const epgUrl = 'http://localhost/epg.xml'; beforeEach(() => { - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); spyOn(settingsService, 'changeTheme'); spyOn(component, 'handleWhatsNewDialog'); spyOn(translateService, 'use'); diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index ab0ac6cb4..9b462d7f8 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -16,10 +16,10 @@ import { MatIconModule } from '@angular/material/icon'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { RouterTestingModule } from '@angular/router/testing'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; -import { ElectronService } from '../services/electron.service'; import { Router } from '@angular/router'; import { DialogService } from '../services/dialog.service'; import { ElectronServiceStub } from '../services/electron.service.stub'; +import { DataService } from '../services/data.service'; class MatSnackBarStub { open(): void {} @@ -29,7 +29,7 @@ describe('HomeComponent', () => { let component: HomeComponent; let dialogService: DialogService; let fixture: ComponentFixture; - let electronService: ElectronService; + let electronService: DataService; let router: Router; beforeEach(() => { @@ -51,7 +51,7 @@ describe('HomeComponent', () => { ], providers: [ { provide: MatSnackBar, useClass: MatSnackBarStub }, - { provide: ElectronService, useClass: ElectronServiceStub }, + { provide: DataService, useClass: ElectronServiceStub }, MockProvider(DialogService), MockProvider(TranslateService), ], @@ -61,10 +61,9 @@ describe('HomeComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(HomeComponent); component = fixture.componentInstance; - electronService = TestBed.inject(ElectronService); + electronService = TestBed.inject(DataService); dialogService = TestBed.inject(DialogService); router = TestBed.inject(Router); - TestBed.inject(ElectronService); fixture.detectChanges(); }); @@ -81,7 +80,7 @@ describe('HomeComponent', () => { it('should send an event to the main process to remove a playlist', () => { const playlistId = '12345'; - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); component.removePlaylist(playlistId); expect(electronService.sendIpcEvent).toHaveBeenCalledWith( 'playlist-remove-by-id', @@ -94,7 +93,7 @@ describe('HomeComponent', () => { _id: 'iptv1', filePath: '/home/user/lists/iptv.m3u', } as PlaylistMeta; - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); component.refreshPlaylist(playlistMeta); expect(electronService.sendIpcEvent).toHaveBeenCalledWith( PLAYLIST_UPDATE, @@ -104,7 +103,7 @@ describe('HomeComponent', () => { it('should send an event to the main process to get a playlist', () => { const playlistId = '6789'; - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); component.getPlaylist(playlistId); expect(electronService.sendIpcEvent).toHaveBeenCalledWith( 'playlist-by-id', @@ -117,7 +116,7 @@ describe('HomeComponent', () => { it('should send an event to the main process to get a playlist by URL', () => { const playlistTitle = 'playlist.m3u'; const playlistUrl = 'http://test.com/' + playlistTitle; - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); component.sendPlaylistsUrl(playlistUrl); expect(electronService.sendIpcEvent).toHaveBeenCalledWith( 'parse-playlist-by-url', @@ -129,7 +128,7 @@ describe('HomeComponent', () => { }); it('should send an event to the main process to parse a playlist', () => { - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); const title = 'my-list.m3u'; const path = '/home/user/iptv/' + title; const playlistContent = 'test'; @@ -160,9 +159,9 @@ describe('HomeComponent', () => { }); it('should set IPC event listeners', () => { - spyOn(electronService.ipcRenderer, 'on'); + spyOn(electronService, 'listenOn'); component.setRendererListeners(); - expect(electronService.ipcRenderer.on).toHaveBeenCalledTimes( + expect(electronService.listenOn).toHaveBeenCalledTimes( component.commandsList.length ); }); diff --git a/src/app/home/recent-playlists/playlist-info/playlist-info.component.spec.ts b/src/app/home/recent-playlists/playlist-info/playlist-info.component.spec.ts index 4f430d5ea..92f51582b 100644 --- a/src/app/home/recent-playlists/playlist-info/playlist-info.component.spec.ts +++ b/src/app/home/recent-playlists/playlist-info/playlist-info.component.spec.ts @@ -55,7 +55,7 @@ describe('PlaylistInfoComponent', () => { it('should send an event to the main process after save', () => { const playlistToSave = { _id: 'a12345', title: 'Playlist' } as Playlist; - spyOn(electronService.ipcRenderer, 'send'); + spyOn(electronService, 'sendIpcEvent'); component.saveChanges(playlistToSave); expect(electronService.sendIpcEvent).toHaveBeenCalledTimes(1); expect(electronService.sendIpcEvent).toHaveBeenCalledWith( diff --git a/src/app/services/electron.service.stub.ts b/src/app/services/electron.service.stub.ts index ebe6db40d..7a7aba8a4 100644 --- a/src/app/services/electron.service.stub.ts +++ b/src/app/services/electron.service.stub.ts @@ -14,11 +14,13 @@ export class ElectronServiceStub { }, }; + removeAllListeners(type: string) {} + getAppVersion() { return this.remote.app.getVersion(); } - sendIpcEvent() { - this.sendIpcEvent(); - } + sendIpcEvent() {} + + listenOn() {} }