From a42f0023dc76052f268ad5493537b4b3403b3fa5 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 7 Jun 2017 13:44:02 -0400 Subject: [PATCH] Make tests work under multiple notifications --- gratipay/testing/browser.py | 29 ++++++++++++++++++----------- js/gratipay/packages.js | 11 ++++------- tests/ttw/test_package_claiming.py | 4 ++-- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/gratipay/testing/browser.py b/gratipay/testing/browser.py index ae4da4c434..fbcab08803 100644 --- a/gratipay/testing/browser.py +++ b/gratipay/testing/browser.py @@ -113,27 +113,34 @@ def wait_for(self, selector, timeout=2): return element raise NeverShowedUp(selector) - def wait_for_notification(self, type='notice'): - """Wait for a certain ``type`` of notification. Dismiss the - notification and return the message. + def wait_for_notification(self, type='notice', message=None, timeout=2): + """Wait for a certain ``type`` of notification, with a certain message + (if specified). Dismiss the notification and return the message. """ notification_selector = '.notifications-fixed .notification-{}'.format(type) close_button_selector = 'span.btn-close' - notification = self.wait_for(notification_selector).first - message = notification.find_by_css('div').html + end_time = time.time() + timeout + while time.time() < end_time: + notification = self.wait_for(notification_selector, timeout).first + candidate = notification.find_by_css('div').html + if message is None or message == candidate: + message = candidate + break notification.find_by_css(close_button_selector).first.click() self.wait_to_disappear('#{} {}'.format(notification['id'], close_button_selector)) return message - def wait_for_success(self): - """Wait for a success notification. Dismiss it and return the message. + def wait_for_success(self, message=None): + """Wait for a success notification, with a certain message (if + specified). Dismiss it and return the message. """ - return self.wait_for_notification('success') + return self.wait_for_notification('success', message) - def wait_for_error(self): - """Wait for an error notification. Dismiss it and return the message. + def wait_for_error(self, message=None): + """Wait for an error notification, with a certain message (if + specified). Dismiss it and return the message. """ - return self.wait_for_notification('error') + return self.wait_for_notification('error', message) def __getattr__(self, name): try: diff --git a/js/gratipay/packages.js b/js/gratipay/packages.js index 938ddc9cd1..cb47b88453 100644 --- a/js/gratipay/packages.js +++ b/js/gratipay/packages.js @@ -12,17 +12,14 @@ Gratipay.packages.initSingle = function() { Gratipay.packages.postBulk = function(e) { e.preventDefault(); - var pkg, email, package_id, emails=[], package_ids_by_email={}; + var pkg, email, package_id, package_ids_by_email={}; $('table.listing td.item ').not('.disabled').each(function() { pkg = $(this).data(); - if (package_ids_by_email[pkg.email] === undefined) { - emails.push(pkg.email); + if (package_ids_by_email[pkg.email] === undefined) package_ids_by_email[pkg.email] = []; - } package_ids_by_email[pkg.email].push(pkg.packageId); }); - emails.sort(); - for (var i=0, email; email = emails[i]; i++) + for (email in package_ids_by_email) Gratipay.packages.post(email, package_ids_by_email[email], true); }; @@ -36,7 +33,7 @@ Gratipay.packages.postOne = function(e) { Gratipay.packages.post = function(email, package_ids, show_email) { var action = 'start-verification'; - var $button = $('.important-button button') + var $button = $('button.apply') $button.prop('disabled', true); function reenable() { $button.prop('disabled', false); } diff --git a/tests/ttw/test_package_claiming.py b/tests/ttw/test_package_claiming.py index eb679d28ea..14501bd7a1 100644 --- a/tests/ttw/test_package_claiming.py +++ b/tests/ttw/test_package_claiming.py @@ -211,8 +211,8 @@ def test_sends_one_mail_per_address(self): self.add_and_verify_email(cat, 'bob@example.com') self.visit_as('cat') self.css('.important-button button').click() - assert self.wait_for_success() == 'Check bob@example.com for a verification link.' - assert self.wait_for_success() == 'Check cat@example.com for a verification link.' + assert self.wait_for_success('Check bob@example.com for a verification link.') + assert self.wait_for_success('Check cat@example.com for a verification link.') def test_sends_one_mail_for_multiple_packages(self): self.make_participant('alice', claimed_time='now', email_address='alice@example.com')