From 38ee95a37bd9218d82bd3f65fba896119c68f11c Mon Sep 17 00:00:00 2001 From: Paddy <89168564+patrickballard@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:59:47 +0000 Subject: [PATCH 1/2] fix(web): show hours in the Summary tab's chapter timestamps The Summary tab formatted chapter start times with its own minutes-only helper, so a chapter 1 h 5 m 5 s in read 65:05. Use formatPlayerTime, added for the embed player in #2655, which rolls over into hours. Output under an hour is unchanged. --- .../__tests__/unit/summary-chapters.test.ts | 98 +++++++++++++++++++ .../s/[videoId]/_components/tabs/Summary.tsx | 11 +-- 2 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 apps/web/__tests__/unit/summary-chapters.test.ts diff --git a/apps/web/__tests__/unit/summary-chapters.test.ts b/apps/web/__tests__/unit/summary-chapters.test.ts new file mode 100644 index 00000000000..26f7e4f05d5 --- /dev/null +++ b/apps/web/__tests__/unit/summary-chapters.test.ts @@ -0,0 +1,98 @@ +// @vitest-environment jsdom + +import React, { act } from "react"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +vi.mock("@cap/ui", () => ({ + Button: ({ children, ...props }: React.ComponentProps<"button">) => + React.createElement("button", { type: "button", ...props }, children), +})); +vi.mock("@fortawesome/react-fontawesome", () => ({ + FontAwesomeIcon: () => null, +})); +vi.mock("@fortawesome/free-solid-svg-icons", () => ({ + faRectangleList: {}, + faRotateRight: {}, +})); +vi.mock("lucide-react", () => ({ Edit3: () => null })); +vi.mock("react-markdown", () => ({ + default: ({ children }: { children?: string }) => + React.createElement("div", null, children), +})); +vi.mock("@/app/s/[videoId]/_components/tabs/SummaryEditor", () => ({ + SummaryEditor: () => null, +})); + +import { Summary } from "@/app/s/[videoId]/_components/tabs/Summary"; + +let container: HTMLDivElement; +let root: Root; + +beforeEach(() => { + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); + container = document.createElement("div"); + document.body.appendChild(container); + root = createRoot(container); +}); + +afterEach(() => { + act(() => root.unmount()); + container.remove(); + vi.unstubAllGlobals(); +}); + +const renderChapters = (chapters: { title: string; start: number }[]) => { + act(() => { + root.render( + React.createElement(Summary, { + videoId: "vid" as never, + ownerIsPro: true, + initialAiData: { + summary: "A summary", + chapters, + aiGenerationStatus: "COMPLETE", + }, + }), + ); + }); + return Array.from(container.querySelectorAll("button")) + .map((button) => button.textContent ?? "") + .filter((text) => /\d:\d\d/.test(text)); +}; + +describe("Summary chapter timestamps", () => { + it("rolls over into hours for chapters past the hour mark", () => { + const rendered = renderChapters([ + { title: "Intro", start: 0 }, + { title: "Middle", start: 95 }, + { title: "Just under", start: 3599 }, + { title: "On the hour", start: 3600 }, + { title: "Past the hour", start: 3905 }, + { title: "Two hours in", start: 7384 }, + ]); + + expect(rendered).toEqual([ + "00:00Intro", + "01:35Middle", + "59:59Just under", + "1:00:00On the hour", + "1:05:05Past the hour", + "2:03:04Two hours in", + ]); + }); + + it("never renders a minute count above 59", () => { + const rendered = renderChapters([ + { title: "a", start: 3600 }, + { title: "b", start: 5400 }, + { title: "c", start: 36000 }, + ]); + + for (const text of rendered) { + const minutes = Number(text.split(":")[0]); + expect(minutes).toBeLessThanOrEqual(59); + } + expect(rendered).toEqual(["1:00:00a", "1:30:00b", "10:00:00c"]); + }); +}); diff --git a/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx b/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx index a5cd915f47b..d276a9481ec 100644 --- a/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx +++ b/apps/web/app/s/[videoId]/_components/tabs/Summary.tsx @@ -10,6 +10,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Edit3 } from "lucide-react"; import { useRef, useState } from "react"; import ReactMarkdown from "react-markdown"; +import { formatPlayerTime } from "@/lib/player-time"; import { type SummaryEditingState, SummaryEditor } from "./SummaryEditor"; type AiGenerationStatus = @@ -42,14 +43,6 @@ interface SummaryProps { onEditingStateChange?: (state: SummaryEditingState) => void; } -const formatTime = (time: number) => { - const minutes = Math.floor(time / 60); - const seconds = Math.floor(time % 60); - return `${minutes.toString().padStart(2, "0")}:${seconds - .toString() - .padStart(2, "0")}`; -}; - const SkeletonLoader = () => (
@@ -318,7 +311,7 @@ export const Summary: React.FC = ({ onClick={() => handleSeek(chapter.start)} > - {formatTime(chapter.start)} + {formatPlayerTime(chapter.start)} {chapter.title} From 45796a08de3cb52d291af7604871c0dbd63a8b5f Mon Sep 17 00:00:00 2001 From: Paddy <89168564+patrickballard@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:36:41 +0000 Subject: [PATCH 2/2] fix(web): show hours in the share page's chapter list too SummaryChapters, the chapter list under the video, used the same minutes-only formatTimeMinutes, so a chapter 1 h 5 m 5 s in still read 65:05 there. Use formatPlayerTime like the Summary tab, and remove formatTimeMinutes, which nothing else used. --- .../__tests__/unit/summary-chapters.test.ts | 45 ++++++++++++++----- .../[videoId]/_components/SummaryChapters.tsx | 4 +- .../_components/utils/transcript-utils.ts | 8 ---- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/apps/web/__tests__/unit/summary-chapters.test.ts b/apps/web/__tests__/unit/summary-chapters.test.ts index 26f7e4f05d5..2450941b20c 100644 --- a/apps/web/__tests__/unit/summary-chapters.test.ts +++ b/apps/web/__tests__/unit/summary-chapters.test.ts @@ -24,8 +24,11 @@ vi.mock("@/app/s/[videoId]/_components/tabs/SummaryEditor", () => ({ SummaryEditor: () => null, })); +import SummaryChapters from "@/app/s/[videoId]/_components/SummaryChapters"; import { Summary } from "@/app/s/[videoId]/_components/tabs/Summary"; +type Chapter = { title: string; start: number }; + let container: HTMLDivElement; let root: Root; @@ -42,9 +45,10 @@ afterEach(() => { vi.unstubAllGlobals(); }); -const renderChapters = (chapters: { title: string; start: number }[]) => { - act(() => { - root.render( +const chapterViews: [string, (chapters: Chapter[]) => React.ReactElement][] = [ + [ + "Summary tab", + (chapters) => React.createElement(Summary, { videoId: "vid" as never, ownerIsPro: true, @@ -54,14 +58,35 @@ const renderChapters = (chapters: { title: string; start: number }[]) => { aiGenerationStatus: "COMPLETE", }, }), - ); - }); - return Array.from(container.querySelectorAll("button")) - .map((button) => button.textContent ?? "") - .filter((text) => /\d:\d\d/.test(text)); -}; + ], + [ + "SummaryChapters", + (chapters) => + React.createElement(SummaryChapters, { + isSummaryDisabled: false, + areChaptersDisabled: false, + handleSeek: () => {}, + aiData: { + title: null, + summary: "A summary", + chapters, + aiGenerationStatus: "COMPLETE", + }, + aiLoading: false, + }), + ], +]; + +describe.each(chapterViews)("%s chapter timestamps", (_name, view) => { + const renderChapters = (chapters: Chapter[]) => { + act(() => { + root.render(view(chapters)); + }); + return Array.from(container.querySelectorAll("button")) + .map((button) => button.textContent ?? "") + .filter((text) => /\d:\d\d/.test(text)); + }; -describe("Summary chapter timestamps", () => { it("rolls over into hours for chapters past the hour mark", () => { const rendered = renderChapters([ { title: "Intro", start: 0 }, diff --git a/apps/web/app/s/[videoId]/_components/SummaryChapters.tsx b/apps/web/app/s/[videoId]/_components/SummaryChapters.tsx index c1b8f9d68b0..90bba426f48 100644 --- a/apps/web/app/s/[videoId]/_components/SummaryChapters.tsx +++ b/apps/web/app/s/[videoId]/_components/SummaryChapters.tsx @@ -1,5 +1,5 @@ import ReactMarkdown from "react-markdown"; -import { formatTimeMinutes } from "./utils/transcript-utils"; +import { formatPlayerTime } from "@/lib/player-time"; type AiGenerationStatus = | "QUEUED" @@ -64,7 +64,7 @@ const SummaryChapters = ({ onClick={() => handleSeek(chapter.start)} > - {formatTimeMinutes(chapter.start)} + {formatPlayerTime(chapter.start)} {chapter.title} diff --git a/apps/web/app/s/[videoId]/_components/utils/transcript-utils.ts b/apps/web/app/s/[videoId]/_components/utils/transcript-utils.ts index 97a16a64bff..8855f6ec72c 100644 --- a/apps/web/app/s/[videoId]/_components/utils/transcript-utils.ts +++ b/apps/web/app/s/[videoId]/_components/utils/transcript-utils.ts @@ -20,14 +20,6 @@ export const formatTime = (seconds: number): string => { .padStart(3, "0")}`; }; -export const formatTimeMinutes = (time: number) => { - const minutes = Math.floor(time / 60); - const seconds = Math.floor(time % 60); - return `${minutes.toString().padStart(2, "0")}:${seconds - .toString() - .padStart(2, "0")}`; -}; - /** * Formats transcript entries as VTT format for subtitles */