Completed
Push — master ( 675e71...1fbf32 )
by greg
01:38
created

test/templates.js   A

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 100
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 12
c 1
b 0
f 0
nc 1
mnd 0
bc 12
fnc 12
dl 0
loc 100
rs 10
bpm 1
cpm 1
noi 5

1 Function

Rating   Name   Duplication   Size   Complexity  
B templates.js ➔ describe(ꞌTemplateꞌ) 0 90 1
1
var chai = require('chai');
2
var path = require('path');
3
4
var config = require('../src/cli').config
5
config.set({root: __dirname + '/fixtures'})
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
6
7
var cmsTemplates = require('../src/cli').cmsTemplates;
8
var Manager = require('../src/cli').Manager;
9
var fse = require('fs-extra');
10
11
describe('Template', function() {
12
  before( function(done) {
13
    Manager.instance.init()
14
      .then(function () {
15
        this.fixture = {
16
          template: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf-8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
17
          articleEach: fse.readFileSync(__dirname + '/fixtures/templates/article-each-abe.html', 'utf-8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
18
          templateKeys: fse.readFileSync(__dirname + '/fixtures/templates/article-keys.html', 'utf-8')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
19
        }
20
        done()
21
        
22
      }.bind(this))
23
  });
24
25
  /**
26
   * getAbeImport
27
   * 
28
   */
29
  it('cmsTemplates.template.getStructureAndTemplatesFiles()', function() {
30
    var res = cmsTemplates.template.getStructureAndTemplatesFiles()
31
    chai.expect(res.templates.length).to.be.above(1);
32
  });
33
34
  /**
35
   * getAbeImport
36
   * 
37
   */
38
  it('cmsTemplates.template.getAbeImport()', function() {
39
    var res = cmsTemplates.template.getAbeImport(this.fixture.template)
40
    chai.expect(res).to.have.length(4);
41
  });
42
43
  /**
44
   * includePartials
45
   * 
46
   */
47
  it('cmsTemplates.template.includePartials()', function() {
48
    var template = cmsTemplates.template.includePartials(this.fixture.template)
49
    chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default'}}");
50
  });
51
52
  /**
53
   * cmsTemplates.template.getTemplate
54
   * 
55
   */
56
  it('cmsTemplates.template.getTemplate()', function() {
57
    var template = cmsTemplates.template.getTemplate('article')
58
    chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default' order='1'}}");
59
  });
60
61
  /**
62
   * getTemplate
63
   * 
64
   */
65
  it('cmsTemplates.template.getSelectTemplateKeys()', function() {
66
    const pathTemplate = path.join(config.root, config.templates.url)
67
    cmsTemplates.template.getSelectTemplateKeys(pathTemplate)
68
      .then((whereKeys) => {
69
        chai.expect(whereKeys.indexOf('abe_meta.date')).to.be.above(-1);
70
      })
71
  });
72
73
  /**
74
   * getTemplate
75
   * 
76
   */
77
  it('cmsTemplates.template.execRequestColumns()', function() { // templateKeys
78
    const pathTemplate = path.join(config.root, config.templates.url)
0 ignored issues
show
Unused Code introduced by
The constant pathTemplate seems to be never used. Consider removing it.
Loading history...
79
    var ar = cmsTemplates.template.execRequestColumns(this.fixture.templateKeys)
80
    chai.expect(ar.indexOf('abe_meta.date')).to.be.above(-1);
81
  });
82
83
  /**
84
   * cmsTemplates.insertDebugtoolUtilities
85
   * 
86
   */
87
  it('cmsTemplates.insertDebugtoolUtilities()', function() {
88
    var txt = cmsTemplates.insertDebugtoolUtilities('</body>');
89
    chai.expect(txt.length).to.above(10);
90
  });
91
92
  /**
93
   * cmsTemplates.encodeAbeTagAsComment
94
   * 
95
   */
96
  it('cmsTemplates.encodeAbeTagAsComment()', function() {
97
    var txt = cmsTemplates.encodeAbeTagAsComment(this.fixture.articleEach);
98
    chai.expect(txt.indexOf('{')).to.equal(-1);
99
  });
100
});
101