1 |
|
2 |
|
3 |
|
4 | var helper = require('../lib/helper');
|
5 | require('chai').should();
|
6 |
|
7 | describe('helper.condenseArray()', function() {
|
8 | it('should condense a homogeneous list into a single element array', function() {
|
9 | var input, output;
|
10 | input = [
|
11 | { $name: 'item', $text: 'something' },
|
12 | { $name: 'item', $text: 'else' }
|
13 | ];
|
14 | output = [[
|
15 | { $name: 'item', $text: 'something' },
|
16 | { $name: 'item', $text: 'else' }
|
17 | ]];
|
18 | helper.condenseArray(input).should.deep.equal(output);
|
19 | });
|
20 |
|
21 | it('should condense contiguous items', function() {
|
22 | var input, output;
|
23 | input = [
|
24 | { $name: 'item', $text: 'something' },
|
25 | { $name: 'item', $text: 'else' },
|
26 | { $name: 'other', $text: 'something' },
|
27 | { $name: 'other', $text: 'else' }
|
28 | ];
|
29 | output = [
|
30 | [
|
31 | { $name: 'item', $text: 'something' },
|
32 | { $name: 'item', $text: 'else' }
|
33 | ],
|
34 | [
|
35 | { $name: 'other', $text: 'something' },
|
36 | { $name: 'other', $text: 'else' }
|
37 | ]
|
38 | ];
|
39 | helper.condenseArray(input).should.deep.equal(output);
|
40 | });
|
41 |
|
42 | it('should not condense noncontiguous items', function() {
|
43 | var input, output;
|
44 | input = [
|
45 | { $name: 'other', $text: 'something' },
|
46 | { $name: 'item', $text: 'something' },
|
47 | { $name: 'item', $text: 'else' },
|
48 | { $name: 'other', $text: 'else' }
|
49 | ];
|
50 | output = [
|
51 | [{ $name: 'other', $text: 'something' }],
|
52 | [
|
53 | { $name: 'item', $text: 'something' },
|
54 | { $name: 'item', $text: 'else' }
|
55 | ],
|
56 | [{ $name: 'other', $text: 'else' }]
|
57 | ];
|
58 | helper.condenseArray(input).should.deep.equal(output);
|
59 | });
|
60 |
|
61 | it('should condense text to single text elements', function() {
|
62 | var input, output;
|
63 | input = [
|
64 | 'Something said...',
|
65 | 'words here.',
|
66 | { $name: 'item', $text: 'something' },
|
67 | { $name: 'item', $text: 'else' },
|
68 | { $name: 'other', $text: 'else' },
|
69 | 'more words'
|
70 | ];
|
71 | output = [
|
72 | 'Something said...words here.',
|
73 | [
|
74 | { $name: 'item', $text: 'something' },
|
75 | { $name: 'item', $text: 'else' }
|
76 | ],
|
77 | [{ $name: 'other', $text: 'else' }],
|
78 | 'more words'
|
79 | ];
|
80 | helper.condenseArray(input).should.deep.equal(output);
|
81 | });
|
82 | });
|