UNPKG

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