t3xbu10dr: Publish video posts through the media pipeline and upgrade thumbnails to the player
This commit is contained in:
+33
-1
@@ -3,7 +3,7 @@ import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { FeedView, type FeedViewProps } from "@/components/FeedView";
|
||||
import { fetchFeedPage, FeedLoadError } from "@/lib/feed-client";
|
||||
import { mergePosts, relativeTime, toCardPosts } from "@/lib/feed-model";
|
||||
import { mergePosts, relativeTime, toCardPosts, upgradeVideos } from "@/lib/feed-model";
|
||||
|
||||
const NOW = Date.parse("2026-10-19T12:00:00Z");
|
||||
const post = (id: string, publishedAt: string, extra: Record<string, unknown> = {}) => ({
|
||||
@@ -137,3 +137,35 @@ describe("fetchFeedPage", () => {
|
||||
await expect(fetchFeedPage(null, mk(500))).rejects.toMatchObject({ signedOut: false });
|
||||
});
|
||||
});
|
||||
|
||||
describe("video transcoding", () => {
|
||||
const vid = (hls: unknown) =>
|
||||
toCardPosts([post("7", "2026-10-19T10:00:00Z", { mediaItems: [{ mediaType: "video", thumbnailUrl: "https://i/t.jpg", hlsUrl: hls }] })]);
|
||||
|
||||
it("keeps a just-published video as a thumbnail with no hlsUrl", () => {
|
||||
const [p] = vid(null);
|
||||
expect(p.media).toEqual([{ kind: "video", src: "https://i/t.jpg", hlsUrl: null }]);
|
||||
});
|
||||
|
||||
it("keeps a video with neither thumbnail nor hlsUrl as a pending card", () => {
|
||||
const [p] = toCardPosts([post("8", "2026-10-19T10:00:00Z", { mediaItems: [{ mediaType: "video" }] })]);
|
||||
expect(p.media).toHaveLength(1);
|
||||
expect(p.media[0].src).toBeNull();
|
||||
});
|
||||
|
||||
it("upgrades the shown thumbnail to the player when hlsUrl appears", () => {
|
||||
const shown = vid(null);
|
||||
const next = upgradeVideos(shown, vid("https://stream.mux.com/abc"));
|
||||
expect(next[0].media[0].hlsUrl).toContain("stream.mux.com");
|
||||
expect(upgradeVideos(next, vid("https://stream.mux.com/abc"))).toBe(next);
|
||||
expect(upgradeVideos(shown, vid(null))).toBe(shown);
|
||||
});
|
||||
|
||||
it("renders the thumbnail while transcoding and the player once hlsUrl is present", () => {
|
||||
const html = render({ posts: vid(null) });
|
||||
expect(html).toContain("https://i/t.jpg");
|
||||
expect(html).not.toContain("<video");
|
||||
const live = render({ posts: vid("https://stream.mux.com/abc") });
|
||||
expect(live).toContain("<video");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user