Merge lp:~frankban/juju-gui/bug-1081803-tests-mutate-url into lp:juju-gui/experimental

Proposed by Francesco Banconi
Status: Merged
Approved by: Gary Poster
Approved revision: 259
Merged at revision: 258
Proposed branch: lp:~frankban/juju-gui/bug-1081803-tests-mutate-url
Merge into: lp:juju-gui/experimental
Diff against target: 143 lines (+35/-34)
2 files modified
test/test_app.js (+10/-9)
test/test_app_hotkeys.js (+25/-25)
To merge this branch: bzr merge lp:~frankban/juju-gui/bug-1081803-tests-mutate-url
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+135670@code.launchpad.net

Description of the change

Tests mutating URL and not removing test nodes.

One of the hotkeys tests mutated the URL.
Both tests in that test case also failed when run
in isolation, and some variables were unused.

Also fixed tests leaving elements in the DOM:
as a consequence, "Environmenton excellent provider"
was visible at the top of the page after a test run.
Now the container used by those tests is removed
after each test is run. Also removed an XXX saying
that removing the elements in afterEach can be
problematic. I've tried to reproduce the erroneus
behavior described, running the test suite several
times, without success. Anyway, removing in afterEach
what was created in beforeEach is something we do
everywhere in the tests. So, that XXX confused me
a bit, any hint?

To avoid flickering in the test page, I tried to
hide the nodes used by tests where possible.

https://codereview.appspot.com/6856075/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :
Download full text (6.0 KiB)

Reviewers: mp+135670_code.launchpad.net,

Message:
Please take a look.

Description:
Tests mutating URL and not removing test nodes.

One of the hotkeys tests mutated the URL.
Both tests in that test case also failed when run
in isolation, and some variables were unused.

Also fixed tests leaving elements in the DOM:
as a consequence, "Environmenton excellent provider"
was visible at the top of the page after a test run.
Now the container used by those tests is removed
after each test is run. Also removed an XXX saying
that removing the elements in afterEach can be
problematic. I've tried to reproduce the erroneus
behavior described, running the test suite several
times, without success. Anyway, removing in afterEach
what was created in beforeEach is something we do
everywhere in the tests. So, that XXX confused me
a bit, any hint?

To avoid flickering in the test page, I tried to
hide the nodes used by tests where possible.

https://code.launchpad.net/~frankban/juju-gui/bug-1081803-tests-mutate-url/+merge/135670

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6856075/

Affected files:
   A [revision details]
   M test/test_app.js
   M test/test_app_hotkeys.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision:
<email address hidden>

Index: test/test_app.js
=== modified file 'test/test_app.js'
--- test/test_app.js 2012-11-14 14:34:31 +0000
+++ test/test_app.js 2012-11-22 12:20:52 +0000
@@ -41,13 +41,6 @@
    });

    beforeEach(function(done) {
- // XXX Apparently removing a DOM node is asynchronous (on Chrome at
least)
- // and we occasionally lose the race if this code is in the afterEach
- // function, so instead we do it here, but only if one has previously
been
- // created.
- if (container) {
- container.remove(true);
- }
      container = Y.one('#main')
        .appendChild(Y.Node.create('<div/>'))
          .set('id', 'test-container')
@@ -55,7 +48,8 @@
          .append(Y.Node.create('<span/>')
            .set('id', 'environment-name'))
          .append(Y.Node.create('<span/>')
- .set('id', 'provider-type'));
+ .set('id', 'provider-type'))
+ .hide();
      app = new Y.juju.App(
          { container: container,
            viewContainer: container});
@@ -63,6 +57,10 @@
      done();
    });

+ afterEach(function() {
+ container.remove(true);
+ });
+
    it('should produce a valid index', function() {
      var container = app.get('container');
      app.render();
@@ -114,14 +112,13 @@
    it('should show the provider type, when available', function() {
      var providerType = 'excellent provider';
      // Since no provider type has been set yet, none is displayed.
- assert.equal(
- container.one('#provider-type').get('text'),
- '');
+ assert.equal('', container.one('#provider-type').get('text'));
      app.env.set('providerType', providerTy...

Read more...

Revision history for this message
Nicola Larosa (teknico) wrote :

Nice cleanup, just a couple minor comments inline.

https://codereview.appspot.com/6856075/diff/1/test/test_app.js
File test/test_app.js (left):

https://codereview.appspot.com/6856075/diff/1/test/test_app.js#oldcode50
test/test_app.js:50: }
I'm a bit concerned about this: I wonder what exactly "losing the race"
means. It might warrant further investigation.

https://codereview.appspot.com/6856075/diff/1/test/test_app_hotkeys.js
File test/test_app_hotkeys.js (right):

https://codereview.appspot.com/6856075/diff/1/test/test_app_hotkeys.js#newcode41
test/test_app_hotkeys.js:41: keyCode: 83, // "S" key.
Is the additional space before the "S" useful?

https://codereview.appspot.com/6856075/diff/1/test/test_app_hotkeys.js#newcode58
test/test_app_hotkeys.js:58: keyCode: 69, // "E" key.
Same comment as line 41 above.

https://codereview.appspot.com/6856075/

259. By Francesco Banconi

Clean up white spaces.

Revision history for this message
Francesco Banconi (frankban) wrote :

Thanks for the review Nicola.

On 2012/11/22 15:06:01, teknico wrote:
> Nice cleanup, just a couple minor comments inline.

https://codereview.appspot.com/6856075/diff/1/test/test_app.js#oldcode50
> test/test_app.js:50: }
> I'm a bit concerned about this: I wonder what exactly "losing the
race" means.
> It might warrant further investigation.

Maybe it means a subsequent test tries to create a container before it
is destroyed by the first one, but I'm just guessing. Anyway, as
mentioned, I was not able to reproduce that behavior, and we are doing
the same elsewhere. Also notice that removing the node in beforeEach
means it is not removed at all after the last test of that test case.

> https://codereview.appspot.com/6856075/diff/1/test/test_app_hotkeys.js
> File test/test_app_hotkeys.js (right):

https://codereview.appspot.com/6856075/diff/1/test/test_app_hotkeys.js#newcode41
> test/test_app_hotkeys.js:41: keyCode: 83, // "S" key.
> Is the additional space before the "S" useful?

Absolutely not. And it's also wrong. Removing them.

https://codereview.appspot.com/6856075/

Revision history for this message
Francesco Banconi (frankban) wrote :
Revision history for this message
Gary Poster (gary) wrote :

Really nice cleanups, Francesco. Thank you. Please land it!

Gary

https://codereview.appspot.com/6856075/diff/5001/test/test_app.js
File test/test_app.js (left):

https://codereview.appspot.com/6856075/diff/5001/test/test_app.js#oldcode44
test/test_app.js:44: // XXX Apparently removing a DOM node is
asynchronous (on Chrome at least)
Weird that this comment is not in trunk. Not worrying about it.

I agree that the tests seem reliable on Chrome without this code, so
ripping it out seems fine.

https://codereview.appspot.com/6856075/

260. By Francesco Banconi

Merged trunk and resolved conflicts.

Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Tests mutating URL and not removing test nodes.

One of the hotkeys tests mutated the URL.
Both tests in that test case also failed when run
in isolation, and some variables were unused.

Also fixed tests leaving elements in the DOM:
as a consequence, "Environmenton excellent provider"
was visible at the top of the page after a test run.
Now the container used by those tests is removed
after each test is run. Also removed an XXX saying
that removing the elements in afterEach can be
problematic. I've tried to reproduce the erroneus
behavior described, running the test suite several
times, without success. Anyway, removing in afterEach
what was created in beforeEach is something we do
everywhere in the tests. So, that XXX confused me
a bit, any hint?

To avoid flickering in the test page, I tried to
hide the nodes used by tests where possible.

R=
CC=
https://codereview.appspot.com/6856075

https://codereview.appspot.com/6856075/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/test_app.js'
2--- test/test_app.js 2012-11-23 16:21:32 +0000
3+++ test/test_app.js 2012-11-27 14:27:31 +0000
4@@ -36,9 +36,6 @@
5 var app, container;
6
7 beforeEach(function() {
8- if (container) {
9- container.remove(true);
10- }
11 container = Y.one('#main')
12 .appendChild(Y.Node.create('<div/>'))
13 .set('id', 'test-container')
14@@ -46,13 +43,18 @@
15 .append(Y.Node.create('<span/>')
16 .set('id', 'environment-name'))
17 .append(Y.Node.create('<span/>')
18- .set('id', 'provider-type'));
19+ .set('id', 'provider-type'))
20+ .hide();
21 app = new Y.juju.App(
22 { container: container,
23 viewContainer: container});
24 injectData(app);
25 });
26
27+ afterEach(function() {
28+ container.remove(true);
29+ });
30+
31 it('should produce a valid index', function() {
32 var container = app.get('container');
33 app.render();
34@@ -104,14 +106,13 @@
35 it('should show the provider type, when available', function() {
36 var providerType = 'excellent provider';
37 // Since no provider type has been set yet, none is displayed.
38- assert.equal(
39- container.one('#provider-type').get('text'),
40- '');
41+ assert.equal('', container.one('#provider-type').get('text'));
42 app.env.set('providerType', providerType);
43 // The provider type has been displayed.
44 assert.equal(
45- container.one('#provider-type').get('text'),
46- 'on ' + providerType);
47+ 'on ' + providerType,
48+ container.one('#provider-type').get('text')
49+ );
50 });
51
52 });
53
54=== modified file 'test/test_app_hotkeys.js'
55--- test/test_app_hotkeys.js 2012-11-23 16:21:32 +0000
56+++ test/test_app_hotkeys.js 2012-11-27 14:27:31 +0000
57@@ -3,9 +3,14 @@
58 YUI(GlobalConfig).use(['juju-gui', 'juju-tests-utils', 'node-event-simulate'],
59 function(Y) {
60 describe('application hotkeys', function() {
61- var app, container, env, conn, testUtils, windowNode;
62+ var app, container, windowNode;
63
64- before(function() {
65+ before(function(done) {
66+ var env = {
67+ after: function() {},
68+ get: function() {},
69+ on: function() {}
70+ };
71 windowNode = Y.one(window);
72 app = new Y.juju.App({
73 env: env,
74@@ -13,51 +18,46 @@
75 viewContainer: container
76 });
77 app.activateHotkeys();
78+ done();
79+ });
80+
81+ beforeEach(function() {
82+ container = Y.Node.create('<div/>');
83+ Y.one('#main').append(container);
84+ app.render();
85 });
86
87 afterEach(function() {
88 container.remove(true);
89 });
90
91- beforeEach(function() {
92- container = Y.one('#main').appendChild(Y.Node.create(
93- '<div/>')).set('id', 'test-container').append(
94- Y.Node.create('<input />').set('id', 'charm-search-field'));
95- testUtils = Y.namespace('juju-tests.utils');
96- env = {
97- get: function() {
98- },
99- on: function() {
100- },
101- after: function() {
102- }
103- };
104- });
105-
106 it('should listen for alt-S events', function() {
107- app.render();
108+ var searchInput = Y.Node.create('<input/>');
109+ searchInput.set('id', 'charm-search-field');
110+ container.append(searchInput);
111 windowNode.simulate('keydown', {
112- keyCode: 83, // "S" key
113+ keyCode: 83, // "S" key.
114 altKey: true
115 });
116 // Did charm-search-field get the focus?
117- assert.equal(Y.one('#charm-search-field'),
118- Y.one(document.activeElement));
119+ assert.equal(searchInput, Y.one(document.activeElement));
120 });
121
122 it('should listen for alt-E events', function() {
123 var altEtriggered = false;
124- app.on('navigateTo', function(param) {
125- if (param && param.url === '/') {
126+ app.on('navigateTo', function(ev) {
127+ if (ev && ev.url === '/') {
128 altEtriggered = true;
129 }
130+ // Avoid URL change performed by additional listeners.
131+ ev.stopImmediatePropagation();
132 });
133- app.render();
134 windowNode.simulate('keydown', {
135- keyCode: 69, // "E" key
136+ keyCode: 69, // "E" key.
137 altKey: true
138 });
139 assert.isTrue(altEtriggered);
140 });
141+
142 });
143 });

Subscribers

People subscribed via source and target branches