|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { getUrl } from "../src/utils"; |
| 3 | + |
| 4 | +// Regression test for #13583. With code-copy enabled (the default), each code |
| 5 | +// block is wrapped in div.code-copy-outer-scaffold, which used to break the |
| 6 | +// direct-child selectors the code-tools "Show All Code" / "Hide All Code" |
| 7 | +// handler relied on. The toggle must still open/close every folded <details> |
| 8 | +// and swap the hidden<->unhidden class on the echo:false cell's source. |
| 9 | +test("code-tools Show/Hide All Code toggles folded and hidden code with code-copy", async ({ |
| 10 | + page, |
| 11 | +}) => { |
| 12 | + await page.goto(getUrl("html/code-tools-toggle.html"), { |
| 13 | + waitUntil: "load", |
| 14 | + }); |
| 15 | + |
| 16 | + const details = page.locator(".cell details.code-fold"); |
| 17 | + const hiddenCode = page.locator("div.sourceCode.cell-code.hidden"); |
| 18 | + const unhiddenCode = page.locator("div.sourceCode.cell-code.unhidden"); |
| 19 | + |
| 20 | + // Baseline: two folded cells, both collapsed; the echo:false cell's source |
| 21 | + // is emitted hidden (keep-hidden). |
| 22 | + await expect(details).toHaveCount(2); |
| 23 | + await expect(details.nth(0)).toHaveJSProperty("open", false); |
| 24 | + await expect(details.nth(1)).toHaveJSProperty("open", false); |
| 25 | + await expect(hiddenCode).toHaveCount(1); |
| 26 | + await expect(unhiddenCode).toHaveCount(0); |
| 27 | + |
| 28 | + // Show All Code: every <details> opens, the hidden source becomes unhidden. |
| 29 | + await page.locator("#quarto-code-tools-menu").click(); |
| 30 | + await page.locator("#quarto-show-all-code").click(); |
| 31 | + |
| 32 | + await expect(details.nth(0)).toHaveJSProperty("open", true); |
| 33 | + await expect(details.nth(1)).toHaveJSProperty("open", true); |
| 34 | + await expect(hiddenCode).toHaveCount(0); |
| 35 | + await expect(unhiddenCode).toHaveCount(1); |
| 36 | + |
| 37 | + // Hide All Code: every <details> closes, the source goes back to hidden. |
| 38 | + await page.locator("#quarto-code-tools-menu").click(); |
| 39 | + await page.locator("#quarto-hide-all-code").click(); |
| 40 | + |
| 41 | + await expect(details.nth(0)).toHaveJSProperty("open", false); |
| 42 | + await expect(details.nth(1)).toHaveJSProperty("open", false); |
| 43 | + await expect(hiddenCode).toHaveCount(1); |
| 44 | + await expect(unhiddenCode).toHaveCount(0); |
| 45 | +}); |
0 commit comments