UNPKG

2.29 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 assert = require('assert');
15const s = require('../lib/symbols');
16const { gentitle, gendescription } = require('../lib/formattingTools');
17
18describe('Testing formatting tools: gettitle', () => {
19 it('robust for undefined', () => {
20 assert.strictEqual(gentitle('foo'), 'Untitled schema');
21 });
22 it('robust for non array', () => {
23 assert.strictEqual(gentitle('foo'), 'Untitled schema');
24 });
25 it('robust for undefined array', () => {
26 assert.strictEqual(gentitle([undefined]), 'Untitled schema');
27 });
28 it('robust for larger undefined array', () => {
29 assert.strictEqual(gentitle([undefined, undefined]), 'Untitled schema');
30 });
31 it('returns single first title', () => {
32 assert.strictEqual(gentitle(['Hello world schema']), 'Hello world schema');
33 });
34 it('returns last title', () => {
35 assert.strictEqual(gentitle([1, 2, 3, 'Hello world schema']), 'Hello world schema');
36 });
37 it('returns title with type', () => {
38 assert.strictEqual(gentitle(['Hello world schema', undefined], 'string'),
39 'Untitled string in Hello world schema');
40 });
41 it('returns title with for undefined type', () => {
42 assert.strictEqual(gentitle(['Hello world schema', undefined]),
43 'Untitled undefined type in Hello world schema');
44 });
45});
46
47describe('Testing formatting tools: gendescription', () => {
48 it('robust for undefined', () => {
49 assert.strictEqual(gendescription(), '');
50 });
51
52 it('works with meta', () => {
53 assert.strictEqual(gendescription({
54 [s.meta]: {
55 shortdescription: 'Hello, world',
56 },
57 }), 'Hello, world');
58 });
59});