Completed
Push — master ( 8bee3a...8be05e )
by greg
01:46
created

describe(ꞌcmsEditor.handlebars.sourceAttrꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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
    }
12
  });
13
14
  it('sourceAttr', function() {
15
    var obj = this.fixture.gmapsElement
16
    var params = {
17
      display:'{{formatted_address}}',
18
      value: 'State of Pará, Brazil'
19
    }
20
    var json = sourceAttr.default(obj, params)
21
    chai.expect(json.selected).to.equal('selected')
22
    chai.expect(json.val).to.equal('State of Pará, Brazil')
23
  });
24
25
  it('get path', function() {
26
    var obj = this.fixture.gmapsElement
27
    var path = 'geometry.location.lat'
28
    var str = sourceAttr.get(obj, path)
29
    chai.expect(str).to.equal(-1.9981271)
30
  });
31
32
  it('get unknown path', function() {
33
    var obj = this.fixture.gmapsElement
34
    var path = 'errored.path'
35
    var str = sourceAttr.get(obj, path)
36
    chai.expect(str).to.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(str).to.be.undefined is not used.
Loading history...
37
  });
38
39
  it('prepareDisplay value', function() {
40
    var obj = this.fixture.gmapsElement
41
    var str = 'formatted_address'
42
    str = sourceAttr.prepareDisplay(obj, str)
43
    chai.expect(str).to.equal('State of Pará, Brazil')
44
  });
45
46
  it('prepareDisplay variable', function() {
47
    var obj = this.fixture.gmapsElement
48
    var str = '{{formatted_address}}'
49
    str = sourceAttr.prepareDisplay(obj, str)
50
    chai.expect(str).to.equal('State of Pará, Brazil')
51
  });
52
53
  it('prepareDisplay 2 variables', function() {
54
    var obj = this.fixture.gmapsElement
55
    var str = '{{formatted_address}} - {{geometry.location.lat}}'
56
    str = sourceAttr.prepareDisplay(obj, str)
57
    chai.expect(str).to.equal('State of Pará, Brazil - -1.9981271')
58
  });
59
60
  it('prepareDisplay unknown', function() {
61
    var obj = this.fixture.gmapsElement
62
    var str = 'unknownkey'
63
    str = sourceAttr.prepareDisplay(obj, str)
64
    chai.expect(str).to.equal(str)
65
  });
66
67
  it('getKeys key', function() {
68
    var ar = sourceAttr.getKeys('key')
69
    chai.expect(ar.length).to.equal(1)
70
  });
71
72
  it('getKeys {{key}}', function() {
73
    var ar = sourceAttr.getKeys('{{key}}')
74
    chai.expect(ar.length).to.equal(1)
75
  });
76
77
  it('getKeys {{key}}-nokey-{{key2}}', function() {
78
    var ar = sourceAttr.getKeys('{{key}}-nokey-{{key2}}')
79
    chai.expect(ar.length).to.equal(2)
80
  });
81
});