redoc/tests/unit/pipes.spec.js

109 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-12-14 19:14:35 +03:00
'use strict';
import {KeysPipe, ValuesPipe, JsonPointerEscapePipe, MarkedPipe} from 'lib/utils/pipes';
2015-12-19 20:36:28 +03:00
describe('Pipes', () => {
describe('KeysPipe and ValuesPipe', () => {
let obj;
var keysPipe, valuesPipe;
beforeEach(() => {
obj = {
a: 1,
b: 2,
c: 3
};
keysPipe = new KeysPipe();
valuesPipe = new ValuesPipe();
2015-12-14 19:14:35 +03:00
});
2015-12-19 20:36:28 +03:00
describe('KeysPipe transform', () => {
it('should return keys', () => {
var val = keysPipe.transform(obj);
val.should.be.deepEqual(['a', 'b', 'c']);
});
2015-12-14 19:31:17 +03:00
2015-12-19 20:36:28 +03:00
it('should not support other objects', () => {
(() => keysPipe.transform(45)).should.throw();
(() => keysPipe.transform('45')).should.throw();
});
2015-12-14 19:14:35 +03:00
2015-12-19 20:36:28 +03:00
it('should not throw on blank input', () => {
(() => valuesPipe.transform()).should.not.throw();
});
2015-12-14 19:14:35 +03:00
});
2015-12-19 20:36:28 +03:00
describe('KeysPipe transform', () => {
it('should return values', () => {
var val = valuesPipe.transform(obj);
val.should.be.deepEqual([1, 2, 3]);
});
it('should not support other objects', () => {
(() => valuesPipe.transform(45)).should.throw();
(() => valuesPipe.transform('45')).should.throw();
});
2015-12-14 19:31:17 +03:00
2015-12-19 20:36:28 +03:00
it('should not throw on blank input', () => {
(() => keysPipe.transform()).should.not.throw();
});
2015-12-14 19:14:35 +03:00
});
});
2015-12-19 20:36:28 +03:00
describe('JsonPointerEscapePipe', () => {
let unescaped;
let escaped;
var pipe;
2015-12-14 19:14:35 +03:00
2015-12-19 20:36:28 +03:00
beforeEach(() => {
unescaped = 'test/path~1';
escaped = 'test~1path~01';
pipe = new JsonPointerEscapePipe();
2015-12-14 19:14:35 +03:00
});
2015-12-19 20:36:28 +03:00
describe('JsonPointerEscapePipe transform', () => {
it('should escpae pointer', () => {
var val = pipe.transform(unescaped);
val.should.be.equal(escaped);
});
2015-12-14 19:31:17 +03:00
2015-12-19 20:36:28 +03:00
it('should not support other objects', () => {
(() => pipe.transform(45)).should.throw();
(() => pipe.transform({})).should.throw();
});
it('should not throw on blank input', () => {
(() => pipe.transform()).should.not.throw();
});
2015-12-14 19:31:17 +03:00
});
2015-12-14 19:14:35 +03:00
});
2015-12-19 20:36:28 +03:00
describe('MarkedPipe', () => {
let unmarked;
let marked;
var pipe;
2015-12-14 19:14:35 +03:00
2015-12-19 20:36:28 +03:00
beforeEach(() => {
unmarked = 'test\n';
2016-01-23 17:00:38 +03:00
marked = '<span class="redoc-markdown-block"><p>test</p>\n</span>';
2015-12-19 20:36:28 +03:00
pipe = new MarkedPipe();
2015-12-14 19:14:35 +03:00
});
2015-12-19 20:36:28 +03:00
describe('MarkedPipe transform', () => {
2016-01-23 17:00:38 +03:00
it('should wrap in markdown span', () => {
2015-12-19 20:36:28 +03:00
var val = pipe.transform(unmarked);
val.should.be.equal(marked);
});
it('should not support other objects', () => {
(() => pipe.transform(45)).should.throw();
(() => pipe.transform({})).should.throw();
});
2015-12-14 19:31:17 +03:00
2015-12-19 20:36:28 +03:00
it('should not throw on blank input', () => {
(() => pipe.transform()).should.not.throw();
});
2015-12-14 19:31:17 +03:00
});
2015-12-14 19:14:35 +03:00
});
});