Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1326)

Issue 6845065: refactored manageUnitsMixin and added tests

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 6 months ago by benji
Modified:
11 years, 6 months ago
Reviewers:
frankban, thiago, mp+135261
Visibility:
Public.

Description

refactored manageUnitsMixin and added tests Full details: - refactored manageUnitsMixin and added tests for it - added documentation for manageUnitsMixin - reconsidered our object literal style, updated the style guide to reflect my current notions, and used the style in the code as a proof of concept - captured current naming practice in the style guide (camelCase everywhere) - tweaked all of the tests so the test container element is "display: none" when possible and "visibility: hidden" otherwise - transmuted an "apply" to a slightly simpler "call" https://code.launchpad.net/~benji/juju-gui/bug-1074336/+merge/135261 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 51
Unified diffs Side-by-side diffs Delta from patch set Stats (+293 lines, -58 lines) Patch
A [revision details] View 1 chunk +2 lines, -0 lines 0 comments Download
M app/store/env.js View 1 chunk +1 line, -1 line 0 comments Download
M app/views/service.js View 3 chunks +91 lines, -34 lines 15 comments Download
M docs/style-guide.rst View 4 chunks +42 lines, -13 lines 8 comments Download
M test/index.html View 1 chunk +1 line, -0 lines 0 comments Download
M test/test_app.js View 2 chunks +7 lines, -2 lines 7 comments Download
M test/test_application_notifications.js View 1 chunk +1 line, -1 line 2 comments Download
M test/test_charm_collection_view.js View 1 chunk +1 line, -1 line 2 comments Download
M test/test_charm_view.js View 1 chunk +1 line, -1 line 1 comment Download
M test/test_environment_view.js View 1 chunk +3 lines, -1 line 1 comment Download
A test/test_manageUnitsMixin.js View 1 chunk +142 lines, -0 lines 13 comments Download
M test/test_service_view.js View 1 chunk +1 line, -1 line 1 comment Download
M undocumented View 2 chunks +0 lines, -3 lines 1 comment Download

Messages

Total messages: 4
benji
Please take a look.
11 years, 6 months ago (2012-11-20 22:03:58 UTC) #1
frankban
The code is easy to follow and everything looks very readable Benji, thank you! I ...
11 years, 6 months ago (2012-11-21 11:26:13 UTC) #2
thiago
Hi Benji, thanks for the improvement. I love the multiple "var" declarations... and Douglas Crockford ...
11 years, 6 months ago (2012-11-21 13:42:24 UTC) #3
benji
11 years, 6 months ago (2012-11-21 17:56:41 UTC) #4
Thanks to Francesco and Thiago for the good reviews.  I have addressed (almost)
everything brought up.  The only unaddressed things were minor misunderstandings
(I hope).

https://codereview.appspot.com/6845065/diff/1/app/views/service.js
File app/views/service.js (right):

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode48
app/views/service.js:48: * @param {Number} keyCode The key that was pressed.
On 2012/11/21 11:26:14, francesco.banconi wrote:
> The parameter fieldValue should be documented here.

Good catch.  I have fixed this and added a slack card to extend the yuidoc
linter to check for this.

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode56
app/views/service.js:56: var numberRegex = /^\d+$/;
On 2012/11/21 11:26:14, francesco.banconi wrote:
> Thanks for defining the regex so that humans can understand what's going on.

I really wanted to this:

var isNumber = /^\d+$/.test;
if (isNumber(fieldValue)) {
...

But because of Javascript's infernal binding rules that isn't possible without
an intermediate variable, making the current version preferable.

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode58
app/views/service.js:58: this._modifyUnits(parseInt(fieldValue, 10));
On 2012/11/21 13:42:24, thiago wrote:
> I've found a YUI utility for it.
> 
> http://yuilibrary.com/yui/docs/api/classes/Number.html
> 
> "parse"

What are the benefits of using YUI for this?

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode76
app/views/service.js:76: var field = this._getInputBox();
On 2012/11/21 13:42:24, thiago wrote:
> This feature is not working. I cannot change the field value. If you change
this
> method to...
> 
>     handleKeyEvent: function(ev) {
>       if (ev.keyCode !== ESC && ev.keyCode !== ENTER) {
>         return;
>       }
>       
>       var field = this._getInputBox();
>       ev.halt(true);
>       this._handleKeyPress(ev.keyCode, field.get('value'));
>     },
> 
> ... it starts working again. I think it is something related to the
> "field.get('value')" method call. 

I see what happened, I misunderstood the meaning of the argument to halt().  I
have fixed this.

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode91
app/views/service.js:91: env = this.get('env'),
On 2012/11/21 13:42:24, thiago wrote:
> env never used?

Nope, fixed.

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode92
app/views/service.js:92: db = this.get('db');
On 2012/11/21 11:26:14, francesco.banconi wrote:
> db does not seem used by this method.

Fixed.

https://codereview.appspot.com/6845065/diff/1/app/views/service.js#newcode111
app/views/service.js:111: * @param {Function} getUnits A function that returns
all the units for a
On 2012/11/21 11:26:14, francesco.banconi wrote:
> These callable parameters are not passed to the method: they seem to be still
> called as env methods.

Indeed.  I got excited about removing some this.get()s but Javascript binding
rules thwarted me.  Fixed.

https://codereview.appspot.com/6845065/diff/1/docs/style-guide.rst
File docs/style-guide.rst (right):

https://codereview.appspot.com/6845065/diff/1/docs/style-guide.rst#newcode63
docs/style-guide.rst:63: equals sign (e.g., "var foo = {"
On 2012/11/21 11:26:14, francesco.banconi wrote:
> Missing closing bracket.

Too many brackets I guess. :)  Fixed.

https://codereview.appspot.com/6845065/diff/1/docs/style-guide.rst#newcode87
docs/style-guide.rst:87: int_bad: 'nope!'},
On 2012/11/21 11:26:14, francesco.banconi wrote:
> This example seems to contradict the rules above.
> There is multiple var definition (separated by commas), and the old object
> literal style.

Indeed, it was left from the old style.  I fixed it.

I'm still not happy that object literal brace indents are different from
function brace indents, but reconciling them would seem to be uncommon,
style-wise.

https://codereview.appspot.com/6845065/diff/1/test/test_app.js
File test/test_app.js (right):

https://codereview.appspot.com/6845065/diff/1/test/test_app.js#newcode138
test/test_app.js:138: container.hide();
On 2012/11/21 11:26:14, francesco.banconi wrote:
> Isn't the container already hidden by the line above?

Heh, yep.  That was left over from an earlier revision.  Fixed.

https://codereview.appspot.com/6845065/diff/1/test/test_app.js#newcode138
test/test_app.js:138: container.hide();
On 2012/11/21 13:42:24, thiago wrote:
> In other test files we simply remove the elements from the DOM. Probably you
> could do the same.

I don't see that in the other tests.  Maybe I am missing something.

https://codereview.appspot.com/6845065/diff/1/test/test_app.js#newcode199
test/test_app.js:199: container = Y.Node.create('<div/>')
On 2012/11/21 13:42:24, thiago wrote:
> Why? We already remove it from the dom after every test.

I don't understand the question.  If it is "Why are we hiding the test
container?" then the reason is that it stops the test page flicker.  I may be
the only one bothered by it, but the cure seems cheap enough.

https://codereview.appspot.com/6845065/diff/1/test/test_application_notificat...
File test/test_application_notifications.js (right):

https://codereview.appspot.com/6845065/diff/1/test/test_application_notificat...
test/test_application_notifications.js:42: applicationContainer =
Y.Node.create('<div/>').hide();
On 2012/11/21 13:42:24, thiago wrote:
> Why? We already remove it from the dom after every test.

See earlier response.

https://codereview.appspot.com/6845065/diff/1/test/test_charm_collection_view.js
File test/test_charm_collection_view.js (right):

https://codereview.appspot.com/6845065/diff/1/test/test_charm_collection_view...
test/test_charm_collection_view.js:108: var container =
Y.Node.create('<div/>').hide();
On 2012/11/21 13:42:24, thiago wrote:
> We already destroy it in this method. I don't think we need to hide it.

See earlier response.

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js
File test/test_manageUnitsMixin.js (right):

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js#n...
test/test_manageUnitsMixin.js:3: (function() {
On 2012/11/21 13:42:24, thiago wrote:
> Why do you wrap everything inside this function? "describe" already does that.

I cribbed this from another test module.  I don't know why they do it that way. 
I am more than happy to remove the outer function if we are reasonably sure it
isn't preforming an important function.

This is one of the reasons less is more: unnecessary code tends to perpetuate
itself.

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js#n...
test/test_manageUnitsMixin.js:20: after(function(done)  {
On 2012/11/21 11:26:14, francesco.banconi wrote:
> Is this required by the testing framework?

Good catch.  This was left from using another test module as a starting point. 
Fixed.

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js#n...
test/test_manageUnitsMixin.js:21: done();
On 2012/11/21 13:42:24, thiago wrote:
> You dont need to call it.
> In fact, you should avoid the use of this magic "done" method.

Indeed!  Fixed.

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js#n...
test/test_manageUnitsMixin.js:25: container = Y.Node.create('<div
id=\"test-container\"/>').hide();
On 2012/11/21 13:42:24, thiago wrote:
> Avoid "done". This is not a async execution.  

Done.

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js#n...
test/test_manageUnitsMixin.js:31: container.remove(true);
On 2012/11/21 13:42:24, thiago wrote:
> If you keep "done", you risk of having a call to an "it" method before the
> previous "it" execution calls the "afterEach" method.

Done.

https://codereview.appspot.com/6845065/diff/1/test/test_manageUnitsMixin.js#n...
test/test_manageUnitsMixin.js:111: it('should reset the unit count a non-number
is entered', function() {
On 2012/11/21 11:26:14, francesco.banconi wrote:
> Missing 'when' in the test description.

I added the missing "when". I really wanted to use more words, but that forced a
line break, which would made the linter require insane indentation for the body
of the function. <sigh>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b