import { test, expect } from "@playwright/test"; import { buildIndex, pathExists, readJson, resetData, writeSite, } from "./helpers"; import type { ChannelConfig } from "yt-dlp-transcript-common/lib/channelConfig"; // The build-inclusion toggle on /channels flips `excludeFromBuild` in the // channel's config.json. The next build then skips the channel entirely and // the existing top-level cleanup loops in buildIndex remove its per-channel // output dirs. Toggling back re-includes it on the next build. const CONFIG_PATH = "test-transcripts/channels/test-youtube/config.json"; const MANIFEST_PATH = "test-transcripts/.export-index/sites/testsite/summaries/manifest.json"; const CHANNEL_OUT_DIR = "test-transcripts/.export-index/shared/transcripts/test-youtube"; test("toggling a channel off skips it from the build; toggling back restores it", async ({ page, }) => { await resetData("one-youtube-channel-with-data"); await writeSite("testsite", { channels: [{ slug: "test-youtube", groupId: "default" }], }); await buildIndex(page); { const manifest = await readJson<{ totalCount: number; channels: { name: string }[]; }>(MANIFEST_PATH); expect(manifest.totalCount).toBe(1); expect(manifest.channels.map((c) => c.name)).toContain( "Test YouTube Channel", ); expect(await pathExists(`${CHANNEL_OUT_DIR}/manifest.json`)).toBe(true); } await page.goto("/channels"); const toggle = page.getByRole("button", { name: "toggle build inclusion for test-youtube", }); await expect(toggle).toHaveText(/Included/); await expect(toggle).toHaveAttribute("aria-pressed", "true"); await toggle.click(); await expect( page.getByRole("button", { name: "toggle build inclusion for test-youtube" }), ).toHaveText(/Skipped/); await expect( page.getByRole("button", { name: "toggle build inclusion for test-youtube" }), ).toHaveAttribute("aria-pressed", "false"); { const cfg = await readJson(CONFIG_PATH); expect(cfg.excludeFromBuild).toBe(true); } await buildIndex(page); { const manifest = await readJson<{ totalCount: number; channels: { name: string }[]; }>(MANIFEST_PATH); expect(manifest.totalCount).toBe(0); expect(manifest.channels.map((c) => c.name)).not.toContain( "Test YouTube Channel", ); expect(await pathExists(CHANNEL_OUT_DIR)).toBe(false); } await page.goto("/channels"); const reToggle = page.getByRole("button", { name: "toggle build inclusion for test-youtube", }); await expect(reToggle).toHaveText(/Skipped/); await reToggle.click(); await expect( page.getByRole("button", { name: "toggle build inclusion for test-youtube" }), ).toHaveText(/Included/); { const cfg = await readJson(CONFIG_PATH); expect(cfg.excludeFromBuild).toBeUndefined(); } await buildIndex(page); { const manifest = await readJson<{ totalCount: number; channels: { name: string }[]; }>(MANIFEST_PATH); expect(manifest.totalCount).toBe(1); expect(manifest.channels.map((c) => c.name)).toContain( "Test YouTube Channel", ); expect(await pathExists(`${CHANNEL_OUT_DIR}/manifest.json`)).toBe(true); } });