1 |
|
2 |
|
3 |
|
4 | const helper = require('../lib/helper');
|
5 | require('chai').should();
|
6 |
|
7 | describe('helper.objectifyMarkup()', () => {
|
8 | it('should add object array properties from $markup', () => {
|
9 | const input = {
|
10 | $name: 'root',
|
11 | $attrs: {},
|
12 | $markup: [
|
13 | 'text',
|
14 | [
|
15 | { $name: 'item', $text: 'something' },
|
16 | { $name: 'item', $text: 'else' }
|
17 | ]
|
18 | ]
|
19 | };
|
20 |
|
21 | const output = {
|
22 | $name: 'root',
|
23 | $attrs: {},
|
24 | $text: 'text',
|
25 | item: [ 'something', 'else' ]
|
26 | };
|
27 |
|
28 | helper.objectifyMarkup(input).should.deep.equal(output);
|
29 | });
|
30 |
|
31 | it('should aggregate everything from $markup', () => {
|
32 | const input = {
|
33 | $name: 'root',
|
34 | $attrs: {},
|
35 | $markup: [
|
36 | 'text',
|
37 | [
|
38 | { $name: 'item', $text: 'something' },
|
39 | { $name: 'item', $text: 'else' }
|
40 | ],
|
41 | 'text',
|
42 | { $name: 'item', $text: 'otherwise' }
|
43 | ]
|
44 | };
|
45 |
|
46 | const output = {
|
47 | $name: 'root',
|
48 | $attrs: {},
|
49 | $text: [ 'text', 'text' ],
|
50 | item: [ 'something', 'else', 'otherwise' ]
|
51 | };
|
52 | helper.objectifyMarkup(input).should.deep.equal(output);
|
53 | });
|
54 |
|
55 | it('should not oversimplify', () => {
|
56 | const input = {
|
57 | $name: 'thing',
|
58 | $markup: [{
|
59 | $name: 'header',
|
60 | $attrs: { id: '3' },
|
61 | $markup: [ 'some text' ]
|
62 | }]
|
63 | };
|
64 |
|
65 | const output = {
|
66 | $name: 'thing',
|
67 | header: {
|
68 | $attrs: { id: '3' },
|
69 | $markup: [ 'some text' ]
|
70 | }
|
71 | };
|
72 |
|
73 | helper.objectifyMarkup(input).should.deep.equal(output);
|
74 | });
|
75 |
|
76 | it('should preserve arrays if asked', () => {
|
77 | const input = {
|
78 | $name: 'root',
|
79 | $attrs: {},
|
80 | $markup: [
|
81 | 'text',
|
82 | { $name: 'item', $text: 'something' }
|
83 | ]
|
84 | };
|
85 |
|
86 | const output = {
|
87 | $name: 'root',
|
88 | $attrs: {},
|
89 | $text: [ 'text' ],
|
90 | item: [ 'something' ]
|
91 | };
|
92 |
|
93 | helper.objectifyMarkup(input, true).should.deep.equal(output);
|
94 | });
|
95 | });
|