|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
var path = require('path'); |
|
3
|
|
|
var fse = require('fs-extra'); |
|
4
|
|
|
|
|
5
|
|
|
var sourceAttr = require('../../../../src/cli/cms/editor/handlebars/sourceAttr') |
|
6
|
|
|
|
|
7
|
|
|
describe('cmsEditor.handlebars.sourceAttr', function() { |
|
8
|
|
|
before( function() { |
|
9
|
|
|
this.fixture = { |
|
10
|
|
|
gmapsElement: fse.readJsonSync(path.join(__dirname, '../../../fixtures/editor/gmaps-element.json'), 'utf8'), |
|
11
|
|
|
colors: fse.readJsonSync(path.join(__dirname, '../../../fixtures/editor/colors.json'), 'utf8') |
|
12
|
|
|
} |
|
13
|
|
|
}); |
|
14
|
|
|
|
|
15
|
|
|
it('sourceAttr test', function() { |
|
16
|
|
|
var obj = this.fixture.gmapsElement |
|
17
|
|
|
var params = { |
|
18
|
|
|
display:'{{formatted_address}}', |
|
19
|
|
|
value: [{formatted_address: 'State of Pará, Brazil'}] |
|
20
|
|
|
} |
|
21
|
|
|
var json = sourceAttr.default(obj, params) |
|
22
|
|
|
chai.expect(json.selected).to.equal('selected') |
|
23
|
|
|
chai.expect(json.val).to.equal('State of Pará, Brazil') |
|
24
|
|
|
}); |
|
25
|
|
|
|
|
26
|
|
|
it('sourceAttr string', function() { |
|
27
|
|
|
var obj = this.fixture.colors |
|
|
|
|
|
|
28
|
|
|
var params = { |
|
29
|
|
|
display: null, |
|
30
|
|
|
value: ["red"], |
|
31
|
|
|
source: this.fixture.colors |
|
32
|
|
|
} |
|
33
|
|
|
var json = sourceAttr.default("red", params) |
|
34
|
|
|
chai.expect(json.selected).to.equal('selected') |
|
35
|
|
|
chai.expect(json.val).to.equal('red') |
|
36
|
|
|
}); |
|
37
|
|
|
|
|
38
|
|
|
it('get path', function() { |
|
39
|
|
|
var obj = this.fixture.gmapsElement |
|
40
|
|
|
var path = 'geometry.location.lat' |
|
41
|
|
|
var str = sourceAttr.get(obj, path) |
|
42
|
|
|
chai.expect(str).to.equal(-1.9981271) |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
it('get unknown path', function() { |
|
46
|
|
|
var obj = this.fixture.gmapsElement |
|
47
|
|
|
var path = 'errored.path' |
|
48
|
|
|
var str = sourceAttr.get(obj, path) |
|
49
|
|
|
chai.expect(str).to.be.undefined; |
|
|
|
|
|
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
it('prepareDisplay value', function() { |
|
53
|
|
|
var obj = this.fixture.gmapsElement |
|
54
|
|
|
var str = 'formatted_address' |
|
55
|
|
|
str = sourceAttr.prepareDisplay(obj, str) |
|
56
|
|
|
chai.expect(str).to.equal('State of Pará, Brazil') |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
it('prepareDisplay variable', function() { |
|
60
|
|
|
var obj = this.fixture.gmapsElement |
|
61
|
|
|
var str = '{{formatted_address}}' |
|
62
|
|
|
str = sourceAttr.prepareDisplay(obj, str) |
|
63
|
|
|
chai.expect(str).to.equal('State of Pará, Brazil') |
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
it('prepareDisplay 2 variables', function() { |
|
67
|
|
|
var obj = this.fixture.gmapsElement |
|
68
|
|
|
var str = '{{formatted_address}} - {{geometry.location.lat}}' |
|
69
|
|
|
str = sourceAttr.prepareDisplay(obj, str) |
|
70
|
|
|
chai.expect(str).to.equal('State of Pará, Brazil - -1.9981271') |
|
71
|
|
|
}); |
|
72
|
|
|
|
|
73
|
|
|
it('prepareDisplay unknown', function() { |
|
74
|
|
|
var obj = this.fixture.gmapsElement |
|
75
|
|
|
var str = 'unknownkey' |
|
76
|
|
|
str = sourceAttr.prepareDisplay(obj, str) |
|
77
|
|
|
chai.expect(str).to.equal(str) |
|
78
|
|
|
}); |
|
79
|
|
|
|
|
80
|
|
|
it('prepareDisplay null', function() { |
|
81
|
|
|
var obj = this.fixture.colors |
|
82
|
|
|
var str = null |
|
83
|
|
|
str = sourceAttr.prepareDisplay(obj, str) |
|
84
|
|
|
chai.expect(str).to.equal(this.fixture.colors) |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
it('getKeys key', function() { |
|
88
|
|
|
var ar = sourceAttr.getKeys('key') |
|
89
|
|
|
chai.expect(ar.length).to.equal(1) |
|
90
|
|
|
}); |
|
91
|
|
|
|
|
92
|
|
|
it('getKeys {{key}}', function() { |
|
93
|
|
|
var ar = sourceAttr.getKeys('{{key}}') |
|
94
|
|
|
chai.expect(ar.length).to.equal(1) |
|
95
|
|
|
}); |
|
96
|
|
|
|
|
97
|
|
|
it('getKeys {{key}}-nokey-{{key2}}', function() { |
|
98
|
|
|
var ar = sourceAttr.getKeys('{{key}}-nokey-{{key2}}') |
|
99
|
|
|
chai.expect(ar.length).to.equal(2) |
|
100
|
|
|
}); |
|
101
|
|
|
}); |