|
| 1 | +/* |
| 2 | + * listing-pagination.test.ts |
| 3 | + * |
| 4 | + * Copyright (C) 2026 Posit Software, PBC |
| 5 | + */ |
| 6 | + |
| 7 | +import { assertEquals } from "testing/asserts"; |
| 8 | +import { yamlValidationUnitTest } from "./utils.ts"; |
| 9 | +import { getFrontMatterSchema } from "../../../src/core/lib/yaml-schema/front-matter.ts"; |
| 10 | +import { readAndValidateYamlFromMappedString } from "../../../src/core/lib/yaml-schema/validated-yaml.ts"; |
| 11 | +import { asMappedString } from "../../../src/core/lib/mapped-text.ts"; |
| 12 | + |
| 13 | +const cases: [string, string, boolean][] = [ |
| 14 | + ["outer-window-left", "outer-window-left: 2", true], |
| 15 | + [ |
| 16 | + "all options", |
| 17 | + "inner-window: 1\n outer-window: 2\n outer-window-left: 0\n outer-window-right: 3", |
| 18 | + true, |
| 19 | + ], |
| 20 | + ["unknown property", "outer-window-top: 1", false], |
| 21 | + ["string value", "outer-window: wide", false], |
| 22 | + ["string value for inner-window", "inner-window: '2'", false], |
| 23 | +]; |
| 24 | + |
| 25 | +for (const [name, options, valid] of cases) { |
| 26 | + yamlValidationUnitTest(`listing pagination ${name}`, async () => { |
| 27 | + const yaml = |
| 28 | + `title: Page\nlisting:\n contents: posts\n pagination:\n ${options}\n`; |
| 29 | + const schema = await getFrontMatterSchema(); |
| 30 | + const { yamlValidationErrors } = await readAndValidateYamlFromMappedString( |
| 31 | + asMappedString(yaml), |
| 32 | + schema, |
| 33 | + ); |
| 34 | + assertEquals(yamlValidationErrors.length === 0, valid, yaml); |
| 35 | + }); |
| 36 | +} |
0 commit comments