mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-24 09:33:44 +03:00
d175a4d6ae
closes #192
90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
'use strict';
|
|
import { SchemaHelper } from './schema-helper.service';
|
|
import { SpecManager } from '../utils/spec-manager';
|
|
|
|
describe('Spec Helper', () => {
|
|
describe('injectors', () => {
|
|
it('should autodetect type if not-specified', () => {
|
|
spyOn(console, 'warn').and.stub();
|
|
let schema = {
|
|
type: undefined,
|
|
properties: {}
|
|
};
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
schema.type.should.be.equal('object');
|
|
expect(console.warn).toHaveBeenCalled();
|
|
(<jasmine.Spy>console.warn).and.callThrough();
|
|
});
|
|
|
|
describe('string', () => {
|
|
it('should calculate range for string with maxLength', () => {
|
|
let schema:any = {
|
|
type: 'string',
|
|
maxLength: 3
|
|
};
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
schema._range.should.be.equal('<= 3 characters');
|
|
});
|
|
|
|
it('should calculate range for string with minLength', () => {
|
|
let schema:any = {
|
|
type: 'string',
|
|
minLength: 3,
|
|
};
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
schema._range.should.be.equal('>= 3 characters');
|
|
});
|
|
|
|
it('should calculate range for string with both max and minLength', () => {
|
|
let schema:any = {
|
|
type: 'string',
|
|
minLength: 3,
|
|
maxLength: 5
|
|
};
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
schema._range.should.be.equal('[ 3 .. 5 ] characters');
|
|
});
|
|
|
|
it('should calculate range for string with equal max and minLength', () => {
|
|
let schema:any = {
|
|
type: 'string',
|
|
minLength: 5,
|
|
maxLength: 5
|
|
};
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
schema._range.should.be.equal('5 characters');
|
|
});
|
|
|
|
it('should show range as non-empty for minLength == 1', () => {
|
|
let schema:any = {
|
|
type: 'string',
|
|
minLength: 1
|
|
};
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
schema._range.should.be.equal('non-empty');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('preprocessProperties', () => {
|
|
it('should not throw when type array and items are not defined', () => {
|
|
let schema = {
|
|
type: 'object',
|
|
properties: {
|
|
prop1: {
|
|
type: 'array'
|
|
}
|
|
}
|
|
};
|
|
|
|
(() => SchemaHelper.preprocessProperties(schema, '#/', {})).should.not.throw();
|
|
});
|
|
});
|
|
});
|