| Conditions | 1 |
| Paths | 1 |
| Total Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai'); |
||
| 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'), |
||
| 17 | articleEach: fse.readFileSync(__dirname + '/fixtures/templates/article-each-abe.html', 'utf-8'), |
||
| 18 | templateKeys: fse.readFileSync(__dirname + '/fixtures/templates/article-keys.html', 'utf-8') |
||
| 19 | } |
||
| 20 | done() |
||
| 21 | |||
| 22 | }.bind(this)) |
||
| 23 | }); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * getAbeImport |
||
| 27 | * |
||
| 28 | */ |
||
| 29 | it('cmsTemplate.template.getAbeImport()', function() { |
||
| 30 | var res = cmsTemplate.template.getAbeImport(this.fixture.template) |
||
| 31 | chai.expect(res).to.have.length(4); |
||
| 32 | }); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * includePartials |
||
| 36 | * |
||
| 37 | */ |
||
| 38 | it('cmsTemplate.template.includePartials()', function() { |
||
| 39 | var template = cmsTemplate.template.includePartials(this.fixture.template) |
||
| 40 | chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default'}}"); |
||
| 41 | }); |
||
| 42 | |||
| 43 | /** |
||
| 44 | * cmsTemplate.template.getTemplate |
||
| 45 | * |
||
| 46 | */ |
||
| 47 | it('cmsTemplate.template.getTemplate()', function() { |
||
| 48 | var template = cmsTemplate.template.getTemplate('article') |
||
| 49 | chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default' order='1'}}"); |
||
| 50 | }); |
||
| 51 | |||
| 52 | /** |
||
| 53 | * getTemplate |
||
| 54 | * |
||
| 55 | */ |
||
| 56 | it('cmsTemplate.template.getSelectTemplateKeys()', function() { |
||
| 57 | const pathTemplate = path.join(config.root, config.templates.url) |
||
| 58 | cmsTemplate.template.getSelectTemplateKeys(pathTemplate) |
||
| 59 | .then((whereKeys) => { |
||
| 60 | chai.expect(whereKeys.indexOf('abe_meta.date')).to.be.above(-1); |
||
| 61 | }) |
||
| 62 | }); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * getTemplate |
||
| 66 | * |
||
| 67 | */ |
||
| 68 | it('cmsTemplate.template.execRequestColumns()', function() { // templateKeys |
||
| 69 | const pathTemplate = path.join(config.root, config.templates.url) |
||
| 70 | var ar = cmsTemplate.template.execRequestColumns(this.fixture.templateKeys) |
||
| 71 | chai.expect(ar.indexOf('abe_meta.date')).to.be.above(-1); |
||
| 72 | }); |
||
| 73 | |||
| 74 | /** |
||
| 75 | * cmsTemplate.insertDebugtoolUtilities |
||
| 76 | * |
||
| 77 | */ |
||
| 78 | it('cmsTemplate.insertDebugtoolUtilities()', function() { |
||
| 79 | var txt = cmsTemplate.insertDebugtoolUtilities('</body>'); |
||
| 80 | chai.expect(txt.length).to.above(10); |
||
| 81 | }); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * cmsTemplate.encodeAbeTagAsComment |
||
| 85 | * |
||
| 86 | */ |
||
| 87 | it('cmsTemplate.encodeAbeTagAsComment()', function() { |
||
| 88 | var txt = cmsTemplate.encodeAbeTagAsComment(this.fixture.articleEach); |
||
| 89 | chai.expect(txt.indexOf('{')).to.equal(-1); |
||
| 90 | }); |
||
| 91 | }); |
||
| 92 |