UNPKG

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