mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 13:16:16 -08:00
* fix(i18n): translate hard-coded labels, snackbars and missing keys Catalog screens, snackbars and external player messages showed English in every locale, and seven keys used in code were missing from en.json, so ngx-translate rendered them raw. - Catalog: "All items", item and channel counts, channel sort menus and tooltips, unnamed-category and empty-category labels, LIVE/PAUSED badges and the Xtream global search summary are translated. The Xtream and Stalker stores no longer bake an English name into the every-item sentinel; the facades return a null title and the view translates it. - Snackbars: Xtream/Stalker request failures, the 413 upload error, backup export/import results and the category visibility failure use keys; every "Close" action uses CLOSE. - External player: the main process sends an error code instead of an English sentence (player-error event, session errorCode, and a tag in rejected launch errors); the renderer, dock and VOD primary button translate it. The external player info dialog is translated. - Adds the seven missing keys and 43 new ones, translated in all 18 locales; seven legitimately identical values are baselined. - tools/i18n/check-usage.mjs fails on keys used in code but missing from en.json; it runs in i18n:check (and so in CI through i18n:validate). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(i18n): translate catalog counts in the template and skip inline template comments - The category subtitle hands a key to the translate pipe instead of caching translate.instant(), so a cold start re-renders it once the language file loads. - The Xtream live root count uses the singular/plural item keys, so one result no longer reads "1 channels". - check-usage.mjs strips HTML comments inside inline templates of TypeScript files, so a commented-out key no longer fails the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(i18n): check keys in parenthesised translate pipe operands `(expanded() ? 'SHOW_LESS' : 'SHOW_MORE') | translate` yields keys that neither precede the pipe directly nor contain a dot, so the usage check missed them. It now reads the ternary and fallback branches of a parenthesised operand; a literal compared in the condition is not read as a key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(e2e): expect the translated external player failure in the dock A launch failure without an error code now shows the translated generic status in the playback dock, with the raw main-process detail as its tooltip. The ClearKey DASH flow asserted the raw English text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(playback): keep the IPC error tag out of the stored session detail A tagged launch failure reached ExternalPlayerSession.error unchanged, so the dock tooltip showed "[iptvnator:external-player:start-failed]". The registry now strips the tag when it stores the detail; the rejected IPC error keeps it for the renderer to read the code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(web): expect translated portal request failure toasts #1861's new resolved-failure specs asserted the English toast text; the toasts now go through PORTALS.REQUEST_ERRORS keys, so the specs check the key and its message/status params. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(i18n): read only returned branches of a grouped translate operand A literal at the start of a condition, as in `('ERROR' === status() ? 'CLOSE' : 'CLOSE') | translate`, was taken for a translation key, so a valid template could fail the usage check. A grouped literal now counts only when it ends its operand (end of group, `:`, `||` or `??`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(i18n): translate the remaining hard-coded labels Follow-up to the UI-26 pass. The remaining English UI literals now come from translation keys, translated in all 18 locales: - Windows/Linux window controls, playlist switcher title and actions menu, the portal status tooltip, dashboard carousel roles and rail scroll buttons, the search placeholder, the card remove tooltip, the EPG offset unit, the REC chip, the Stalker EPG source label and the export file type. - Embedded MPV failures raised in the renderer and the release-notes dialog without a bridge. Settings never showed its English reasons, so they are dropped. - Unnamed Stalker episodes: data access leaves the title empty and the series view labels it after the TMDB overlay. Synthetic season names stay, because they key persisted episode progress. - The phone remote-control page, which follows the first browser language with a translation and sets <html lang>. Removes the dead getStatusMessage(), the unused favorites layout and the translateWithFallback() helpers whose keys now exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(remote-control): keep the remote build off shared-interfaces The language resolver imported the Language enum, which made remote-control-web depend on shared-interfaces. Its build-performance chain then hit Nx's recursive-invocation guard through the existing shared-interfaces/shared-logging build loop, failing the Electron E2E and performance journey builds. The resolver now keeps its own list of translation codes, and a spec checks it against the locale files the page loads. Also drops the deleted favorites layout from the zoneless checklist, whose guard spec requires ticked entries to exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(journeys): raise the launch DOM mutation baseline for translated attributes Launch now sets 569 DOM mutations before the first dashboard card instead of 557 (identical in all three CI iterations). The extra twelve come from attributes this PR moved from static English to translated bindings on the launch path: the window-control labels and tooltips on Linux, the hero carousel and slide roles, and the rail scroll-button labels. A translated attribute is a binding set after the element is attached, so each costs a mutation. Accepted as a deliberate trade-off; it needs the perf-baseline-increase label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
437 lines
15 KiB
TypeScript
437 lines
15 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import {
|
|
EmbeddedMpvSession,
|
|
ResolvedPortalPlayback,
|
|
} from '@iptvnator/shared/interfaces';
|
|
import { TranslateModule } from '@ngx-translate/core';
|
|
import { EmbeddedMpvSessionController } from './embedded-mpv-session-controller';
|
|
|
|
describe('EmbeddedMpvSessionController', () => {
|
|
let electron: {
|
|
platform: string;
|
|
getEmbeddedMpvSupport: jest.Mock;
|
|
prepareEmbeddedMpv: jest.Mock;
|
|
createEmbeddedMpvSession: jest.Mock;
|
|
loadEmbeddedMpvPlayback: jest.Mock;
|
|
disposeEmbeddedMpvSession: jest.Mock;
|
|
setEmbeddedMpvBounds: jest.Mock;
|
|
onEmbeddedMpvSessionUpdate: jest.Mock;
|
|
setEmbeddedMpvPaused: jest.Mock;
|
|
seekEmbeddedMpv: jest.Mock;
|
|
seekEmbeddedMpvBy: jest.Mock;
|
|
setEmbeddedMpvVolume: jest.Mock;
|
|
};
|
|
let sessionUpdate: ((session: EmbeddedMpvSession) => void) | null;
|
|
let unsubscribeSessionUpdate: jest.Mock;
|
|
let testingModuleDestroyed: boolean;
|
|
|
|
beforeEach(() => {
|
|
// Fake timers before anything else: the controller's startup chain is
|
|
// driven from here (see `waitFor`), and the rAF shim below defers
|
|
// through `setTimeout`, so it has to resolve to the faked one.
|
|
jest.useFakeTimers();
|
|
testingModuleDestroyed = false;
|
|
sessionUpdate = null;
|
|
unsubscribeSessionUpdate = jest.fn();
|
|
electron = {
|
|
platform: 'darwin',
|
|
getEmbeddedMpvSupport: jest.fn().mockResolvedValue({
|
|
supported: true,
|
|
platform: 'darwin',
|
|
}),
|
|
prepareEmbeddedMpv: jest.fn().mockResolvedValue({
|
|
supported: true,
|
|
platform: 'darwin',
|
|
}),
|
|
createEmbeddedMpvSession: jest
|
|
.fn()
|
|
.mockResolvedValue(createSession({ id: 'mpv-1' })),
|
|
loadEmbeddedMpvPlayback: jest.fn().mockResolvedValue(undefined),
|
|
disposeEmbeddedMpvSession: jest.fn().mockResolvedValue(undefined),
|
|
setEmbeddedMpvBounds: jest.fn().mockResolvedValue(undefined),
|
|
onEmbeddedMpvSessionUpdate: jest.fn((callback) => {
|
|
sessionUpdate = callback;
|
|
return unsubscribeSessionUpdate;
|
|
}),
|
|
setEmbeddedMpvPaused: jest.fn().mockResolvedValue(
|
|
createSession({
|
|
id: 'mpv-1',
|
|
status: 'paused',
|
|
})
|
|
),
|
|
seekEmbeddedMpv: jest.fn().mockResolvedValue(
|
|
createSession({
|
|
id: 'mpv-1',
|
|
positionSeconds: 15,
|
|
})
|
|
),
|
|
seekEmbeddedMpvBy: jest.fn().mockResolvedValue(
|
|
createSession({
|
|
id: 'mpv-1',
|
|
positionSeconds: 15,
|
|
})
|
|
),
|
|
setEmbeddedMpvVolume: jest.fn().mockResolvedValue(
|
|
createSession({
|
|
id: 'mpv-1',
|
|
volume: 0.25,
|
|
})
|
|
),
|
|
};
|
|
Object.defineProperty(window, 'electron', {
|
|
configurable: true,
|
|
value: electron,
|
|
});
|
|
Object.defineProperty(globalThis, 'ResizeObserver', {
|
|
configurable: true,
|
|
value: class MockResizeObserver {
|
|
observe = jest.fn();
|
|
disconnect = jest.fn();
|
|
},
|
|
});
|
|
Object.defineProperty(window, 'requestAnimationFrame', {
|
|
configurable: true,
|
|
value: (callback: FrameRequestCallback) => {
|
|
return window.setTimeout(() => callback(0), 0);
|
|
},
|
|
});
|
|
Object.defineProperty(window, 'cancelAnimationFrame', {
|
|
configurable: true,
|
|
value: (handle: number) => window.clearTimeout(handle),
|
|
});
|
|
|
|
TestBed.configureTestingModule({
|
|
imports: [TranslateModule.forRoot()],
|
|
providers: [EmbeddedMpvSessionController],
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (!testingModuleDestroyed) {
|
|
TestBed.resetTestingModule();
|
|
}
|
|
delete (window as unknown as { electron?: unknown }).electron;
|
|
// After teardown has cancelled the controller's timers, so the stalled
|
|
// tracker's 30s timeout never leaks into the real timer queue.
|
|
jest.useRealTimers();
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
function destroyTestingModule(): void {
|
|
TestBed.resetTestingModule();
|
|
testingModuleDestroyed = true;
|
|
}
|
|
|
|
it('loads support and unsubscribes from session updates on destroy', async () => {
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
|
|
await waitFor(() => controller.support() !== null, 'support to load');
|
|
|
|
expect(electron.getEmbeddedMpvSupport).toHaveBeenCalled();
|
|
expect(controller.support()).toEqual({
|
|
supported: true,
|
|
platform: 'darwin',
|
|
});
|
|
|
|
destroyTestingModule();
|
|
expect(unsubscribeSessionUpdate).toHaveBeenCalled();
|
|
});
|
|
|
|
it('starts a session, forwards matching updates, and disposes on teardown', async () => {
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
const host = createHost();
|
|
const playback = createPlayback();
|
|
|
|
const teardown = controller.startSession(host, playback, 0.7);
|
|
expect(controller.session()).toEqual(
|
|
expect.objectContaining({
|
|
id: 'embedded-mpv-starting',
|
|
status: 'loading',
|
|
volume: 0.7,
|
|
})
|
|
);
|
|
|
|
await waitFor(
|
|
() => controller.sessionId() === 'mpv-1',
|
|
'session to start'
|
|
);
|
|
|
|
expect(electron.prepareEmbeddedMpv).toHaveBeenCalled();
|
|
// Fractional CSS edges stay unrounded: the main process rounds once,
|
|
// after converting them to native units.
|
|
expect(electron.createEmbeddedMpvSession).toHaveBeenCalledWith(
|
|
{ x: 10.6, y: 20.5, width: 640, height: 360 },
|
|
'Example Movie',
|
|
0.7
|
|
);
|
|
expect(electron.loadEmbeddedMpvPlayback).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
playback
|
|
);
|
|
expect(controller.sessionId()).toBe('mpv-1');
|
|
|
|
sessionUpdate?.(createSession({ id: 'other', status: 'paused' }));
|
|
expect(controller.session()?.status).toBe('playing');
|
|
|
|
sessionUpdate?.(createSession({ id: 'mpv-1', status: 'paused' }));
|
|
expect(controller.session()?.status).toBe('paused');
|
|
|
|
teardown();
|
|
|
|
expect(controller.session()).toBeNull();
|
|
expect(controller.sessionId()).toBeNull();
|
|
expect(electron.disposeEmbeddedMpvSession).toHaveBeenCalledWith(
|
|
'mpv-1'
|
|
);
|
|
});
|
|
|
|
it('sets an error session when Electron cannot create playback', async () => {
|
|
electron.prepareEmbeddedMpv.mockRejectedValueOnce(
|
|
new Error('native module missing')
|
|
);
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
|
|
controller.startSession(createHost(), createPlayback(), 0.5);
|
|
await waitFor(
|
|
() => controller.session()?.status === 'error',
|
|
'error session to be set'
|
|
);
|
|
|
|
expect(controller.session()).toEqual(
|
|
expect.objectContaining({
|
|
id: 'embedded-mpv-error',
|
|
status: 'error',
|
|
error: 'native module missing',
|
|
})
|
|
);
|
|
expect(controller.sessionId()).toBeNull();
|
|
});
|
|
|
|
it('ignores a late startup rejection after teardown so it cannot clobber a newer session', async () => {
|
|
let rejectPrepare: ((error: Error) => void) | undefined;
|
|
electron.prepareEmbeddedMpv.mockImplementationOnce(
|
|
() =>
|
|
new Promise((_resolve, reject) => {
|
|
rejectPrepare = reject;
|
|
})
|
|
);
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
|
|
const teardown = controller.startSession(
|
|
createHost(),
|
|
createPlayback(),
|
|
0.5
|
|
);
|
|
await waitFor(
|
|
() => rejectPrepare !== undefined,
|
|
'startup to reach prepareEmbeddedMpv'
|
|
);
|
|
teardown();
|
|
|
|
// A newer session replaces the torn-down one (fast channel zapping).
|
|
const newer = createSession({ id: 'mpv-2' });
|
|
controller.sessionId.set('mpv-2');
|
|
controller.session.set(newer);
|
|
|
|
rejectPrepare?.(new Error('native module missing'));
|
|
await flush();
|
|
|
|
expect(controller.session()).toBe(newer);
|
|
expect(controller.sessionId()).toBe('mpv-2');
|
|
});
|
|
|
|
it('delegates track, speed, aspect, and recording commands to the runner', async () => {
|
|
const commandBridge = {
|
|
setEmbeddedMpvAudioTrack: jest.fn().mockResolvedValue(null),
|
|
setEmbeddedMpvSubtitleTrack: jest.fn().mockResolvedValue(null),
|
|
setEmbeddedMpvSpeed: jest.fn().mockResolvedValue(null),
|
|
setEmbeddedMpvAspect: jest.fn().mockResolvedValue(null),
|
|
seekEmbeddedMpv: jest.fn().mockResolvedValue(null),
|
|
startEmbeddedMpvRecording: jest.fn().mockResolvedValue(
|
|
createSession({
|
|
recording: { active: true, targetPath: '/tmp/rec.ts' },
|
|
})
|
|
),
|
|
stopEmbeddedMpvRecording: jest
|
|
.fn()
|
|
.mockResolvedValue(
|
|
createSession({ recording: { active: false } })
|
|
),
|
|
};
|
|
Object.assign(electron, commandBridge);
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
controller.sessionId.set('mpv-1');
|
|
controller.session.set(createSession());
|
|
|
|
await controller.seekTo(75);
|
|
await controller.setAudioTrack(2);
|
|
await controller.setSubtitleTrack(-1);
|
|
await controller.setSpeed(1.5);
|
|
await controller.setAspect('16:9');
|
|
const started = await controller.startRecording('/rec', 'Show');
|
|
const stopped = await controller.stopRecording();
|
|
|
|
expect(commandBridge.seekEmbeddedMpv).toHaveBeenCalledWith('mpv-1', 75);
|
|
expect(commandBridge.setEmbeddedMpvAudioTrack).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
2
|
|
);
|
|
expect(commandBridge.setEmbeddedMpvSubtitleTrack).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
-1
|
|
);
|
|
expect(commandBridge.setEmbeddedMpvSpeed).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
1.5
|
|
);
|
|
expect(commandBridge.setEmbeddedMpvAspect).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
'16:9'
|
|
);
|
|
expect(started).toEqual({ active: true, targetPath: '/tmp/rec.ts' });
|
|
expect(stopped).toEqual({ active: false });
|
|
});
|
|
|
|
it('forwards playback commands and updates session snapshots', async () => {
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
controller.sessionId.set('mpv-1');
|
|
controller.session.set(
|
|
createSession({
|
|
id: 'mpv-1',
|
|
status: 'playing',
|
|
positionSeconds: 3,
|
|
})
|
|
);
|
|
|
|
await controller.togglePaused();
|
|
expect(electron.setEmbeddedMpvPaused).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
true
|
|
);
|
|
expect(controller.session()?.status).toBe('paused');
|
|
|
|
await controller.seekBy(-30);
|
|
// Relative: the delta goes to mpv as-is, never a snapshot-derived
|
|
// absolute target.
|
|
expect(electron.seekEmbeddedMpvBy).toHaveBeenCalledWith('mpv-1', -30);
|
|
expect(electron.seekEmbeddedMpv).not.toHaveBeenCalled();
|
|
expect(controller.session()?.positionSeconds).toBe(15);
|
|
|
|
await controller.applyVolume(0.25);
|
|
expect(electron.setEmbeddedMpvVolume).toHaveBeenCalledWith(
|
|
'mpv-1',
|
|
0.25
|
|
);
|
|
expect(controller.session()?.volume).toBe(0.25);
|
|
});
|
|
|
|
it('swallows command errors so stale IPC races do not clear current state', async () => {
|
|
const controller = TestBed.inject(EmbeddedMpvSessionController);
|
|
const current = createSession({ id: 'mpv-1', volume: 0.8 });
|
|
controller.sessionId.set('mpv-1');
|
|
controller.session.set(current);
|
|
electron.setEmbeddedMpvVolume.mockRejectedValueOnce(
|
|
new Error('session disposed')
|
|
);
|
|
|
|
await controller.applyVolume(0.25);
|
|
|
|
expect(controller.session()).toBe(current);
|
|
});
|
|
});
|
|
|
|
function createHost(): HTMLElement {
|
|
return {
|
|
getBoundingClientRect: () => ({
|
|
left: 10.6,
|
|
top: 20.5,
|
|
width: 640,
|
|
height: 360,
|
|
}),
|
|
} as HTMLElement;
|
|
}
|
|
|
|
function createPlayback(): ResolvedPortalPlayback {
|
|
return {
|
|
streamUrl: 'https://example.com/movie.mp4',
|
|
title: 'Example Movie',
|
|
};
|
|
}
|
|
|
|
function createSession(
|
|
overrides: Partial<EmbeddedMpvSession> = {}
|
|
): EmbeddedMpvSession {
|
|
return {
|
|
id: 'mpv-1',
|
|
title: 'Example Movie',
|
|
streamUrl: 'https://example.com/movie.mp4',
|
|
status: 'playing',
|
|
positionSeconds: 10,
|
|
durationSeconds: 120,
|
|
volume: 0.7,
|
|
audioTracks: [],
|
|
selectedAudioTrackId: null,
|
|
subtitleTracks: [],
|
|
selectedSubtitleTrackId: null,
|
|
playbackSpeed: 1,
|
|
aspectOverride: 'no',
|
|
recording: { active: false },
|
|
startedAt: '2026-06-02T00:00:00.000Z',
|
|
updatedAt: '2026-06-02T00:00:01.000Z',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Advance the fake clock by one drain round: flush pending microtasks (the IPC
|
|
* promises the startup chain awaits), then run every timer now due — which is
|
|
* how the rAF shim's continuations get to run.
|
|
*
|
|
* One millisecond, never zero: a zero-delay timer scheduled from *inside* a
|
|
* timer callback is clamped to the next millisecond, and `waitForStartupPaint`
|
|
* nests exactly that way (rAF inside rAF). Advancing by 0 fires the outer hop
|
|
* and strands the inner one forever.
|
|
*/
|
|
async function drainRound(): Promise<void> {
|
|
await Promise.resolve();
|
|
await jest.advanceTimersByTimeAsync(1);
|
|
}
|
|
|
|
/**
|
|
* Settle the controller's async startup chain, then assert.
|
|
*
|
|
* The bound is a number of drain rounds, not elapsed wall-clock time. Polling
|
|
* real timers against a `Date.now()` deadline made these specs load-sensitive:
|
|
* under parallel Jest workers the budget expired before the chain settled, so
|
|
* a different pair of tests failed on each run. With the clock virtual the
|
|
* spec imposes no deadline of its own — the rounds only ever advance when this
|
|
* loop says so — so settling stops being a race against the machine. Jest's
|
|
* own per-test timeout still applies, as it does to every spec.
|
|
*/
|
|
async function waitFor(
|
|
condition: () => boolean,
|
|
description: string
|
|
): Promise<void> {
|
|
// Generous next to the ~4 rounds the longest chain needs, while still
|
|
// failing fast (and reporting `description`) if it never settles.
|
|
for (let round = 0; round < 100; round += 1) {
|
|
if (condition()) {
|
|
return;
|
|
}
|
|
await drainRound();
|
|
}
|
|
|
|
throw new Error(`Timed out waiting for ${description}`);
|
|
}
|
|
|
|
/**
|
|
* Settle everything pending with no condition to poll for — used by the
|
|
* negative assertions, where the point is that a late continuation runs and
|
|
* still changes nothing.
|
|
*/
|
|
async function flush(): Promise<void> {
|
|
for (let round = 0; round < 5; round += 1) {
|
|
await drainRound();
|
|
}
|
|
}
|