| Conditions | 1 |
| Paths | 1 |
| Total Lines | 140 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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'); |
||
| 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 | source: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-source.html'), 'utf-8'), |
||
| 28 | each: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each.html'), 'utf-8'), |
||
| 29 | rawHandlebar: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-raw-handlebars.html'), 'utf-8') |
||
| 30 | } |
||
| 31 | done() |
||
| 32 | |||
| 33 | }.bind(this)) |
||
| 34 | }); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * cmsTemplates.template.addAbeDataAttrForHtmlTag |
||
| 38 | * |
||
| 39 | */ |
||
| 40 | it('cmsTemplates.prepare.addAbeDataAttrForHtmlTag()', function() { |
||
| 41 | // stub |
||
| 42 | |||
| 43 | // test |
||
| 44 | var template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.text) |
||
| 45 | chai.expect(template.indexOf('data-abe-')).to.be.above(-1); |
||
| 46 | }); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * cmsTemplates.template.addAbeDataAttrForHtmlAttributes |
||
| 50 | * |
||
| 51 | */ |
||
| 52 | it('cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes()', function() { |
||
| 53 | // stub |
||
| 54 | |||
| 55 | // test |
||
| 56 | var template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attribute) |
||
| 57 | chai.expect(template.indexOf('data-abe-attr-')).to.be.above(-1); |
||
| 58 | }); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * cmsTemplates.template.addAbeSourceComment |
||
| 62 | * |
||
| 63 | */ |
||
| 64 | it('cmsTemplates.prepare.addAbeSourceComment()', function() { |
||
| 65 | // stub |
||
| 66 | |||
| 67 | // test |
||
| 68 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.source, |
||
| 69 | { |
||
| 70 | abe_source: { |
||
| 71 | data_key: [{title: "test"}] |
||
| 72 | } |
||
| 73 | } |
||
| 74 | ) |
||
| 75 | |||
| 76 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
| 77 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
| 78 | }); |
||
| 79 | |||
| 80 | /** |
||
| 81 | * cmsTemplates.template.addAbeHtmlTagBetweenAbeTags |
||
| 82 | * |
||
| 83 | */ |
||
| 84 | it('cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags()', function() { |
||
| 85 | // stub |
||
| 86 | |||
| 87 | // test |
||
| 88 | var template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.text) |
||
| 89 | chai.expect(template.indexOf('<abe>{{')).to.be.above(-1); |
||
| 90 | chai.expect(template.indexOf('}}</abe>')).to.be.above(-1); |
||
| 91 | }); |
||
| 92 | |||
| 93 | /** |
||
| 94 | * cmsTemplates.template.replaceAbeEachIndex |
||
| 95 | * |
||
| 96 | */ |
||
| 97 | it('cmsTemplates.prepare.replaceAbeEachIndex()', function() { |
||
| 98 | // stub |
||
| 99 | |||
| 100 | // test |
||
| 101 | var template = cmsTemplates.prepare.replaceAbeEachIndex('[index].') |
||
| 102 | chai.expect(template).to.be.equal('{{@index}}-'); |
||
| 103 | }); |
||
| 104 | |||
| 105 | /** |
||
| 106 | * cmsTemplates.template.removeHiddenAbeTag |
||
| 107 | * |
||
| 108 | */ |
||
| 109 | it('cmsTemplates.prepare.removeHiddenAbeTag()', function() { |
||
| 110 | // stub |
||
| 111 | |||
| 112 | // test |
||
| 113 | var template = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleFalse) |
||
| 114 | chai.expect(template).to.be.equal(""); |
||
| 115 | |||
| 116 | // test |
||
| 117 | var template2 = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleTrue) |
||
| 118 | chai.expect(template2.indexOf('{{abe')).to.be.above(-1); |
||
| 119 | }); |
||
| 120 | |||
| 121 | /** |
||
| 122 | * cmsTemplates.template.removeHandlebarsRawFromHtml |
||
| 123 | * |
||
| 124 | */ |
||
| 125 | it('cmsTemplates.prepare.removeHandlebarsRawFromHtml()', function() { |
||
| 126 | // stub |
||
| 127 | |||
| 128 | // test |
||
| 129 | var template = cmsTemplates.prepare.removeHandlebarsRawFromHtml(this.fixture.rawHandlebar) |
||
| 130 | chai.expect(template).to.be.equal("test"); |
||
| 131 | }); |
||
| 132 | |||
| 133 | /** |
||
| 134 | * cmsTemplates.template.splitEachBlocks |
||
| 135 | * |
||
| 136 | */ |
||
| 137 | it('cmsTemplates.prepare.splitEachBlocks()', function() { |
||
| 138 | // stub |
||
| 139 | |||
| 140 | // test |
||
| 141 | var blocks = cmsTemplates.prepare.splitEachBlocks(this.fixture.each) |
||
| 142 | chai.expect(blocks.length).to.be.above(0); |
||
| 143 | }); |
||
| 144 | |||
| 145 | /** |
||
| 146 | * cmsTemplates.template.indexEachBlocks |
||
| 147 | * |
||
| 148 | */ |
||
| 149 | it('cmsTemplates.prepare.indexEachBlocks()', function() { |
||
| 150 | // stub |
||
| 151 | |||
| 152 | // test |
||
| 153 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.each, false) |
||
| 154 | chai.expect(template.indexOf('data-abe-block')).to.be.above(-1); |
||
| 155 | chai.expect(template.indexOf('<!-- [[test]]')).to.be.above(-1); |
||
| 156 | }); |
||
| 157 | }); |
||
| 158 |