launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04417
[Merge] lp:~benji/launchpad/bug-pre-search-2 into lp:launchpad
Benji York has proposed merging lp:~benji/launchpad/bug-pre-search-2 into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~benji/launchpad/bug-pre-search-2/+merge/69710
This is a branch that began life in Dublin and is finally coming to fruition.
It is common for branch names to include the ID of the bug they address.
When so, we have the opportunity to help the user by initiating a search
for the current bug ID as soon as they click the "Link a related branch"
link.
This branch adds a simple event subscriber that kicks off a search for
the current bug ID when the user opens the "Link a related branch"
overlay. A "Loading suggestions..." message is displayed below the
search box but otherwise the form is unchanged and is ready for the
user's search string.
Huw has given his approval to the UI bits.
The tests can be run by loading them in a browser:
lib/lp/bugs/javascript/tests/test_pre_search.html
The lint report is clean.
--
https://code.launchpad.net/~benji/launchpad/bug-pre-search-2/+merge/69710
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/bug-pre-search-2 into lp:launchpad.
=== modified file 'lib/lp/bugs/javascript/bugtask_index.js'
--- lib/lp/bugs/javascript/bugtask_index.js 2011-07-27 00:01:47 +0000
+++ lib/lp/bugs/javascript/bugtask_index.js 2011-07-28 19:42:32 +0000
@@ -428,6 +428,28 @@
lp_bug_entry.lp_save(config);
};
+
+/**
+ * Do a preemptive search for branches that contain the current bug's ID.
+ */
+function do_pre_search(picker, bug_id) {
+ if (!Y.Lang.isValue(bug_id)) {
+ bug_id = LP.cache.bug.id;
+ }
+ picker.set('footer_slot', 'Loading suggestions...');
+ // A very few bugs have small IDs.
+ var original_min_search_chars = picker.get('min_search_chars');
+ picker.set('min_search_chars', 0);
+ picker.fire('search', bug_id.toString());
+ // Don't disable the search input box or the search button while
+ // doing our search.
+ picker.set('search_mode', false);
+ picker.set('min_search_chars', original_min_search_chars);
+}
+// Expose to the namespace for testing.
+namespace._do_pre_search = do_pre_search;
+
+
/**
* Set up the link-a-related-branch picker.
*/
@@ -469,6 +491,11 @@
config.save = get_branch_and_link_to_bug;
var picker = Y.lp.app.picker.create('Branch', config);
+ // When the user clicks on "Link a related branch" do a search for
+ // branches that contain the bug number.
+ link_branch_link.subscribe('click', function (e) {
+ do_pre_search(picker);
+ });
}
}
=== added file 'lib/lp/bugs/javascript/tests/test_pre_search.html'
--- lib/lp/bugs/javascript/tests/test_pre_search.html 1970-01-01 00:00:00 +0000
+++ lib/lp/bugs/javascript/tests/test_pre_search.html 2011-07-28 19:42:32 +0000
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+ <head>
+ <title>Status Editor</title>
+
+ <!-- YUI and test setup -->
+ <script type="text/javascript"
+ src="../../../../canonical/launchpad/icing/yui/yui/yui.js">
+ </script>
+ <link rel="stylesheet" href="../../../app/javascript/testing/test.css" />
+ <script type="text/javascript"
+ src="../../../app/javascript/testing/testrunner.js"></script>
+
+ <!-- Dependency -->
+ <script type="text/javascript"
+ src="../../../../canonical/launchpad/icing/yui/attribute/attribute.js">
+ </script>
+ <script type="text/javascript"
+ src="../../../../canonical/launchpad/icing/yui/event-custom/event-custom.js">
+ </script>
+ <script type="text/javascript"
+ src="../../../../canonical/launchpad/icing/yui/oop/oop.js">
+ </script>
+ <script type="text/javascript"
+ src="../../../app/javascript/overlay/overlay.js">
+ </script>
+ <script type="text/javascript"
+ src="../../../app/javascript/choiceedit/choiceedit.js">
+ </script>
+ <script type="text/javascript"
+ src="../../../app/javascript/client.js"></script>
+
+ <!-- The module under test -->
+ <script type="text/javascript" src="../bugtask_index.js"></script>
+
+ <!-- The test suite -->
+ <script type="text/javascript" src="test_pre_search.js"></script>
+
+ <!-- Test layout -->
+ <link rel="stylesheet"
+ href="../../../../canonical/launchpad/javascript/test.css" />
+ <style type="text/css">
+ /* CSS classes specific to this test */
+ .unseen { display: none; }
+ </style>
+</head>
+<body class="yui3-skin-sam">
+</body>
+</html>
=== added file 'lib/lp/bugs/javascript/tests/test_pre_search.js'
--- lib/lp/bugs/javascript/tests/test_pre_search.js 1970-01-01 00:00:00 +0000
+++ lib/lp/bugs/javascript/tests/test_pre_search.js 2011-07-28 19:42:32 +0000
@@ -0,0 +1,106 @@
+/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */
+
+YUI({
+ base: '../../../../canonical/launchpad/icing/yui/',
+ filter: 'raw',
+ combine: false,
+ fetchCSS: false
+ }).use('event', 'lp.bugs.bugtask_index', 'lp.client', 'node',
+ 'test', 'widget-stack', 'console', function(Y) {
+
+// Local aliases
+var Assert = Y.Assert,
+ ArrayAssert = Y.ArrayAssert;
+
+// A picker implementation that records method calls for testing.
+function FauxPicker() {
+ this.events = [];
+}
+
+FauxPicker.prototype.get = function(name) {
+ this.events.push('get ' + name);
+ return 47;
+};
+
+FauxPicker.prototype.set = function(name, value) {
+ this.events.push('set ' + name + ' = ' + value);
+};
+
+FauxPicker.prototype.fire = function(name, value) {
+ this.events.push('fire ' + name + ' with ' + value);
+};
+
+
+var suite = new Y.Test.Suite("Link a related branch preemptive search.");
+var module = Y.lp.bugs.bugtask_index;
+
+suite.add(new Y.Test.Case({
+
+ name: 'pre_search',
+
+ setUp: function() {
+ },
+
+ tearDown: function() {
+ },
+
+ /**
+ * A loading message is added to the footer slot.
+ */
+ test_loading_message: function() {
+ picker = new FauxPicker();
+ module._do_pre_search(picker, 'BUG-ID');
+ ArrayAssert.contains(
+ 'set footer_slot = Loading suggestions...',
+ picker.events);
+ },
+
+ /**
+ * Because some bug numbers are short strings, the minimum search
+ * character limit has to be set to zero and then reset to its original
+ * value.
+ */
+ test_min_search_length: function() {
+ picker = new FauxPicker();
+ module._do_pre_search(picker, 'BUG-ID');
+ ArrayAssert.contains(
+ 'get min_search_chars',
+ picker.events);
+ ArrayAssert.contains(
+ 'set min_search_chars = 47',
+ picker.events);
+ },
+
+ /**
+ * After the search event is fired, search_mode has to be (immediately)
+ * disbled so the user can enter a search.
+ */
+ test_disable_search_mode: function() {
+ picker = new FauxPicker();
+ module._do_pre_search(picker, 'BUG-ID');
+ ArrayAssert.contains(
+ 'fire search with BUG-ID',
+ picker.events);
+ ArrayAssert.contains(
+ 'set search_mode = false',
+ picker.events);
+ }
+
+}));
+
+var handle_complete = function(data) {
+ window.status = '::::' + JSON.stringify(data);
+ };
+Y.Test.Runner.on('complete', handle_complete);
+Y.Test.Runner.add(suite);
+
+var yconsole = new Y.Console({
+ newestOnTop: false
+});
+yconsole.render('#log');
+
+Y.on('domready', function() {
+ Y.Test.Runner.run();
+});
+
+});