UNPKG

1.99 kBJavaScriptView Raw
1/*global describe, it */
2
3var helper = require('../lib/helper')
4 , should = require('chai').should()
5;
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});