mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
test(services): avoid angular testing entrypoint
This commit is contained in:
1 parent
f9e95466e8
commit
5ae8c5bedd
2 files changed
+47
-16
No files matched your search
@@ -1,5 +1,12 @@
|
||||
import { signal, Signal, WritableSignal } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
EnvironmentInjector,
|
||||
Injector,
|
||||
Signal,
|
||||
WritableSignal,
|
||||
createEnvironmentInjector,
|
||||
runInInjectionContext,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
DownloadItem,
|
||||
DownloadsService,
|
||||
@@ -30,7 +37,6 @@ describe('DownloadsService', () => {
|
||||
|
||||
afterEach(() => {
|
||||
testWindow.electron = originalElectron;
|
||||
TestBed.resetTestingModule();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
@@ -79,8 +85,8 @@ describe('DownloadsService', () => {
|
||||
}
|
||||
|
||||
it('reports availability through the runtime capability', () => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
const injector = createEnvironmentInjector(
|
||||
[
|
||||
DownloadsService,
|
||||
{ provide: SettingsStore, useValue: {} },
|
||||
{
|
||||
@@ -88,11 +94,19 @@ describe('DownloadsService', () => {
|
||||
useValue: { supportsDownloads: false },
|
||||
},
|
||||
],
|
||||
});
|
||||
Injector.NULL as unknown as EnvironmentInjector
|
||||
);
|
||||
|
||||
const service = TestBed.inject(DownloadsService);
|
||||
try {
|
||||
const service = runInInjectionContext(
|
||||
injector,
|
||||
() => new DownloadsService()
|
||||
);
|
||||
|
||||
expect(service.isAvailable()).toBe(false);
|
||||
expect(service.isAvailable()).toBe(false);
|
||||
} finally {
|
||||
injector.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
it('tracks loading and loaded state around a successful download list request', async () => {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
EnvironmentInjector,
|
||||
Injector,
|
||||
createEnvironmentInjector,
|
||||
runInInjectionContext,
|
||||
} from '@angular/core';
|
||||
import { of } from 'rxjs';
|
||||
import { PlaylistMeta } from '@iptvnator/shared/interfaces';
|
||||
import { DatabaseService } from './database-electron.service';
|
||||
@@ -23,6 +28,7 @@ describe('PlaylistDeleteActionService', () => {
|
||||
let runtime: {
|
||||
isElectron: boolean;
|
||||
};
|
||||
let injector: EnvironmentInjector;
|
||||
|
||||
beforeEach(() => {
|
||||
databaseService = {
|
||||
@@ -38,18 +44,29 @@ describe('PlaylistDeleteActionService', () => {
|
||||
isElectron: false,
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
PlaylistDeleteActionService,
|
||||
injector = createEnvironmentInjector(
|
||||
[
|
||||
{ provide: DatabaseService, useValue: databaseService },
|
||||
{ provide: PlaylistsService, useValue: playlistsService },
|
||||
{ provide: RuntimeCapabilitiesService, useValue: runtime },
|
||||
],
|
||||
});
|
||||
Injector.NULL as unknown as EnvironmentInjector
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
injector.destroy();
|
||||
});
|
||||
|
||||
function createService(): PlaylistDeleteActionService {
|
||||
return runInInjectionContext(
|
||||
injector,
|
||||
() => new PlaylistDeleteActionService()
|
||||
);
|
||||
}
|
||||
|
||||
it('deletes browser playlists through PlaylistsService', async () => {
|
||||
const service = TestBed.inject(PlaylistDeleteActionService);
|
||||
const service = createService();
|
||||
|
||||
await expect(service.deletePlaylist(playlist)).resolves.toBe(true);
|
||||
|
||||
@@ -62,7 +79,7 @@ describe('PlaylistDeleteActionService', () => {
|
||||
it('deletes Electron Xtream playlists through DatabaseService with progress options', async () => {
|
||||
runtime.isElectron = true;
|
||||
const onEvent = jest.fn();
|
||||
const service = TestBed.inject(PlaylistDeleteActionService);
|
||||
const service = createService();
|
||||
|
||||
await expect(
|
||||
service.deletePlaylist(playlist, { onEvent })
|
||||
@@ -83,7 +100,7 @@ describe('PlaylistDeleteActionService', () => {
|
||||
|
||||
it('deletes Electron non-Xtream playlists without progress options', async () => {
|
||||
runtime.isElectron = true;
|
||||
const service = TestBed.inject(PlaylistDeleteActionService);
|
||||
const service = createService();
|
||||
|
||||
await expect(
|
||||
service.deletePlaylist({
|
||||
|
||||
Reference in new issue
Block a user