Path: blob/main/tests/smoke/website/website-sidebar-section-index.test.ts
12925 views
/*1* website-sidebar-section-index.test.ts2*3* Tests that sidebar section headers correctly link to index files with4* non-qmd extensions (like .ipynb) in subdirectories. This exercises the5* indexFileHrefForDir() -> engineValidExtensions() code path in6* website-sidebar-auto.ts.7*8* The test uses a section with glob pattern (contents: subdir/*) which9* triggers indexFileHrefForDir() to scan for index files. The subdir10* contains both index.ipynb and other.qmd - the section header should11* link to index.ipynb while other.qmd appears as a child item.12*13* Note: A second file (other.qmd) is required because sidebaritem.ejs14* only renders section hrefs when contents is non-empty. This may be15* a bug - sections with href but empty contents render as plain text16* instead of links. See sidebaritem.ejs lines 19 and 35-36.17*18* Copyright (C) 2020-2025 Posit Software, PBC19*/2021import { docs } from "../../utils.ts";22import { join } from "../../../src/deno_ral/path.ts";23import { existsSync } from "../../../src/deno_ral/fs.ts";24import { testQuartoCmd } from "../../test.ts";25import { ensureHtmlElements, fileExists, noErrorsOrWarnings } from "../../verify.ts";2627const renderDir = docs("websites/website-sidebar-section-index");28const outDir = join(Deno.cwd(), renderDir, "_site");2930// Test that sidebar section headers link to index.ipynb in subdirectory31// (not just that the file renders - we verify the sidebar href)32testQuartoCmd(33"render",34[renderDir],35[36noErrorsOrWarnings,37fileExists(join(outDir, "index.html")), // Main index page38fileExists(join(outDir, "subdir", "index.html")), // Subdir index from .ipynb should be rendered39fileExists(join(outDir, "subdir", "other.html")), // Other page should also render40// Verify the sidebar section header links to subdir/index.html41// This tests that indexFileHrefForDir() found the index.ipynb file42ensureHtmlElements(43join(outDir, "index.html"),44['a.sidebar-link[href="./subdir/index.html"]'], // Sidebar should link to subdir index45),46],47{48teardown: async () => {49if (existsSync(outDir)) {50await Deno.remove(outDir, { recursive: true });51}52},53},54);555657