-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
144 lines (121 loc) · 4.92 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
const expect = require('chai').expect,
dirname = __dirname.split('/').pop(),
filename = __filename.split('/').pop().split('.').shift(),
lib = require('./' + filename);
describe(dirname, function () {
describe(filename, function () {
const mockRef = '/_components/a/instances/foo';
describe('save', function () {
const fn = lib[this.title];
it ('saves simple-list content descriptors as an array of strings in edit mode', function () {
const mockData = {
includeTags: [{text: 'a'}, {text: 'b'}],
excludeTags: [{text: 'c'}],
includeContentChannels: [{text: 'd'}],
excludeContentChannels: [{text: 'e'}],
includeFeatureTypes: [{text: 'f'}],
excludeFeatureTypes: [{text: 'g'}],
includeStoryCharacteristics: [{text: 'h'}],
excludeStoryCharacteristics: [{text: 'i'}],
sitePrefixes: [{text: 'j'}],
crossposts: [{text: 'k'}],
dedupeContexts: [{text: 'l'}],
},
expectedResult = {
includeTags: ['a', 'b'],
excludeTags: ['c'],
includeContentChannels: ['d'],
excludeContentChannels: ['e'],
includeFeatureTypes: ['f'],
excludeFeatureTypes: ['g'],
includeStoryCharacteristics: ['h'],
excludeStoryCharacteristics: ['i'],
sitePrefixes: ['j'],
crossposts: ['k'],
dedupeContexts: ['l']
};
expect(fn(mockRef, mockData, {edit: true}))
.to.deep.include(expectedResult);
});
it ('removes empty strings from arrays in edit mode', function () {
const mockData = {
includeTags: [{text: 'a'}, {text: ''}]
},
expectedResult = {
includeTags: ['a']
};
expect(fn(mockRef, mockData, {edit: true})).to.deep.include(expectedResult);
});
it ('converts https overrideUrls to http', function () {
expect(fn(mockRef, {overrideUrl: 'https://foo.com'}, {}).overrideUrl).to.equal('http://foo.com');
});
it ('converts relative overrideUrls to http', function () {
expect(fn(mockRef, {overrideUrl: '//foo.com'}, {}).overrideUrl).to.equal('http://foo.com');
});
});
describe('render', function () {
const fn = lib[this.title];
it ('returns input data', function () {
const mockData = {};
expect(fn(mockRef, mockData)).to.equal(mockData);
});
it ('renders simple-list content descriptors as an array of {text: string} objects in edit mode', function () {
const mockData = {
includeTags: ['a', 'b'],
excludeTags: ['c'],
includeContentChannels: ['d'],
excludeContentChannels: ['e'],
includeFeatureTypes: ['f'],
excludeFeatureTypes: ['g'],
includeStoryCharacteristics: ['h'],
excludeStoryCharacteristics: ['i'],
sitePrefixes: ['j'],
crossposts: ['k'],
dedupeContexts: ['l']
},
expectedResult = {
includeTags: [{text: 'a'}, {text: 'b'}],
excludeTags: [{text: 'c'}],
includeContentChannels: [{text: 'd'}],
excludeContentChannels: [{text: 'e'}],
includeFeatureTypes: [{text: 'f'}],
excludeFeatureTypes: [{text: 'g'}],
includeStoryCharacteristics: [{text: 'h'}],
excludeStoryCharacteristics: [{text: 'i'}],
sitePrefixes: [{text: 'j'}],
crossposts: [{text: 'k'}],
dedupeContexts: [{text: 'l'}],
};
expect(fn(mockRef, mockData, {edit: true})).to.eql(expectedResult);
});
});
describe('getCallout', function () {
const fn = lib[this.title];
it ('returns an empty string if there is no article data', function () {
expect(fn()).to.equal('');
});
it ('returns an empty string if the article data has no tags set', function () {
expect(fn({})).to.equal('');
});
it ('returns an empty string if the article has an empty tags array', function () {
expect(fn({tags:[]})).to.equal('');
});
it ('returns an empty string if the article has no relevant tags', function () {
expect(fn({tags:['foo']})).to.equal('');
});
it ('returns "video" if article has the tag "video"', function () {
expect(fn({tags:['video']})).to.equal('video');
});
it ('returns "video" if the article has the tag "original video"', function () {
expect(fn({tags: ['original video']})).to.equal('video');
});
it ('returns "gallery" if the article has the tag "gallery"', function () {
expect(fn({tags: ['gallery']})).to.equal('gallery');
});
it ('prefers "video" to "gallery"', function () {
expect(fn({tags: ['video', 'gallery']})).to.equal('video');
});
});
});
});