Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/website/website-sidebar-section-index.test.ts
12921 views
1
/*
2
* website-sidebar-section-index.test.ts
3
*
4
* Tests that sidebar section headers correctly link to index files with
5
* non-qmd extensions (like .ipynb) in subdirectories. This exercises the
6
* indexFileHrefForDir() -> engineValidExtensions() code path in
7
* website-sidebar-auto.ts.
8
*
9
* The test uses a section with glob pattern (contents: subdir/*) which
10
* triggers indexFileHrefForDir() to scan for index files. The subdir
11
* contains both index.ipynb and other.qmd - the section header should
12
* link to index.ipynb while other.qmd appears as a child item.
13
*
14
* Note: A second file (other.qmd) is required because sidebaritem.ejs
15
* only renders section hrefs when contents is non-empty. This may be
16
* a bug - sections with href but empty contents render as plain text
17
* instead of links. See sidebaritem.ejs lines 19 and 35-36.
18
*
19
* Copyright (C) 2020-2025 Posit Software, PBC
20
*/
21
22
import { docs } from "../../utils.ts";
23
import { join } from "../../../src/deno_ral/path.ts";
24
import { existsSync } from "../../../src/deno_ral/fs.ts";
25
import { testQuartoCmd } from "../../test.ts";
26
import { ensureHtmlElements, fileExists, noErrorsOrWarnings } from "../../verify.ts";
27
28
const renderDir = docs("websites/website-sidebar-section-index");
29
const outDir = join(Deno.cwd(), renderDir, "_site");
30
31
// Test that sidebar section headers link to index.ipynb in subdirectory
32
// (not just that the file renders - we verify the sidebar href)
33
testQuartoCmd(
34
"render",
35
[renderDir],
36
[
37
noErrorsOrWarnings,
38
fileExists(join(outDir, "index.html")), // Main index page
39
fileExists(join(outDir, "subdir", "index.html")), // Subdir index from .ipynb should be rendered
40
fileExists(join(outDir, "subdir", "other.html")), // Other page should also render
41
// Verify the sidebar section header links to subdir/index.html
42
// This tests that indexFileHrefForDir() found the index.ipynb file
43
ensureHtmlElements(
44
join(outDir, "index.html"),
45
['a.sidebar-link[href="./subdir/index.html"]'], // Sidebar should link to subdir index
46
),
47
],
48
{
49
teardown: async () => {
50
if (existsSync(outDir)) {
51
await Deno.remove(outDir, { recursive: true });
52
}
53
},
54
},
55
);
56
57