UNPKG

13.3 kBJavaScriptView Raw
1/*
2 * Copyright 2019 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12/* eslint-env mocha */
13/* eslint-disable no-unused-expressions */
14const { assertMarkdown, loadschemas } = require('./testUtils');
15
16const build = require('../lib/markdownBuilder');
17
18describe('Testing Markdown Builder: content', () => {
19 let results;
20
21 before(async () => {
22 const schemas = await loadschemas('content');
23 const builder = build({ header: false });
24 results = builder(schemas);
25 });
26
27 it('PNG Schema looks OK', () => {
28 assertMarkdown(results.png)
29 .contains('**encoding**: the string content must be using the base64 content encoding.');
30 });
31
32 it('HTML Schema looks OK', () => {
33 assertMarkdown(results.html)
34 .contains('**media type**: the media type of the contents of this string is: `text/html`');
35 });
36
37 it('JWT Schema looks OK', () => {
38 assertMarkdown(results.jwt)
39 .contains('**schema**: the contents of this string should follow this schema: [JSON Web Token](jwt-json-web-token.md "check type definition")')
40 .contains('**media type**: the media type of the contents of this string is: `application/jwt`');
41 });
42});
43
44describe('Testing Markdown Builder: not', () => {
45 let results;
46
47 before(async () => {
48 const schemas = await loadschemas('not');
49 const builder = build({ header: false });
50 results = builder(schemas);
51 });
52
53 it('Not Schema looks OK', () => {
54 assertMarkdown(results.not)
55 .fuzzy`## Not true Type
56
57merged type ([Not true](not.md))
58
59not
60
61* [True](not-true.md "check type definition")`;
62 });
63});
64
65describe('Testing Markdown Builder: nullable', () => {
66 let results;
67
68 before(async () => {
69 const schemas = await loadschemas('nullable');
70 const builder = build({ header: false });
71 results = builder(schemas);
72 });
73
74 it('Nullable Array Type Schema looks OK', () => {
75 assertMarkdown(results.array)
76 .fuzzy`| [sampleProp](#sampleprop) | \`string\` | Required | can be null | [Type Array Repro](array-properties-sample-property.md "http://example.com/type-array-repro.json#/properties/sampleProp") |`;
77 });
78});
79
80describe('Testing Markdown Builder: title', () => {
81 let results;
82
83 before(async () => {
84 const schemas = await loadschemas('title');
85 const builder = build({ header: false });
86 results = builder(schemas);
87 });
88
89 it('Meta Schema looks OK', () => {
90 assertMarkdown(results.meta)
91 .fuzzy`defined in: [Meta](meta-definitions-meta-properties-title.md "https://ns.adobe.com/helix/pipeline/meta#/definitions/meta/properties/title")`;
92 });
93
94 it('Title Schema looks OK', () => {
95 assertMarkdown(results['meta-definitions-meta-properties-title'])
96 .fuzzy`## title Type\n\n\`string\`\n`;
97 });
98});
99
100describe('Testing Markdown Builder: type', () => {
101 let results;
102
103 before(async () => {
104 const schemas = await loadschemas('type');
105 const builder = build({ header: false });
106 results = builder(schemas);
107 });
108
109 it('Type Schema looks OK', () => {
110 assertMarkdown(results.type)
111 .fuzzy`The type of the Button (not used for anchors).`
112 .print();
113 });
114
115 it('Button Schema looks OK', () => {
116 assertMarkdown(results.button)
117 .fuzzy`## Button Type`
118 .print();
119 });
120});
121
122describe('Testing Markdown Builder: format', () => {
123 let results;
124
125 before(async () => {
126 const schemas = await loadschemas('format');
127 const builder = build({ header: false });
128 results = builder(schemas);
129 });
130
131 it('Format Schema looks OK', () => {
132 assertMarkdown(results.format)
133 .fuzzy`Formatting used to display the date.`;
134 });
135
136 it('Format Schema has JSON examples', () => {
137 assertMarkdown(results.format)
138 .fuzzy`## Properties Examples
139
140\`\`\`json
141{
142 "format": "Coolness",
143 "value": "Maximum"
144}
145\`\`\``;
146 });
147});
148
149describe('Testing Markdown Builder: YAML examples', () => {
150 let results;
151
152 before(async () => {
153 const schemas = await loadschemas('format');
154 const builder = build({ header: false, exampleformat: 'yaml' });
155 results = builder(schemas);
156 });
157
158 it('Format Schema has JSON examples', () => {
159 assertMarkdown(results.format)
160 .fuzzy`## Properties Examples
161
162\`\`\`yaml
163format: Coolness
164value: Maximum
165
166\`\`\``;
167 });
168});
169
170describe('Testing Markdown Builder: enums', () => {
171 let results;
172
173 before(async () => {
174 const schemas = await loadschemas('enums');
175 const builder = build({ header: true, includeproperties: ['foo', 'bar'] });
176 results = builder(schemas);
177 });
178
179 it('Enums Schema looks OK', () => {
180 assertMarkdown(results.enums)
181 .contains('| `"bas"` | from ancient Egyptian religion, an aspect of the soul |')
182 .contains('| `"baa"` | |')
183 .contains('foo: bar')
184 .contains('bar: foo')
185 .contains('**enum**: the value of this property must be equal to one of the following values:');
186 });
187
188 it('Array Enums Schema looks OK', () => {
189 assertMarkdown(results.arrayenums)
190 .contains('| `["P","M"]` | Post Meridiem? |');
191 });
192});
193
194describe('Testing Markdown Builder: null', () => {
195 let results;
196
197 before(async () => {
198 const schemas = await loadschemas('null');
199 const builder = build({ header: true });
200 results = builder(schemas);
201 });
202
203 it('Null Schema looks OK', () => {
204 assertMarkdown(results.null)
205 .contains('the value must be null')
206 .contains('can be null')
207 .contains('the value of this property must be equal to:');
208 });
209});
210
211describe('Testing Markdown Builder: additionalprops', () => {
212 let results;
213
214 before(async () => {
215 const schemas = await loadschemas('additionalprops');
216 const builder = build({ header: true });
217 results = builder(schemas);
218 });
219
220 it('Additional Properties Schema looks OK', () => {
221 assertMarkdown(results.additionalprops)
222 .contains('**maximum number of properties**: the maximum number of properties for this object is: `99`')
223 .contains('**minimum number of properties**: the minimum number of properties for this object is: `10`')
224 .has('heading > text[value="Additional Properties"]');
225 });
226
227 it('Arrays Schema looks OK', () => {
228 assertMarkdown(results.arrays)
229 .contains('**minimum number of contained items**: this array may not contain fewer than 1 items that validate against the schema: [Untitled boolean in undefined](arrays-contains.md "check type definition")')
230 .contains('**maximum number of contained items**: this array may not contain more than 9 items that validate against the schema: [Untitled boolean in undefined](arrays-contains.md "check type definition")')
231 .contains('**unique items**: all items in this array must be unique. Duplicates are not allowed.');
232 });
233});
234
235describe('Testing Markdown Builder: types', () => {
236 let results;
237
238 before(async () => {
239 const schemas = await loadschemas('types');
240 const builder = build({ header: true });
241 results = builder(schemas);
242 });
243
244 it('Object Schema looks OK', () => {
245 assertMarkdown(results.object)
246 .has('paragraph > inlineCode[value="object"]');
247 });
248
249 it('Merged Schema looks OK', () => {
250 assertMarkdown(results.merged)
251 .has('paragraph > text[value^="merged type"]');
252 });
253
254 it('Multiple Typed Schema looks OK', () => {
255 assertMarkdown(results.objectorarray)
256 .has('paragraph > text[value="any of the folllowing: "]');
257 });
258
259 it('Undefined Schema looks OKish', () => {
260 assertMarkdown(results.undefined)
261 .has('paragraph > text[value="unknown"]');
262 });
263
264 it('Wrong Schema looks OKish', () => {
265 assertMarkdown(results.wrong)
266 .has('paragraph > text[value="unknown"]');
267 });
268});
269
270describe('Testing Markdown Builder: identifiable', () => {
271 let results;
272
273 before(async () => {
274 const schemas = await loadschemas('identifiable');
275 const builder = build({ header: true });
276 results = builder(schemas);
277 });
278
279 it('Identifiable Schema looks OK', () => {
280 assertMarkdown(results.identifiable)
281 .has('table > tableRow > tableCell > text[value="Identifiable"]')
282 .has('table > tableRow > tableCell > text[value="Yes"]');
283 });
284});
285
286describe('Testing Markdown Builder: arrays', () => {
287 let results;
288
289 before(async () => {
290 const schemas = await loadschemas('arrays');
291 const builder = build({ header: true });
292 results = builder(schemas);
293 });
294
295 it('Arrays Schema looks OK', () => {
296 assertMarkdown(results.arrays)
297 .contains('and all following items may follow any schema');
298 });
299
300 it('Tuple Schema looks OK', () => {
301 assertMarkdown(results.tuple)
302 .fuzzy`
303* is optional
304
305* Type: an array where each item follows the corresponding schema in the following list:
306
307 1. [Positive Integer](tuple-properties-tuple-items-positive-integer.md "check type definition")
308
309 2. [Negative Integer](tuple-properties-tuple-items-negative-integer.md "check type definition")
310
311 3. and all following items must follow the schema: [Zero](tuple-properties-tuple-zero.md "check type definition")
312
313* cannot be null
314
315* defined in: [Arrays](tuple-properties-tuple.md "https://example.com/schemas/arrays#/properties/tuple")
316
317### tuple Type
318
319an array where each item follows the corresponding schema in the following list:
320
3211. [Positive Integer](tuple-properties-tuple-items-positive-integer.md "check type definition")
322
3232. [Negative Integer](tuple-properties-tuple-items-negative-integer.md "check type definition")
324
3253. and all following items must follow the schema: [Zero](tuple-properties-tuple-zero.md "check type definition")`;
326 });
327});
328
329describe('Testing Markdown Builder: stringformats', () => {
330 let results;
331
332 before(async () => {
333 const schemas = await loadschemas('stringformats');
334 const builder = build({ header: true });
335 results = builder(schemas);
336 });
337
338 it('Simple Types Schema looks OK', () => {
339 assertMarkdown(results.simpletypes)
340 .contains('maximum (exclusive)')
341 .contains('minimum (exclusive)')
342 .fuzzy`### string_pattern Constraints
343
344**pattern**: the string must match the following regular expression: ${null}
345\`\`\`regexp
346^ba.$
347`
348 .fuzzy`### string_date Constraints
349
350**date time**: the string must be a date time string, according to [RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339 "check the specification")
351`;
352 });
353});
354
355describe('Testing Markdown Builder: readme-1', () => {
356 let results;
357
358 before(async () => {
359 const schemas = await loadschemas('readme-1');
360 const builder = build({ header: true, links: { abstract: 'fooabstract.html' } });
361 results = builder(schemas);
362 });
363
364 it('Abstract Schema looks OK', () => {
365 assertMarkdown(results.abstract)
366 .equals('heading > text', { type: 'text', value: 'Abstract Schema' })
367 .contains('cannot be read or written')
368 .contains('nonfoo Access Restrictions')
369 .contains('bar Access Restrictions')
370 .contains('### foo Access Restrictions')
371 .fuzzy`
372## Definitions group second
373
374Reference this group by using
375
376\`\`\`json
377{"$ref":"https://example.com/schemas/abstract#/$defs/second"}
378\`\`\``
379 .fuzzy`
380\`bar\`
381
382* is optional
383
384* Type: \`string\`
385
386* cannot be null
387
388* defined in: [Abstract](abstract-defs-second-properties-bar.md "https://example.com/schemas/abstract#/$defs/second/properties/bar")
389
390#### bar Type
391
392\`string\``
393 .contains('fooabstract.html');
394 // .inspect()
395 // .print();
396 });
397
398 it('Complex Schema looks OK', () => {
399 assertMarkdown(results.complex)
400 .contains('Read only')
401 .contains('# Complex References Schema');
402 });
403
404 it('Simple Schema looks OK', () => {
405 assertMarkdown(results.simple)
406 .contains('Deprecated')
407 .contains('"Simply Untitled"')
408 .contains('Write only')
409 .contains('> This should be here')
410 .contains('living a simple life')
411 .contains('# Simple Schema');
412 });
413});
414
415describe('Testing Markdown Builder: Skip properties', () => {
416 let schemas;
417
418 before(async () => {
419 schemas = await loadschemas('skipproperties');
420 });
421
422 it('Skipped properties exist', () => {
423 const builder = build({});
424 const results = builder(schemas);
425
426 assertMarkdown(results.complete)
427 .contains('### bar Type')
428 .contains('| Property | Type | Required |')
429 .contains('* defined in: [Complete JSON Schema]');
430 });
431
432 it('Skips the expected properties', () => {
433 const builder = build({ skipproperties: ['typesection', 'definedinfact', 'proptable'] });
434 const results = builder(schemas);
435
436 assertMarkdown(results.complete)
437 .doesNotContain('### bar Type')
438 .doesNotContain('| Property | Type | Required |')
439 .doesNotContain('- defined in: [Complete JSON Schema]');
440 });
441});