feat(67): default new channels to the logo-bug watermark preset

This commit is contained in:
2026-07-20 21:05:38 +02:00
parent 0cad333653
commit c1bd8c067a
2 changed files with 65 additions and 1 deletions
+53
View File
@@ -52,6 +52,8 @@ interface MockOptions {
ffmpegSettings?: Record<string, unknown>;
// path -> ProblemDetails body returned with a 422 for a bulk mutation.
mutationFailures?: Record<string, { detail?: string; status?: number; title?: string }>;
watermarks?: unknown[] | null;
watermarksFail?: boolean;
}
interface MockHandle {
@@ -65,6 +67,7 @@ function mockApi(options: MockOptions = {}): MockHandle {
const channelStates = options.channelStates ?? [];
const ffmpegSettings = options.ffmpegSettings ?? ffmpegSettingsFixture();
const mutationFailures = options.mutationFailures ?? {};
const watermarks = options.watermarks ?? [];
const fetchSpy = vi.spyOn(window, 'fetch').mockImplementation((input: RequestInfo | URL, init?: RequestInit) => {
const url = input.toString();
@@ -81,6 +84,12 @@ function mockApi(options: MockOptions = {}): MockHandle {
if (url === '/api/v1/channels' && method === 'GET') return Promise.resolve(jsonResponse(channels));
if (url === '/api/v1/channels/state' && method === 'GET') return Promise.resolve(jsonResponse(channelStates));
if (url === '/api/v1/settings/ffmpeg' && method === 'GET') return Promise.resolve(jsonResponse(ffmpegSettings));
if (url === '/api/v1/watermarks' && method === 'GET') {
if (options.watermarksFail) {
return Promise.resolve(new Response(null, { status: 500 }));
}
return Promise.resolve(jsonResponse(watermarks));
}
if (
url === '/api/v1/channels/bulk/renumber' ||
@@ -564,4 +573,48 @@ describe('ChannelsScreen — bare create', () => {
expect(window.location.pathname).toBe('/app/channels');
expect(screen.getByRole('button', { name: 'New blank channel' })).toBeInTheDocument();
});
// #67: one uploaded channel logo drives both the guide listing and the on-screen bug. A newly
// created channel should default to that shared preset rather than starting with no watermark.
it('defaults a newly created channel to the logo-bug watermark preset', async () => {
const handle = mockApi({
channels: [channelRow()],
createChannelResponse: { id: 42 },
watermarks: [{ id: 9, imageSource: 'ChannelLogo', name: 'Channel Bug' }]
});
render(<ChannelsScreen />);
expect(await screen.findByText('Retro Cartoons')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'New blank channel' }));
await waitFor(() =>
expect(handle.fetchSpy).toHaveBeenCalledWith('/api/v1/channels', expect.objectContaining({ method: 'POST' }))
);
const body = requestBodyFor(handle, '/api/v1/channels');
expect(body).toMatchObject({ watermarkId: 9 });
});
// A watermark-list failure must degrade to no default, never block channel creation.
it('still creates the channel when the watermark lookup fails', async () => {
const handle = mockApi({
channels: [channelRow()],
createChannelResponse: { id: 42 },
watermarksFail: true
});
render(<ChannelsScreen />);
expect(await screen.findByText('Retro Cartoons')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'New blank channel' }));
await waitFor(() =>
expect(handle.fetchSpy).toHaveBeenCalledWith('/api/v1/channels', expect.objectContaining({ method: 'POST' }))
);
const body = requestBodyFor(handle, '/api/v1/channels');
expect(body).toMatchObject({ watermarkId: null });
await waitFor(() => expect(window.location.pathname).toBe('/app/edit-channel/42'));
});
});
+12 -1
View File
@@ -17,7 +17,9 @@ import {
bulkRenumberChannels,
createChannel,
deleteChannel,
findLogoBugWatermark,
getFfmpegSettings,
getWatermarks,
messageFromError,
useChannelsScreenQuery,
type ChannelState,
@@ -347,6 +349,15 @@ export function ChannelsScreen() {
return Number.isFinite(parsed) ? Math.max(max, parsed) : max;
}, 0);
// New channels default to the seeded logo-driven preset so one uploaded logo drives both the
// guide listing and the on-screen bug (#67). A lookup failure must not block channel creation.
let watermarkId: null | number = null;
try {
watermarkId = findLogoBugWatermark(await getWatermarks())?.id ?? null;
} catch {
watermarkId = null;
}
const body: CreateChannelRequest = {
categories: null,
fallbackFillerId: null,
@@ -374,7 +385,7 @@ export function ChannelsScreen() {
streamSelectorMode: 'Default',
subtitleMode: 'None',
transcodeMode: 'OnDemand',
watermarkId: null
watermarkId
};
const created = await createChannel(body);