launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #03263
[Merge] lp:~benji/launchpad/fix-ss-test-lint into lp:launchpad
Benji York has proposed merging lp:~benji/launchpad/fix-ss-test-lint into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~benji/launchpad/fix-ss-test-lint/+merge/56974
This branch spruces up the structural subscription JS tests. It fixes several JS lint issues in the structural subscriptions JS tests, adds a small tests that tests part of the structural subscription JS testing infrastructure and does a small refactoring to several places where click events are simulated.
To run the tests visit lib/lp/registry/javascript/tests/test_structural_subscription.html in a browser.
There is no reported lint.
--
https://code.launchpad.net/~benji/launchpad/fix-ss-test-lint/+merge/56974
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/fix-ss-test-lint into lp:launchpad.
=== modified file 'lib/lp/registry/javascript/tests/test_structural_subscription.js'
--- lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-08 14:48:04 +0000
+++ lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-08 15:42:35 +0000
@@ -29,13 +29,16 @@
var target_link_class = '.menu-link-subscribe_to_bug_mail';
function array_compare(a,b) {
- if (a.length != b.length)
+ if (a.length !== b.length) {
return false;
+ }
a.sort();
b.sort();
- for (i in a) {
- if (a[i] != b[i])
+ var i;
+ for (i=0; i<a.length; i++) {
+ if (a[i] !== b[i]) {
return false;
+ }
}
return true;
}
@@ -43,7 +46,7 @@
function create_test_node(include_listing) {
var test_node = Y.Node.create('<div id="test-content">')
.append(Y.Node.create('<div></div>')
- .set('id', content_box_name))
+ .set('id', content_box_name));
if (include_listing) {
test_node.append(Y.Node.create('<div style="width: 50%"></div>')
@@ -62,8 +65,9 @@
var length = list.size();
for (i=0; i < length; i++) {
item = list.item(i);
- if (item.get('checked') != expected)
+ if (item.get('checked') !== expected) {
return false;
+ }
}
return true;
}
@@ -71,7 +75,7 @@
function monkeypatch_LP() {
// Monkeypatch LP to avoid network traffic and to allow
// insertion of test data.
- var original_lp = window.LP
+ var original_lp = window.LP;
window.LP = {
links: {},
cache: {}
@@ -93,9 +97,10 @@
}
function LPClient(){
- if (!(this instanceof arguments.callee))
+ if (!(this instanceof LPClient)) {
throw new Error("Constructor called as a function");
- this.received = []
+ }
+ this.received = [];
// We create new functions every time because we allow them to be
// configured.
this.named_post = function(url, func, config) {
@@ -103,13 +108,15 @@
};
this.patch = function(bug_filter, data, config) {
this._call('patch', config, arguments);
- }
- };
+ };
+ }
+
LPClient.prototype._call = function(name, config, args) {
this.received.push(
[name, Array.prototype.slice.call(args)]);
- if (!Y.Lang.isValue(args.callee.args))
+ if (!Y.Lang.isValue(args.callee.args)) {
throw new Error("Set call_args on "+name);
+ }
if (Y.Lang.isValue(args.callee.fail) && args.callee.fail) {
config.on.failure.apply(undefined, args.callee.args);
} else {
@@ -123,6 +130,23 @@
return new LPClient();
}
+ suite.add(new Y.Test.Case({
+ name: 'Tests for the fake LP client (LPClient) used in these tests.',
+
+ _should: {
+ error: {
+ test_error_when_used_as_a_function: new Error(
+ 'Constructor called as a function')
+ }
+ },
+
+ test_error_when_used_as_a_function: function() {
+ // LPClient has a built-in safety to ensure that it's instantiated
+ // correctly.
+ LPClient();
+ }
+ }));
+
test_case = new Y.Test.Case({
name: 'structural_subscription_overlay',
@@ -358,7 +382,7 @@
// Even if '+', '-' or '.' are allowed in tags,
// they must not be at the beginning of a tag.
this.assertHasErrorInTagsList('tag1 +tag2 -tag3 .tag4');
- },
+ }
});
suite.add(test_case);
@@ -433,8 +457,7 @@
module.setup(this.configuration);
// Simulate a click on the link to open the overlay.
var link = Y.one('.menu-link-subscribe_to_bug_mail');
- Y.Event.simulate(
- Y.Node.getDOMNode(link), 'click');
+ link.simulate('click');
var filter_wrapper = Y.one('#filter-wrapper');
var accordion_wrapper = Y.one('#accordion-wrapper');
Assert.isTrue(filter_wrapper.hasClass('lazr-closed'));
@@ -447,21 +470,19 @@
module.setup(this.configuration);
// Simulate a click on the link to open the overlay.
var link = Y.one('.menu-link-subscribe_to_bug_mail');
- Y.Event.simulate(
- Y.Node.getDOMNode(link), 'click');
+ link.simulate('click');
var added_changed = Y.one('#added-or-changed');
Assert.isFalse(added_changed.get('checked'));
var filter_wrapper = Y.one('#filter-wrapper');
// Initially closed.
Assert.isTrue(filter_wrapper.hasClass('lazr-closed'));
// Opens when selected.
- Y.Event.simulate(Y.Node.getDOMNode(added_changed), 'click');
+ added_changed.simulate('click');
this.wait(function() {
Assert.isTrue(filter_wrapper.hasClass('lazr-opened'));
}, 500);
// Closes when deselected.
- Y.Event.simulate(
- Y.Node.getDOMNode(Y.one('#added-or-closed')), 'click');
+ Y.one('#added-or-closed').simulate('click');
this.wait(function() {
Assert.isTrue(filter_wrapper.hasClass('lazr-closed'));
}, 500);
@@ -473,8 +494,7 @@
module.setup(this.configuration);
// Simulate a click on the link to open the overlay.
var link = Y.one('.menu-link-subscribe_to_bug_mail');
- Y.Event.simulate(
- Y.Node.getDOMNode(link), 'click');
+ link.simulate('click');
var added_changed = Y.one('#added-or-changed');
added_changed.set('checked', true);
@@ -486,12 +506,12 @@
Assert.isTrue(accordion_wrapper.hasClass('lazr-closed'));
}, 500);
// Opens when selected.
- advanced_filter.set('checked') = true;
+ advanced_filter.set('checked', true);
this.wait(function() {
Assert.isTrue(accordion_wrapper.hasClass('lazr-opened'));
}, 500);
// Closes when deselected.
- advanced_filter.set('checked') = false;
+ advanced_filter.set('checked', false);
this.wait(function() {
Assert.isTrue(accordion_wrapper.hasClass('lazr-closed'));
}, 500);
@@ -507,7 +527,7 @@
var select_none = Y.one('#importances-selectors > a.select-none');
Assert.isTrue(test_checked(checkboxes, true));
// Simulate a click on the select_none control.
- Y.Event.simulate(Y.Node.getDOMNode(select_none), 'click');
+ select_none.simulate('click');
Assert.isTrue(test_checked(checkboxes, false));
// Simulate a click on the select_all control.
Y.Event.simulate(Y.Node.getDOMNode(select_all), 'click');
@@ -1097,7 +1117,7 @@
setUp: function() {
this.config = {
content_box: content_box_id
- }
+ };
this.content_box = create_test_node();
Y.one('body').appendChild(this.content_box);
},
@@ -1150,7 +1170,7 @@
module._show_add_overlay = old_show_add_overlay;
Assert.areEqual(test.config, config);
called_method = true;
- }
+ };
module.setup_subscription_link(this.config, "#link");
Y.Event.simulate(Y.Node.getDOMNode(link), 'click');
@@ -1181,7 +1201,7 @@
Y.Node.create('<div id="structural-subscriptions"></div>'));
var form_data = {
- recipient: ["user"],
+ recipient: ["user"]
};
var target_info = {
title: "MY TARGET",
@@ -1227,7 +1247,7 @@
.appendChild('<div id="subscription-filter-0"'+
' class="subscription-filter"></div>');
var form_data = {
- recipient: ["user"],
+ recipient: ["user"]
};
var target_info = {
title: "Subscription target",
@@ -1251,7 +1271,7 @@
2, subs_list.all('div.subscription-filter').size());
this.config.add_filter_description = false;
delete window.LP.cache.target_info;
- },
+ }
}));
// Lock, stock, and two smoking barrels.