Code review comment for lp:~thumper/launchpad/daily-ajax

Revision history for this message
Deryck Hodge (deryck) wrote :

Here's a patch that fixes this up some. It:

* ensures there is a spinner during the XHR work
* avoids sleep during the test
* avoids xpath
* always use a timeout on waits.forElement
* doesn't rely on a page reload to confirm data

This should be a pretty stable test now, and it's clearer to read.
It's also a little bit faster than the earlier version on my system
(around 3-4 seconds).

If you have questions ping me about it.

Cheers,
deryck

1=== modified file 'lib/lp/app/javascript/choice.js'
2--- lib/lp/app/javascript/choice.js 2011-02-10 01:57:55 +0000
3+++ lib/lp/app/javascript/choice.js 2011-02-11 16:46:13 +0000
4@@ -14,6 +14,22 @@
5 cfg: {
6 patch: attribute,
7 resource: resource_uri}});
8+ // ChoiceSource makes assumptions about HTML in lazr-js
9+ // that don't hold true here, so we need to do our own
10+ // spinner icon and clear it when finished.
11+ Y.after(function() {
12+ var icon = this.get('editicon');
13+ icon.removeClass('edit');
14+ icon.addClass('update-in-progress-message');
15+ icon.setStyle('position', 'relative');
16+ icon.setStyle('bottom', '2px');
17+ }, widget, '_uiSetWaiting');
18+ Y.after(function() {
19+ var icon = this.get('editicon');
20+ icon.removeClass('update-in-progress-message');
21+ icon.addClass('edit');
22+ icon.setStyle('bottom', '0px');
23+ }, widget, '_uiClearWaiting');
24 widget.render();
25 };
26
27
28=== modified file 'lib/lp/code/windmill/tests/test_recipe_index.py'
29--- lib/lp/code/windmill/tests/test_recipe_index.py 2011-02-11 01:49:55 +0000
30+++ lib/lp/code/windmill/tests/test_recipe_index.py 2011-02-11 18:08:58 +0000
31@@ -1,20 +1,19 @@
32 # Copyright 2011 Canonical Ltd. This software is licensed under the
33 # GNU Affero General Public License version 3 (see the file LICENSE).
34
35-"""Tests for branch statuses."""
36+"""Tests for recipe index pages."""
37
38 __metaclass__ = type
39 __all__ = []
40
41 import transaction
42-import unittest
43-
44+
45+from storm.store import Store
46+
47+from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
48 from lp.code.windmill.testing import CodeWindmillLayer
49 from lp.testing import WindmillTestCase
50-from lp.testing.windmill.constants import (
51- PAGE_LOAD,
52- SLEEP,
53- )
54+from lp.testing.windmill.constants import FOR_ELEMENT
55
56
57 class TestRecipeSetDaily(WindmillTestCase):
58@@ -23,9 +22,6 @@
59 layer = CodeWindmillLayer
60 suite_name = "Recipe daily build flag setting"
61
62- BUILD_DAILY_TEXT = u'//span[@id="edit-build_daily"]/span[@class="value"]'
63- BUILD_DAILY_POPUP = u'//div[contains(@class, "yui3-ichoicelist-content")]'
64-
65 def test_inline_recipe_daily_build(self):
66 eric = self.factory.makePerson(
67 name="eric", displayname="Eric the Viking", password="test",
68@@ -34,15 +30,17 @@
69 transaction.commit()
70
71 client, start_url = self.getClientFor(recipe, user=eric)
72- client.click(xpath=self.BUILD_DAILY_TEXT)
73- client.waits.forElement(xpath=self.BUILD_DAILY_POPUP)
74+ client.click(id=u'edit-build_daily')
75+ client.waits.forElement(
76+ classname=u'yui3-ichoicelist-content', timeout=FOR_ELEMENT)
77 client.click(link=u'Build daily')
78- client.waits.sleep(milliseconds=SLEEP)
79- client.asserts.assertText(
80- xpath=self.BUILD_DAILY_TEXT, validator=u'Build daily')
81+ client.waits.forElement(
82+ jquery=u'("div#edit-build_daily a.editicon.sprite.edit")',
83+ timeout=FOR_ELEMENT)
84+ client.asserts.assertTextIn(
85+ id=u'edit-build_daily', validator=u'Build daily')
86
87- # Reload the page and make sure the change has stuck.
88- client.open(url=start_url)
89- client.waits.forPageLoad(timeout=PAGE_LOAD)
90- client.asserts.assertText(
91- xpath=self.BUILD_DAILY_TEXT, validator=u'Build daily')
92+ transaction.commit()
93+ freshly_fetched_recipe = Store.of(recipe).find(
94+ SourcePackageRecipe, SourcePackageRecipe.id == recipe.id).one()
95+ self.assertTrue(freshly_fetched_recipe.build_daily)

« Back to merge proposal