1 |
|
2 |
|
3 | var helper = require('../lib/helper')
|
4 | , should = require('chai').should()
|
5 | ;
|
6 |
|
7 | describe('helper.simplifyNode()', function(){
|
8 | it('should return the already simplified', function(){
|
9 | should.not.exist(helper.simplifyNode(null));
|
10 | helper.simplifyNode('simple').should.equal('simple');
|
11 | });
|
12 |
|
13 | it('should return only text when really simple', function(){
|
14 | var input = {
|
15 | $name: 'title',
|
16 | $attrs: {},
|
17 | $text: 'this is a title'
|
18 | };
|
19 | helper.simplifyNode(input, true).should.equal('this is a title');
|
20 | helper.simplifyNode(input).should.not.equal('this is a title');
|
21 | });
|
22 |
|
23 | it('should return only attributes when really simple', function(){
|
24 | var input = {
|
25 | $name: 'div',
|
26 | $attrs: {id: '34', type:'thing'},
|
27 | };
|
28 | helper.simplifyNode(input).should.deep.equal({$name: 'div', id: '34', type: 'thing'});
|
29 | helper.simplifyNode(input, true).should.deep.equal({id: '34', type: 'thing'});
|
30 | });
|
31 |
|
32 | it('should drop unecessary properties', function(){
|
33 | var input, output;
|
34 |
|
35 | input = {
|
36 | $name: 'title',
|
37 | $attrs: {id: '34'},
|
38 | $text: null
|
39 | };
|
40 |
|
41 | output = {
|
42 | $name: 'title',
|
43 | id: '34'
|
44 | };
|
45 | helper.simplifyNode(input).should.deep.equal(output);
|
46 | helper.simplifyNode(input, true).should.deep.equal(input.$attrs);
|
47 | });
|
48 |
|
49 | it('should simplify $markup', function(){
|
50 | var input, output;
|
51 |
|
52 | input = {
|
53 | $name: 'title',
|
54 | $attrs: {},
|
55 | $markup: [{$name: 'p', $attrs: {}, $markup: ['stuff']}]
|
56 | };
|
57 |
|
58 | output = {
|
59 | $name: 'title',
|
60 | $markup: [{$name: 'p', $markup: ['stuff']}]
|
61 | };
|
62 | helper.simplifyNode(input).should.deep.equal(output);
|
63 |
|
64 | });
|
65 |
|
66 | it('should strip single-element arrays', function(){
|
67 |
|
68 | helper.simplifyNode({
|
69 | $name: 'tag',
|
70 | 'stuff':['test']
|
71 | }).should.deep.equal({
|
72 | $name: 'tag',
|
73 | 'stuff':'test'
|
74 | });
|
75 |
|
76 | helper.simplifyNode(['test']).should.equal('test');
|
77 | });
|
78 |
|
79 | it('should not simplify when things get interesting', function(){
|
80 | var input, output;
|
81 |
|
82 | input = {
|
83 | $name: 'header',
|
84 | $attrs: {id: '3'},
|
85 | $markup: [ 'some text' ]
|
86 | };
|
87 |
|
88 | output = {
|
89 | $name: 'header',
|
90 | $attrs: {id: '3'},
|
91 | $markup: ['some text']
|
92 | };
|
93 |
|
94 | helper.simplifyNode(input).should.deep.equal(output);
|
95 | delete output.$name;
|
96 |
|
97 | helper.simplifyNode(input, true).should.deep.equal(output);
|
98 | });
|
99 | });
|