fix(67): cover the bug-preview geometry path, preserve a custom logo preset across toggling
- Add ChannelEditScreen tests exercising the geometry-fetch/preview path (previously untested because the fixture's blank logo path kept BugPreview from ever rendering): asserts the fetched watermark geometry lands on the preview image with asymmetric values, and that an external logo URL suppresses the preview. - Fix a toggle-off/toggle-on data loss: re-enabling "use logo as on-screen bug" used to always rebind to the default 'Channel Bug' preset, discarding a channel's own per-geometry ChannelLogo preset. Remember the last referenced logo-driven watermark id in a ref and prefer it, falling back to the shared default. - Strip the geometry cache's `id` key before it reaches BugPreview's props (was leaking via a spread). - Drop the "(see #502)" issue reference from the visible help text; keep it in the code comment. - Constrain findLogoBugWatermark's imageSource param to the generated ChannelWatermarkImageSource union instead of `string`, and add unit tests for its preference/fallback/none-found behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
createWatermark,
|
||||
deleteWatermark,
|
||||
findLogoBugWatermark,
|
||||
getWatermark,
|
||||
updateWatermark,
|
||||
watermarkImageUrl,
|
||||
@@ -84,3 +85,33 @@ describe('watermarks api client', () => {
|
||||
expect(watermarkImageUrl('abc.png')).toBe('/artwork/watermarks/abc.png');
|
||||
});
|
||||
});
|
||||
|
||||
describe('findLogoBugWatermark', () => {
|
||||
it('prefers the row named "Channel Bug" over an earlier ChannelLogo row', () => {
|
||||
const watermarks = [
|
||||
{ id: 4, imageSource: 'ChannelLogo' as const, name: 'Alpha Bug' },
|
||||
{ id: 9, imageSource: 'ChannelLogo' as const, name: 'Channel Bug' }
|
||||
];
|
||||
|
||||
expect(findLogoBugWatermark(watermarks)).toMatchObject({ id: 9 });
|
||||
});
|
||||
|
||||
it('falls back to the first ChannelLogo row when no "Channel Bug" exists', () => {
|
||||
const watermarks = [
|
||||
{ id: 2, imageSource: 'Custom' as const, name: 'Corner bug' },
|
||||
{ id: 4, imageSource: 'ChannelLogo' as const, name: 'Alpha Bug' },
|
||||
{ id: 6, imageSource: 'ChannelLogo' as const, name: 'Beta Bug' }
|
||||
];
|
||||
|
||||
expect(findLogoBugWatermark(watermarks)).toMatchObject({ id: 4 });
|
||||
});
|
||||
|
||||
it('returns null when none are ChannelLogo', () => {
|
||||
const watermarks = [
|
||||
{ id: 2, imageSource: 'Custom' as const, name: 'Corner bug' },
|
||||
{ id: 3, imageSource: 'Resource' as const, name: 'Station ident' }
|
||||
];
|
||||
|
||||
expect(findLogoBugWatermark(watermarks)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,9 +16,9 @@ export function getWatermark(id: number): Promise<WatermarkDetail> {
|
||||
// Identifies THE default logo-driven preset. imageSource alone is not enough once a second
|
||||
// ChannelLogo preset exists (the design invites creating one for per-channel geometry), and
|
||||
// getWatermarks() sorts by name — so prefer the seeded name, then fall back deterministically.
|
||||
export function findLogoBugWatermark<T extends { id: number; imageSource: string; name: null | string }>(
|
||||
watermarks: T[]
|
||||
): T | null {
|
||||
export function findLogoBugWatermark<
|
||||
T extends { id: number; imageSource: components['schemas']['ChannelWatermarkImageSource']; name: null | string }
|
||||
>(watermarks: T[]): T | null {
|
||||
const logoDriven = watermarks.filter((watermark) => watermark.imageSource === 'ChannelLogo');
|
||||
return logoDriven.find((watermark) => watermark.name === 'Channel Bug') ?? logoDriven[0] ?? null;
|
||||
}
|
||||
|
||||
@@ -471,5 +471,109 @@ describe('ChannelEditScreen', () => {
|
||||
await waitFor(() => expect(puts).toHaveLength(1));
|
||||
expect((puts[0] as { watermarkId: null | number }).watermarkId).toBe(2);
|
||||
});
|
||||
|
||||
// Regression: toggling off (watermarkId -> null) then back on used to always rebind to
|
||||
// logoBugTarget (the 'Channel Bug' default), silently losing a channel's own per-geometry
|
||||
// ChannelLogo preset.
|
||||
it('restores the channel’s own ChannelLogo preset — not the default — when re-toggled on', async () => {
|
||||
const puts: unknown[] = [];
|
||||
mockApi({
|
||||
channelOverrides: { watermarkId: 4 },
|
||||
onPut: (body) => puts.push(body),
|
||||
watermarks: [
|
||||
{ id: 4, imageSource: 'ChannelLogo', name: 'Alpha Bug' },
|
||||
{ id: 9, imageSource: 'ChannelLogo', name: 'Channel Bug' }
|
||||
]
|
||||
});
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
const toggle = await screen.findByRole('switch', { name: 'Use logo as on-screen bug' });
|
||||
expect(toggle).toHaveAttribute('aria-checked', 'true');
|
||||
|
||||
fireEvent.click(toggle);
|
||||
expect(toggle).toHaveAttribute('aria-checked', 'false');
|
||||
|
||||
fireEvent.click(toggle);
|
||||
expect(toggle).toHaveAttribute('aria-checked', 'true');
|
||||
|
||||
// watermarkId round-trips back to its original value across the off/on toggle, so the form
|
||||
// isn't dirty from that alone — touch something unrelated to enable Save.
|
||||
fireEvent.click(screen.getByRole('button', { name: /^General/ }));
|
||||
fireEvent.change(screen.getByDisplayValue('Cartoons'), { target: { value: 'Renamed channel' } });
|
||||
|
||||
const saveButton = await screen.findByRole('button', { name: 'Save changes' });
|
||||
fireEvent.click(saveButton);
|
||||
|
||||
await waitFor(() => expect(puts).toHaveLength(1));
|
||||
expect((puts[0] as { watermarkId: null | number }).watermarkId).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('on-screen bug preview', () => {
|
||||
it('renders the preview image using the fetched watermark geometry', async () => {
|
||||
mockApi({
|
||||
channelOverrides: {
|
||||
logo: { path: 'iptv/logos/cartoons.png', contentType: 'image/png' },
|
||||
watermarkId: 9
|
||||
},
|
||||
watermarks: [
|
||||
{ id: 2, imageSource: 'Custom', name: 'Corner bug' },
|
||||
{
|
||||
id: 9,
|
||||
imageSource: 'ChannelLogo',
|
||||
name: 'Channel Bug',
|
||||
horizontalMargin: 3,
|
||||
location: 'BottomLeft',
|
||||
opacity: 60,
|
||||
size: 'Scaled',
|
||||
verticalMargin: 7,
|
||||
width: 11
|
||||
}
|
||||
]
|
||||
});
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
const preview = await screen.findByAltText('On-screen bug preview');
|
||||
// Asymmetric values so a horizontal/vertical (or margin/width) prop swap fails this test.
|
||||
expect(preview).toHaveAttribute('src', 'iptv/logos/cartoons.png');
|
||||
expect(preview).toHaveStyle({
|
||||
bottom: '7%',
|
||||
left: '3%',
|
||||
opacity: '0.6',
|
||||
width: '11%'
|
||||
});
|
||||
expect(preview.style.right).toBe('');
|
||||
expect(preview.style.top).toBe('');
|
||||
});
|
||||
|
||||
it('does not render the preview when an external logo URL is set', async () => {
|
||||
mockApi({
|
||||
channelOverrides: {
|
||||
logo: { path: 'iptv/logos/cartoons.png', contentType: 'image/png' },
|
||||
watermarkId: 9
|
||||
},
|
||||
watermarks: [{ id: 9, imageSource: 'ChannelLogo', name: 'Channel Bug' }]
|
||||
});
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
// Preview renders from the uploaded logo first.
|
||||
await screen.findByAltText('On-screen bug preview');
|
||||
|
||||
const urlInput = screen.getByPlaceholderText('https://example.com/logo.png');
|
||||
fireEvent.change(urlInput, { target: { value: 'https://example.com/new-logo.png' } });
|
||||
|
||||
// An external URL can never resolve to a real bug (see the comment on the WatermarkSelector
|
||||
// File.Exists behavior), so the preview must disappear once one is set.
|
||||
await waitFor(() => expect(screen.queryByAltText('On-screen bug preview')).toBeNull());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -729,6 +729,18 @@ function BrandingPane({
|
||||
|
||||
const bugGeometry = fetchedGeometry && fetchedGeometry.id === draft.watermarkId ? fetchedGeometry : null;
|
||||
|
||||
// Remembers the last logo-driven watermark this channel actually referenced — which may be a
|
||||
// per-channel-geometry ChannelLogo preset other than logoBugTarget (the shared default). Without
|
||||
// this, toggling off (watermarkId -> null) then back on would always rebind to logoBugTarget,
|
||||
// silently losing a custom preset's geometry. Only updated while the toggle reads as ON, so a
|
||||
// toggle-off never clobbers the memory of what to restore.
|
||||
const lastLogoWatermarkIdRef = useRef<number | null>(null);
|
||||
useEffect(() => {
|
||||
if (logoBugEnabled && draft.watermarkId != null) {
|
||||
lastLogoWatermarkIdRef.current = draft.watermarkId;
|
||||
}
|
||||
}, [logoBugEnabled, draft.watermarkId]);
|
||||
|
||||
return (
|
||||
<Pane subtitle="Channel logo and the overlays applied while streaming." title="Branding">
|
||||
<Card padded={false}>
|
||||
@@ -786,7 +798,7 @@ function BrandingPane({
|
||||
logoBugTarget == null
|
||||
? 'No logo-driven watermark preset exists yet.'
|
||||
: externalUrlLogo
|
||||
? 'An external logo URL cannot be used as the on-screen bug — upload an image instead (see #502).'
|
||||
? 'An external logo URL cannot be used as the on-screen bug — upload an image instead.'
|
||||
: 'Overlays this channel’s own logo on the stream, using the shared preset’s position and size.'
|
||||
}
|
||||
label="Use logo as on-screen bug"
|
||||
@@ -797,11 +809,24 @@ function BrandingPane({
|
||||
disabled={hlsDirect || logoBugTarget == null}
|
||||
hideLabel
|
||||
label="Use logo as on-screen bug"
|
||||
onChange={(next) => set({ watermarkId: next ? (logoBugTarget?.id ?? null) : null })}
|
||||
onChange={(next) =>
|
||||
set({ watermarkId: next ? (lastLogoWatermarkIdRef.current ?? logoBugTarget?.id ?? null) : null })
|
||||
}
|
||||
size="sm"
|
||||
/>
|
||||
{logoBugEnabled && bugGeometry && previewSrc && !externalUrlLogo && (
|
||||
<BugPreview {...bugGeometry} src={previewSrc} />
|
||||
// bugGeometry is cached keyed by `id` (see fetchedGeometry above); pass the
|
||||
// geometry fields explicitly rather than spreading so the cache key never leaks
|
||||
// into BugPreview's props.
|
||||
<BugPreview
|
||||
horizontalMargin={bugGeometry.horizontalMargin}
|
||||
location={bugGeometry.location}
|
||||
opacity={bugGeometry.opacity}
|
||||
size={bugGeometry.size}
|
||||
src={previewSrc}
|
||||
verticalMargin={bugGeometry.verticalMargin}
|
||||
width={bugGeometry.width}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</Row>
|
||||
|
||||
Reference in New Issue
Block a user