Files
STCourses/packages/feature-import/test/packt.test.ts
T
2026-10-30 03:15:09 +01:00

29 lines
1.2 KiB
TypeScript

import { expect, test } from "bun:test";
import { parsePacktIndex } from "../src/packt";
import { packtIndexHtml } from "./fixtures";
test("sections, clip titles and video files come from the structure", () => {
const p = parsePacktIndex(packtIndexHtml());
expect(p.title).toBe("Fake Docker Course");
expect(p.sections.map((s) => s.title)).toEqual(["Intro to Docker", "Images (Sample)"]);
expect(p.sections[0]!.clips).toEqual([
{ number: 1, title: "Course Introduction", video: "videos/video1_1.mp4" },
{ number: 2, title: "Docker & Friends", video: "videos/video1_2.mp4" },
]);
expect(p.sections[1]!.clips[0]!.video).toBe("videos/video2_1.mp4");
expect(p.warnings).toEqual([]);
});
test("a section without a chapter block falls back to the overview list", () => {
const p = parsePacktIndex(packtIndexHtml({ dropChapter: 1 }));
expect(p.sections[0]!.clips.map((c) => [c.title, c.video])).toEqual([
["Course Introduction", "videos/video1_1.mp4"],
["Docker & Friends", "videos/video1_2.mp4"],
]);
expect(p.warnings.join()).toContain("section 1 has no chapter block");
});
test("not a Packt page is a clear error", () => {
expect(() => parsePacktIndex("<html><h1>Hello</h1></html>")).toThrow(/no "Section N/);
});