Conditions | 1 |
Paths | 1 |
Total Lines | 75 |
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'); |
||
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; |
||
|
|||
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 | }); |