mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-16 06:06:18 -08:00
* build(test): make spec tsconfigs resolve what Jest resolves Lib spec tsconfigs used module: commonjs with node10 resolution, which cannot see Angular's exports-only secondary entry points, and dropped global.d.ts, so tsc reported thousands of resolution errors and no window.electron typing. Switch them to module: preserve with bundler resolution (ts-jest still forces CommonJS emit outside ESM mode), add global.d.ts to every spec program, type jest.unstable_mockModule for the ESM workspace, include the ui-epg and ui-playback specs that jest.web-esm.workspace.ts runs under the web spec config, and drop the snack-bar stub that shadowed the real Material types. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * ci(test): gate spec type-checking with typecheck:spec Add tools/typecheck/spec-typecheck.mjs, which runs tsc --noEmit over every tsconfig.spec.json with a small pool and fails on any diagnostic, wire it into the unit-and-typecheck job after typecheck:ci, and document the gate and the spec tsconfig conventions in the validation map. Also bring the non-Tier-A spec configs (remote-control-web, ui-remote-control, stalker-mock-server) to the same conventions so the gate covers the whole workspace. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * test: fix the spec type errors surfaced by typecheck:spec With the spec programs resolving modules and ambient typings correctly, tsc reported 432 genuine errors across the Tier A projects: read-only capability flags assigned on Partial<> doubles, signal-store values used as types, fixtures missing required fields, index-signature property access, partial bridge doubles cast through incompatible shapes, and deferred resolvers narrowed to never. Type the doubles instead of casting to any: writable mapped types for capability flags, InstanceType<typeof StalkerStore>, typed jest.fn signatures, protectedState: false on test signal stores, and completed fixtures. Production changes are limited to bracket access for index-signature properties under the libs' noPropertyAccessFromIndexSignature setting and two narrowing guards in the global favorites loader. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * test(playback): use the ESM setup's jest global in the controls fixtures The fixture imported jest from @jest/globals, which is not a direct dependency. Jest provides that module at runtime, so tests passed, but on a clean pnpm install tsc cannot resolve it and typecheck:spec failed in CI. The ESM test setup already installs import.meta.jest as the global, typed by @types/jest, as the other ESM specs use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: type the parental lock doubles merged since the gate was written The parental lock feature (#1601) and the Stalker actor route landed on master with spec doubles declared as zero-argument jest.fn()s that the tests then drive with the real arguments, plus a copy of the ResizableDirective override imported from a library that does not export it. Give the doubles the lock service's real signatures, drop the dead override as in the sibling layout specs, use bracket access for the actor route's personId param, and keep the Stalker layout spec within the 1200-line limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: 4gray <fourgray@proton.me> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
242 lines
8.9 KiB
TypeScript
242 lines
8.9 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import { RuntimeCapabilitiesService } from '@iptvnator/services';
|
|
import { EpgRuntimeBridgeService } from './epg-runtime-bridge.service';
|
|
|
|
/** Spec-only double: capability flags are read-only getters on the real class. */
|
|
type WritablePartial<T> = { -readonly [K in keyof T]?: T[K] };
|
|
|
|
describe('EpgRuntimeBridgeService', () => {
|
|
let service: EpgRuntimeBridgeService;
|
|
let runtimeCapabilities: WritablePartial<RuntimeCapabilitiesService>;
|
|
const originalElectron = window.electron;
|
|
|
|
beforeEach(() => {
|
|
runtimeCapabilities = {
|
|
supportsEpgImport: false,
|
|
supportsEpgFilePicker: false,
|
|
supportsEpgProgress: false,
|
|
supportsEpgProgramLookup: false,
|
|
supportsEpgCurrentProgramBatch: false,
|
|
supportsEpgChannelMetadata: false,
|
|
supportsEpgSourceFreshness: false,
|
|
supportsEpgDataManagement: false,
|
|
supportsEpgGuide: false,
|
|
supportsEpgProgramSearch: false,
|
|
};
|
|
|
|
TestBed.configureTestingModule({
|
|
providers: [
|
|
EpgRuntimeBridgeService,
|
|
{
|
|
provide: RuntimeCapabilitiesService,
|
|
useValue: runtimeCapabilities,
|
|
},
|
|
],
|
|
});
|
|
|
|
service = TestBed.inject(EpgRuntimeBridgeService);
|
|
});
|
|
|
|
afterEach(() => {
|
|
window.electron = originalElectron;
|
|
TestBed.resetTestingModule();
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
it('opens the native XMLTV picker only when the capability is available', async () => {
|
|
const openEpgFileDialog = jest
|
|
.fn()
|
|
.mockResolvedValue('/home/user/epg/guide.xml.gz');
|
|
window.electron = {
|
|
...window.electron,
|
|
openEpgFileDialog,
|
|
} as unknown as typeof window.electron;
|
|
|
|
await expect(service.pickEpgFile()).resolves.toBeNull();
|
|
expect(openEpgFileDialog).not.toHaveBeenCalled();
|
|
|
|
runtimeCapabilities.supportsEpgFilePicker = true;
|
|
await expect(service.pickEpgFile()).resolves.toBe(
|
|
'/home/user/epg/guide.xml.gz'
|
|
);
|
|
});
|
|
|
|
it('does not call Electron EPG methods when the matching capability is unavailable', async () => {
|
|
const fetchEpg = jest.fn().mockResolvedValue({ success: true });
|
|
const checkEpgFreshness = jest.fn().mockResolvedValue({
|
|
freshUrls: [],
|
|
staleUrls: [],
|
|
});
|
|
window.electron = {
|
|
...window.electron,
|
|
fetchEpg,
|
|
checkEpgFreshness,
|
|
} as unknown as typeof window.electron;
|
|
|
|
await expect(
|
|
service.fetchEpg(['https://example.com/epg.xml'])
|
|
).resolves.toBeNull();
|
|
await expect(
|
|
service.checkFreshness(['https://example.com/epg.xml'], 12)
|
|
).resolves.toBeNull();
|
|
|
|
expect(fetchEpg).not.toHaveBeenCalled();
|
|
expect(checkEpgFreshness).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('delegates import and data-management calls through the typed Electron bridge', async () => {
|
|
const fetchEpg = jest.fn().mockResolvedValue({ success: true });
|
|
const forceFetchEpg = jest.fn().mockResolvedValue({ success: true });
|
|
const clearEpgData = jest.fn().mockResolvedValue({ success: true });
|
|
const clearEpgDataForSource = jest
|
|
.fn()
|
|
.mockResolvedValue({ success: true });
|
|
window.electron = {
|
|
...window.electron,
|
|
fetchEpg,
|
|
forceFetchEpg,
|
|
clearEpgData,
|
|
clearEpgDataForSource,
|
|
} as unknown as typeof window.electron;
|
|
runtimeCapabilities.supportsEpgImport = true;
|
|
runtimeCapabilities.supportsEpgDataManagement = true;
|
|
|
|
await expect(
|
|
service.fetchEpg(['https://example.com/epg.xml'])
|
|
).resolves.toEqual({ success: true });
|
|
await expect(
|
|
service.forceFetchEpg('https://example.com/epg.xml')
|
|
).resolves.toEqual({ success: true });
|
|
await expect(service.clearEpgData()).resolves.toEqual({
|
|
success: true,
|
|
});
|
|
await expect(
|
|
service.clearEpgDataForSource(
|
|
' https://playlist.example.com/guide.xml '
|
|
)
|
|
).resolves.toEqual({
|
|
success: true,
|
|
});
|
|
|
|
expect(fetchEpg).toHaveBeenCalledWith(
|
|
['https://example.com/epg.xml'],
|
|
undefined
|
|
);
|
|
expect(forceFetchEpg).toHaveBeenCalledWith(
|
|
'https://example.com/epg.xml',
|
|
undefined
|
|
);
|
|
expect(clearEpgData).toHaveBeenCalledTimes(1);
|
|
expect(clearEpgDataForSource).toHaveBeenCalledWith(
|
|
'https://playlist.example.com/guide.xml'
|
|
);
|
|
});
|
|
|
|
it('delegates read-side EPG calls through the typed Electron bridge', async () => {
|
|
const getChannelPrograms = jest.fn().mockResolvedValue([]);
|
|
const getCurrentProgramsBatch = jest.fn().mockResolvedValue({
|
|
'channel-1': null,
|
|
});
|
|
const getEpgChannelMetadata = jest.fn().mockResolvedValue({
|
|
'channel-1': null,
|
|
});
|
|
const checkEpgFreshness = jest.fn().mockResolvedValue({
|
|
freshUrls: ['https://example.com/epg.xml'],
|
|
staleUrls: [],
|
|
});
|
|
const searchEpgPrograms = jest.fn().mockResolvedValue([]);
|
|
window.electron = {
|
|
...window.electron,
|
|
getChannelPrograms,
|
|
getCurrentProgramsBatch,
|
|
getEpgChannelMetadata,
|
|
checkEpgFreshness,
|
|
searchEpgPrograms,
|
|
} as unknown as typeof window.electron;
|
|
runtimeCapabilities.supportsEpgProgramLookup = true;
|
|
runtimeCapabilities.supportsEpgCurrentProgramBatch = true;
|
|
runtimeCapabilities.supportsEpgChannelMetadata = true;
|
|
runtimeCapabilities.supportsEpgSourceFreshness = true;
|
|
runtimeCapabilities.supportsEpgProgramSearch = true;
|
|
|
|
await service.getChannelPrograms('channel-1');
|
|
await service.getCurrentProgramsBatch(['channel-1'], {
|
|
sourceUrls: ['https://playlist.example.com/guide.xml'],
|
|
});
|
|
await service.getChannelMetadata(['channel-1'], {
|
|
sourceUrls: ['https://playlist.example.com/guide.xml'],
|
|
});
|
|
await service.checkFreshness(['https://example.com/epg.xml'], 12);
|
|
await service.searchPrograms('news', 20);
|
|
|
|
expect(getChannelPrograms).toHaveBeenCalledWith('channel-1');
|
|
expect(getCurrentProgramsBatch).toHaveBeenCalledWith(['channel-1'], {
|
|
sourceUrls: ['https://playlist.example.com/guide.xml'],
|
|
});
|
|
expect(getEpgChannelMetadata).toHaveBeenCalledWith(['channel-1'], {
|
|
sourceUrls: ['https://playlist.example.com/guide.xml'],
|
|
});
|
|
expect(checkEpgFreshness).toHaveBeenCalledWith(
|
|
['https://example.com/epg.xml'],
|
|
12
|
|
);
|
|
expect(searchEpgPrograms).toHaveBeenCalledWith('news', 20);
|
|
});
|
|
|
|
it('forwards guide reads when the runtime supports them', async () => {
|
|
const getEpgProgramsForChannels = jest
|
|
.fn()
|
|
.mockResolvedValue({ a: [] });
|
|
const getEpgProgramCoverage = jest.fn().mockResolvedValue(['a']);
|
|
window.electron = {
|
|
...window.electron,
|
|
getEpgProgramsForChannels,
|
|
getEpgProgramCoverage,
|
|
} as unknown as typeof window.electron;
|
|
runtimeCapabilities.supportsEpgGuide = true;
|
|
|
|
const guideWindow = { channelIds: ['a'], fromMs: 1, toMs: 2 };
|
|
await expect(
|
|
service.getProgramsForChannels(guideWindow)
|
|
).resolves.toEqual({ a: [] });
|
|
await expect(service.getProgramCoverage(guideWindow)).resolves.toEqual([
|
|
'a',
|
|
]);
|
|
expect(getEpgProgramsForChannels).toHaveBeenCalledWith(guideWindow);
|
|
expect(getEpgProgramCoverage).toHaveBeenCalledWith(guideWindow);
|
|
});
|
|
|
|
it('answers null for guide reads without runtime support or channels', async () => {
|
|
runtimeCapabilities.supportsEpgGuide = false;
|
|
await expect(
|
|
service.getProgramsForChannels({
|
|
channelIds: ['a'],
|
|
fromMs: 1,
|
|
toMs: 2,
|
|
})
|
|
).resolves.toBeNull();
|
|
runtimeCapabilities.supportsEpgGuide = true;
|
|
await expect(
|
|
service.getProgramCoverage({ channelIds: [], fromMs: 1, toMs: 2 })
|
|
).resolves.toBeNull();
|
|
});
|
|
|
|
it('subscribes to EPG progress only when progress events are supported', () => {
|
|
const onEpgProgress = jest.fn();
|
|
window.electron = {
|
|
...window.electron,
|
|
onEpgProgress,
|
|
} as unknown as typeof window.electron;
|
|
|
|
service.onProgress(jest.fn());
|
|
|
|
expect(onEpgProgress).not.toHaveBeenCalled();
|
|
|
|
runtimeCapabilities.supportsEpgProgress = true;
|
|
const callback = jest.fn();
|
|
service.onProgress(callback);
|
|
|
|
expect(onEpgProgress).toHaveBeenCalledWith(callback);
|
|
});
|
|
});
|