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 | helper.simplifyNode('simple').should.equal('simple');
|
10 | });
|
11 |
|
12 | it('should return only text when really simple', function(){
|
13 | var input = {
|
14 | $name: 'title',
|
15 | $attrs: {},
|
16 | $text: 'this is a title'
|
17 | };
|
18 | helper.simplifyNode(input, true).should.equal('this is a title');
|
19 | helper.simplifyNode(input).should.not.equal('this is a title');
|
20 | });
|
21 |
|
22 | it('should return only attributes when really simple', function(){
|
23 | var input = {
|
24 | $name: 'div',
|
25 | $attrs: {id: '34', type:'thing'},
|
26 | };
|
27 | helper.simplifyNode(input).should.deep.equal({$name: 'div', id: '34', type: 'thing'});
|
28 | helper.simplifyNode(input, true).should.deep.equal({id: '34', type: 'thing'});
|
29 | });
|
30 |
|
31 | it('should drop unecessary properties', function(){
|
32 | var input, output;
|
33 |
|
34 | input = {
|
35 | $name: 'title',
|
36 | $attrs: {id: '34'},
|
37 | $text: null
|
38 | };
|
39 |
|
40 | output = {
|
41 | $name: 'title',
|
42 | id: '34'
|
43 | };
|
44 | helper.simplifyNode(input).should.deep.equal(output);
|
45 | helper.simplifyNode(input, true).should.deep.equal(input.$attrs);
|
46 | });
|
47 |
|
48 | it('should simplify $markup', function(){
|
49 | var input, output;
|
50 |
|
51 | input = {
|
52 | $name: 'title',
|
53 | $attrs: {},
|
54 | $markup: [{$name: 'p', $attrs: {}, $markup: ['stuff']}]
|
55 | };
|
56 |
|
57 | output = {
|
58 | $name: 'title',
|
59 | $markup: [{$name: 'p', $markup: ['stuff']}]
|
60 | };
|
61 | helper.simplifyNode(input).should.deep.equal(output);
|
62 |
|
63 | });
|
64 |
|
65 | it('should not simplify when things get interesting', function(){
|
66 | var input, output;
|
67 |
|
68 | input = {
|
69 | $name: 'header',
|
70 | $attrs: {id: '3'},
|
71 | $markup: [ 'some text' ]
|
72 | };
|
73 |
|
74 | output = {
|
75 | $name: 'header',
|
76 | $attrs: {id: '3'},
|
77 | $markup: ['some text']
|
78 | };
|
79 |
|
80 | helper.simplifyNode(input).should.deep.equal(output);
|
81 | delete output.$name;
|
82 |
|
83 | helper.simplifyNode(input, true).should.deep.equal(output);
|
84 | });
|
85 | });
|