Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/schema-validation/schema-schema.test.ts
6456 views
1
/*
2
* schema-schema.test.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*
6
*/
7
8
import { assert } from "testing/asserts";
9
import { schemaPath } from "../../../src/core/schema/utils.ts";
10
import { getSchemaSchemas } from "../../../src/core/lib/yaml-schema/from-yaml.ts";
11
import { yamlValidationUnitTest } from "./utils.ts";
12
import {
13
arraySchema,
14
idSchema,
15
refSchema,
16
} from "../../../src/core/lib/yaml-schema/common.ts";
17
import { readAndValidateYamlFromFile } from "../../../src/core/schema/validated-yaml.ts";
18
import { expandGlobSync } from "../../../src/core/deno/expand-glob.ts";
19
import { readAndValidateYamlFromMappedString } from "../../../src/core/lib/yaml-schema/validated-yaml.ts";
20
import { asMappedString } from "../../../src/core/lib/mapped-text.ts";
21
22
yamlValidationUnitTest("schema-schema-enum", async () => {
23
const _d = getSchemaSchemas(); // this registers the schema schema
24
const schemaSchema = refSchema("schema/object", "");
25
26
const yamlStrs = [
27
`
28
object:
29
closed: true
30
super:
31
resolveRef: schema/base
32
properties:
33
enum:
34
anyOf:
35
- arrayOf:
36
ref: schema/scalar
37
- object:
38
super:
39
resolveRef: schema/base
40
properties:
41
values:
42
arrayOf:
43
ref: schema/scalar
44
`,
45
`
46
object:
47
properties:
48
properties:
49
object:
50
additionalProperties:
51
ref: schema/schema
52
additionalProperties:
53
ref: schema/schema`,
54
`
55
object:
56
properties:
57
apiUrl:
58
string:
59
description: The base URL of the service API.
60
authority:
61
string:
62
description: The domain name which the annotation service is associated with.
63
grantToken:
64
string:
65
description: An OAuth 2 grant token which the client can send to the service in order to get an access token for making authenticated requests to the service.
66
allowLeavingGroups:
67
boolean:
68
default: true
69
description: A flag indicating whether users should be able to leave groups of which they are a member.
70
enableShareLinks:
71
boolean:
72
default: true
73
description: A flag indicating whether annotation cards should show links that take the user to see an annotation in context.
74
groups:
75
anyOf:
76
- enum: ["$rpc:requestGroups"]
77
- arrayOf: string
78
description: An array of Group IDs or the literal string \`$rpc:requestGroups\`
79
icon:
80
string:
81
description: The URL to an image for the annotation service. This image will appear to the left of the name of the currently selected group.
82
required: [apiUrl, authority, grantToken]`,
83
`
84
object:
85
properties:
86
accentColor:
87
string:
88
description: Secondary color for elements of the commenting UI.
89
appBackgroundColor:
90
string:
91
description: The main background color of the commenting UI.
92
ctaBackgroundColor:
93
string:
94
description: The background color for call to action buttons.
95
selectionFontFamily:
96
string:
97
description: The font family for selection text in the annotation card.
98
annotationFontFamily:
99
string:
100
description: The font family for the actual annotation value that the user writes about the page or selection.
101
description: Settings to adjust the commenting sidebar's look and feel.
102
`,
103
];
104
105
for (const yamlStr of yamlStrs) {
106
const result = await readAndValidateYamlFromMappedString(
107
asMappedString(yamlStr),
108
schemaSchema,
109
);
110
assert(result.yamlValidationErrors.length === 0);
111
}
112
});
113
114
yamlValidationUnitTest("schema-schema", async () => {
115
const _d = getSchemaSchemas(); // this registers the schema schema
116
const yamlSchemaArray = idSchema(
117
arraySchema(refSchema("schema/schema", "")),
118
"schema-array",
119
);
120
121
await readAndValidateYamlFromFile(
122
schemaPath("schema.yml"),
123
yamlSchemaArray,
124
"schema schema validation",
125
);
126
127
await readAndValidateYamlFromFile(
128
schemaPath("definitions.yml"),
129
yamlSchemaArray,
130
"schema definitions",
131
);
132
});
133
134
yamlValidationUnitTest("quarto-schemas", async () => {
135
const _d = getSchemaSchemas(); // this registers the schema schema
136
const schema = idSchema(
137
arraySchema(refSchema("schema/schema-field", "")),
138
"schema-field-array",
139
);
140
for (
141
const walk of expandGlobSync(schemaPath("{project,{cell,document}-*}.yml"))
142
) {
143
await readAndValidateYamlFromFile(
144
walk.path,
145
schema,
146
walk.path,
147
);
148
}
149
});
150
151