1
|
|
|
var chai = require('chai'); |
2
|
|
|
var sinonChai = require('sinon-chai') |
3
|
|
|
var expect = chai.expect |
4
|
|
|
chai.use(sinonChai) |
5
|
|
|
var sinon = require('sinon'); |
6
|
|
|
var path = require('path'); |
7
|
|
|
var fse = require('fs-extra'); |
8
|
|
|
|
9
|
|
|
var config = require('../../../src/cli').config |
10
|
|
|
config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) |
11
|
|
|
|
12
|
|
|
var abeExtend = require('../../../src/cli').abeExtend; |
13
|
|
|
var cmsData = require('../../../src/cli').cmsData; |
14
|
|
|
var cmsTemplates = require('../../../src/cli').cmsTemplates; |
15
|
|
|
var coreUtils = require('../../../src/cli').coreUtils; |
16
|
|
|
var Manager = require('../../../src/cli').Manager; |
17
|
|
|
|
18
|
|
|
describe('cmsTemplates.prepare', function() { |
19
|
|
|
before( function(done) { |
20
|
|
|
Manager.instance.init() |
21
|
|
|
.then(function () { |
22
|
|
|
this.fixture = { |
23
|
|
|
visibleTrue: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-true.html'), 'utf-8'), |
24
|
|
|
visibleFalse: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-false.html'), 'utf-8'), |
25
|
|
|
text: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-text.html'), 'utf-8'), |
26
|
|
|
attribute: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute.html'), 'utf-8'), |
27
|
|
|
attributeConcat: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-concat.html'), 'utf-8'), |
28
|
|
|
attributeMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-multiple.html'), 'utf-8'), |
29
|
|
|
source: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-source.html'), 'utf-8'), |
30
|
|
|
each: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each.html'), 'utf-8'), |
31
|
|
|
eachMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-multiple.html'), 'utf-8'), |
32
|
|
|
rawHandlebar: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-raw-handlebars.html'), 'utf-8') |
33
|
|
|
} |
34
|
|
|
done() |
35
|
|
|
|
36
|
|
|
}.bind(this)) |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* cmsTemplates.template.addAbeDataAttrForHtmlTag |
41
|
|
|
* |
42
|
|
|
*/ |
43
|
|
|
it('cmsTemplates.prepare.addAbeDataAttrForHtmlTag()', function() { |
44
|
|
|
// stub |
45
|
|
|
|
46
|
|
|
// test |
47
|
|
|
var template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.text) |
48
|
|
|
chai.expect(template.indexOf('data-abe-')).to.be.above(-1); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* cmsTemplates.template.getAbeAttributeData |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
it('cmsTemplates.prepare.getAbeAttributeData()', function() { |
56
|
|
|
// stub |
57
|
|
|
|
58
|
|
|
// test |
59
|
|
|
var template = cmsTemplates.prepare.getAbeAttributeData( |
60
|
|
|
this.fixture.attribute, |
61
|
|
|
"src=\"{{abe type='image' key='image_key' tab='default'}}\"", |
62
|
|
|
"src", |
63
|
|
|
"{{abe type='image' key='image_key' tab='default'}}" |
64
|
|
|
) |
65
|
|
|
chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* cmsTemplates.template.addHasAbeAttr |
70
|
|
|
* |
71
|
|
|
*/ |
72
|
|
|
it('cmsTemplates.prepare.addHasAbeAttr()', function() { |
73
|
|
|
// stub |
74
|
|
|
|
75
|
|
|
// test |
76
|
|
|
var template = cmsTemplates.prepare.addHasAbeAttr("}}") |
77
|
|
|
chai.expect(template.indexOf('has-abe=1}}')).to.be.above(-1); |
78
|
|
|
}); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* cmsTemplates.template.addAbeDataAttrForHtmlAttributes |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
|
it('cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes()', function() { |
85
|
|
|
// stub |
86
|
|
|
|
87
|
|
|
// test |
88
|
|
|
var template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attribute) |
89
|
|
|
chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
90
|
|
|
|
91
|
|
|
template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeConcat) |
92
|
|
|
chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
93
|
|
|
|
94
|
|
|
template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeMultiple) |
95
|
|
|
chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
96
|
|
|
chai.expect(template.indexOf('data-abe-attr-alternate="alt" data-abe-alternate="alternate" alt="mon alt')).to.be.above(-1); |
97
|
|
|
|
98
|
|
|
template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.each) |
99
|
|
|
chai.expect(template.indexOf('data-abe-attr-test[index].img="src" data-abe-test[index].img="test[index].img" data-abe-attr-test{{@index}}.img="src" data-abe-test{{@index}}.img="test[index].img" src="')).to.be.above(-1); |
100
|
|
|
|
101
|
|
|
template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.eachMultiple) |
102
|
|
|
chai.expect(template.indexOf('data-abe-attr-test[index].img="src" data-abe-test[index].img="test[index].img" data-abe-attr-test{{@index}}.img="src" data-abe-test{{@index}}.img="test[index].img" src="')).to.be.above(-1); |
103
|
|
|
chai.expect(template.indexOf('data-abe-attr-test[index].alternate="alt" data-abe-test[index].alternate="test[index].alternate" data-abe-attr-test{{@index}}.alternate="alt" data-abe-test{{@index}}.alternate="test[index].alternate" alt="')).to.be.above(-1); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* cmsTemplates.template.addAbeSourceComment |
108
|
|
|
* |
109
|
|
|
*/ |
110
|
|
|
it('cmsTemplates.prepare.addAbeSourceComment()', function() { |
111
|
|
|
// stub |
112
|
|
|
|
113
|
|
|
// test |
114
|
|
|
var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.source, |
115
|
|
|
{ |
116
|
|
|
abe_source: { |
117
|
|
|
data_key: [{title: "test"}] |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
) |
121
|
|
|
|
122
|
|
|
chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
123
|
|
|
chai.expect(template.indexOf('-->')).to.be.above(-1); |
124
|
|
|
}); |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* cmsTemplates.template.addAbeHtmlTagBetweenAbeTags |
128
|
|
|
* |
129
|
|
|
*/ |
130
|
|
|
it('cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags()', function() { |
131
|
|
|
// stub |
132
|
|
|
|
133
|
|
|
// test |
134
|
|
|
var template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.text) |
135
|
|
|
chai.expect(template.indexOf('<abe>{{')).to.be.above(-1); |
136
|
|
|
chai.expect(template.indexOf('}}</abe>')).to.be.above(-1); |
137
|
|
|
}); |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* cmsTemplates.template.replaceAbeEachIndex |
141
|
|
|
* |
142
|
|
|
*/ |
143
|
|
|
it('cmsTemplates.prepare.replaceAbeEachIndex()', function() { |
144
|
|
|
// stub |
145
|
|
|
|
146
|
|
|
// test |
147
|
|
|
var template = cmsTemplates.prepare.replaceAbeEachIndex('[index].') |
148
|
|
|
chai.expect(template).to.be.equal('{{@index}}-'); |
149
|
|
|
}); |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* cmsTemplates.template.removeHiddenAbeTag |
153
|
|
|
* |
154
|
|
|
*/ |
155
|
|
|
it('cmsTemplates.prepare.removeHiddenAbeTag()', function() { |
156
|
|
|
// stub |
157
|
|
|
|
158
|
|
|
// test |
159
|
|
|
var template = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleFalse) |
160
|
|
|
chai.expect(template).to.be.equal(""); |
161
|
|
|
|
162
|
|
|
// test |
163
|
|
|
var template2 = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleTrue) |
164
|
|
|
chai.expect(template2.indexOf('{{abe')).to.be.above(-1); |
165
|
|
|
}); |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* cmsTemplates.template.removeHandlebarsRawFromHtml |
169
|
|
|
* |
170
|
|
|
*/ |
171
|
|
|
it('cmsTemplates.prepare.removeHandlebarsRawFromHtml()', function() { |
172
|
|
|
// stub |
173
|
|
|
|
174
|
|
|
// test |
175
|
|
|
var template = cmsTemplates.prepare.removeHandlebarsRawFromHtml(this.fixture.rawHandlebar) |
176
|
|
|
chai.expect(template).to.be.equal("test"); |
177
|
|
|
}); |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* cmsTemplates.template.splitEachBlocks |
181
|
|
|
* |
182
|
|
|
*/ |
183
|
|
|
it('cmsTemplates.prepare.splitEachBlocks()', function() { |
184
|
|
|
// stub |
185
|
|
|
|
186
|
|
|
// test |
187
|
|
|
var blocks = cmsTemplates.prepare.splitEachBlocks(this.fixture.each) |
188
|
|
|
chai.expect(blocks.length).to.be.above(0); |
189
|
|
|
}); |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* cmsTemplates.template.indexEachBlocks |
193
|
|
|
* |
194
|
|
|
*/ |
195
|
|
|
it('cmsTemplates.prepare.indexEachBlocks()', function() { |
196
|
|
|
// stub |
197
|
|
|
|
198
|
|
|
// test |
199
|
|
|
var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.each, false) |
200
|
|
|
chai.expect(template.indexOf('data-abe-block="test{{@index}}"')).to.be.above(-1); |
201
|
|
|
chai.expect(template.indexOf('<!-- [[test]]')).to.be.above(-1); |
202
|
|
|
|
203
|
|
|
var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachMultiple, false) |
|
|
|
|
204
|
|
|
chai.expect(template.indexOf('data-abe-block')).to.be.above(-1); |
205
|
|
|
chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1); |
206
|
|
|
}); |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* cmsTemplates.template.addAbeDictionnary |
210
|
|
|
* |
211
|
|
|
*/ |
212
|
|
|
it('cmsTemplates.prepare.addAbeDictionnary()', function() { |
213
|
|
|
// stub |
214
|
|
|
|
215
|
|
|
// test |
216
|
|
|
var template = cmsTemplates.prepare.addAbeDictionnary(this.fixture.each, "{{abe type='text' key='test.title' desc='test title' tab='default'}}", 'test') |
217
|
|
|
chai.expect(template.indexOf("abe dictionnary='test'")).to.be.above(-1); |
218
|
|
|
}); |
219
|
|
|
}); |
220
|
|
|
|
This check looks for variables that are declared in multiple lines. There may be several reasons for this.
In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.
If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.