mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 20:36:21 -05:00
Video page: show the Channel from the video response (#1060)
* Video page: show the Channel from the video response The video page fetched the whole Channel just to show its name, and that endpoint computes the Channel's statistics, which took seconds on a large Channel from a cold disk cache. The video response already carries the Channel's id and name. The URL's channel id is still fetched when the Video has no Channel, and an unfetched Channel no longer renders an empty link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Video page: drop the unreachable URL channel fallback VideoPage is only routed at videos/:fileGroupId, so the URL never carries a channel id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
570c63ffc7
commit
d8eba53c24
2 changed files with 65 additions and 5 deletions
60
app/src/components/VideoPlayerChannel.test.js
Normal file
60
app/src/components/VideoPlayerChannel.test.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import React from 'react';
|
||||
import {render, screen, waitFor} from '../test-utils';
|
||||
import VideoPage from './VideoPlayer';
|
||||
import {getChannel} from '../api';
|
||||
|
||||
// The video response carries the Video's Channel (id and name); fetching the whole Channel only to
|
||||
// show its name costs a statistics query that takes seconds on a large, cold Channel.
|
||||
|
||||
jest.mock('../api', () => {
|
||||
const actual = jest.requireActual('../api');
|
||||
return {
|
||||
...actual,
|
||||
getChannel: jest.fn(),
|
||||
getVideoComments: jest.fn().mockResolvedValue([]),
|
||||
getVideoDescription: jest.fn().mockResolvedValue(''),
|
||||
getVideoCaptions: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
});
|
||||
|
||||
const videoFile = (channel) => ({
|
||||
id: 3,
|
||||
name: 'video.mp4',
|
||||
title: 'A Video',
|
||||
primary_path: 'channel/video.mp4',
|
||||
files: [{path: 'channel/video.mp4', mimetype: 'video/mp4'}],
|
||||
tags: [],
|
||||
video: {
|
||||
id: 3,
|
||||
channel,
|
||||
channel_id: channel ? channel.id : null,
|
||||
video_path: 'channel/video.mp4',
|
||||
caption_files: [],
|
||||
codec_names: [],
|
||||
codec_types: [],
|
||||
},
|
||||
});
|
||||
|
||||
describe('VideoPage channel', () => {
|
||||
beforeEach(() => getChannel.mockReset());
|
||||
|
||||
test("shows the Video's Channel without fetching the Channel", async () => {
|
||||
render(<VideoPage videoFile={videoFile({id: 5, name: 'Some Channel'})} fetchVideo={() => null}/>);
|
||||
|
||||
const link = await screen.findByRole('link', {name: 'Some Channel'});
|
||||
expect(link).toHaveAttribute('href', '/videos/channel/5/video');
|
||||
// Let any effects that would fetch settle.
|
||||
await waitFor(() => expect(screen.getByText('A Video')).toBeInTheDocument());
|
||||
expect(getChannel).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('a Video without a Channel shows no Channel link', async () => {
|
||||
render(<VideoPage videoFile={videoFile(null)} fetchVideo={() => null}/>);
|
||||
|
||||
await waitFor(() => expect(screen.getByText('A Video')).toBeInTheDocument());
|
||||
const channelLinks = screen.queryAllByRole('link')
|
||||
.filter(i => (i.getAttribute('href') || '').startsWith('/videos/channel/'));
|
||||
expect(channelLinks).toHaveLength(0);
|
||||
expect(getChannel).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue