[Libreoffice-commits] .: bug/bug

Loic Dachary loic at kemper.freedesktop.org
Thu Sep 22 03:11:54 PDT 2011


 bug/bug/bug.js  |   22 ++++++++++++++--------
 bug/bug/test.js |   35 +++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 24 deletions(-)

New commits:
commit 38a1d38130f3006af9712d58a64f6b7bb7ea46a4
Author: Loic Dachary <loic at dachary.org>
Date:   Thu Sep 22 12:11:49 2011 +0200

    The HTML returned by the submit needs more than one regexp to detect the errors. The lookup_result function now accepts a list of error regexps

diff --git a/bug/bug/bug.js b/bug/bug/bug.js
index 684ccde..0940d31 100644
--- a/bug/bug/bug.js
+++ b/bug/bug/bug.js
@@ -40,8 +40,14 @@
             });
         },
 
-        lookup_result: function(data, error_regexp, success_regexp) {
-            var error = data.match(error_regexp);
+        lookup_result: function(data, error_regexps, success_regexp) {
+            var error = null;
+            for(var i = 0; i < error_regexps.length; i++) {
+                error = data.match(error_regexps[i]);
+                if(error !== null) {
+                    break;
+                }
+            }
             if(error !== null) {
                 $.bug.error_set(error[1]);
                 throw error;
@@ -70,7 +76,7 @@
             $('.error-container').show();
         },
 
-        state_signin_error_regexp: 'class="throw_error">([^<]*)',
+        state_signin_error_regexps: ['class="throw_error">([^<]*)'],
         state_signin_success_regexp: 'Log&nbsp;out</a>([^<]*)',
 
         state_signin: function() {
@@ -84,7 +90,7 @@
                 }).pipe(function(data) {
                     $("body").css("cursor", "default");
                     return $.bug.lookup_result(data,
-                                               $.bug.state_signin_error_regexp,
+                                               $.bug.state_signin_error_regexps,
                                                $.bug.state_signin_success_regexp);
                 }).pipe(function(data) {
                     $('.username').html(data);
@@ -165,7 +171,7 @@
             }
         },
 
-        state_submit_error_regexp: 'font size="\\+2">([^<]*)',
+        state_submit_error_regexps: ['class="throw_error">([^<]*)', 'font size="\\+2">([^<]*)'],
         state_submit_success_regexp: 'title>Bug ([0-9]+)',
 
         state_submit: function() {
@@ -192,7 +198,7 @@
                     }).pipe(function(data) {
                         $("body").css("cursor", "default");
                         return $.bug.lookup_result(data,
-                                                   $.bug.state_submit_error_regexp,
+                                                   $.bug.state_submit_error_regexps,
                                                    $.bug.state_submit_success_regexp);
                     }).pipe(function(data) {
                         $('.bug', element).text(data);
@@ -206,7 +212,7 @@
             }
         },
 
-        state_attach_error_regexp: 'class="throw_error">([^<]*)',
+        state_attach_error_regexps: ['class="throw_error">([^<]*)'],
         state_attach_success_regexp: 'Attachment #([0-9]+)',
 
         state_attach: function() {
@@ -215,7 +221,7 @@
             $('.bug', element).val(bug);
             $('form', element).iframePostForm({ complete: function(data) {
                 var attachment = $.bug.lookup_result(data,
-                                                     $.bug.state_attach_error_regexp,
+                                                     $.bug.state_attach_error_regexps,
                                                      $.bug.state_attach_success_regexp);
                 $('img', element).
                     attr('src', '/attachment.cgi?id=' + attachment).
diff --git a/bug/bug/test.js b/bug/bug/test.js
index 86dc7a9..70785f8 100644
--- a/bug/bug/test.js
+++ b/bug/bug/test.js
@@ -54,7 +54,7 @@ test("lookup_result", function() {
 
     // error
     try {
-        $.bug.lookup_result('ERR_' + what + '_OR', error_regexp, success_regexp);
+        $.bug.lookup_result('ERR_' + what + '_OR', [error_regexp], success_regexp);
     } catch(e) {
         equal(e[1], what);
         equal($('.error').text(), what);
@@ -65,7 +65,7 @@ test("lookup_result", function() {
     // output is not as expected
     var bugous = 'BUGOUS OUTPUT';
     try {
-        $.bug.lookup_result(bugous, error_regexp, success_regexp);
+        $.bug.lookup_result(bugous, [error_regexp], success_regexp);
     } catch(ee) {
         equal(ee, bugous);
         ok($('.error').text().indexOf(success_regexp) >= 0, 'error displayed');
@@ -74,7 +74,7 @@ test("lookup_result", function() {
     ok(caught, 'caught exception');
 
     // success
-    equal($.bug.lookup_result('SUC_' + value + '_ESS', error_regexp, success_regexp), value);
+    equal($.bug.lookup_result('SUC_' + value + '_ESS', [error_regexp], success_regexp), value);
 });
 
 test("state_signin", function() {
@@ -201,7 +201,7 @@ test("state_description", function() {
 });
 
 test("state_submit", function() {
-    expect(11);
+    expect(14);
 
     var state_success = $.bug.state_success;
     $.bug.state_success = function() { ok(true, 'state_success'); };
@@ -238,18 +238,21 @@ test("state_submit", function() {
 
     var error = ' ERROR ';
     equal($('.error').text(), '', 'error is not set');
-    $.bug.ajax = function(type, url, data) {
-        return $.Deferred().resolve('<table cellpadding="20">   <tr>    <td bgcolor="#ff0000">      <font size="+2">' + error + '</font>   </td>  </tr> </table>');
-    };
-    var caught = false;
-    try {
-        $('.go', element).click();
-    } catch(e) {
-        equal($('.error').text(), error);
-        equal(e[1], error);
-        caught = true;
-    }
-    ok(caught, 'caught');
+
+    $(['<table cellpadding="20">   <tr>    <td bgcolor="#ff0000">      <font size="+2">' + error + '</font>   </td>  </tr> </table>', 'class="throw_error">' + error + '<']).each(function(index, str) {
+        $.bug.ajax = function(type, url, data) {
+            return $.Deferred().resolve(str);
+        };
+        var caught = false;
+        try {
+            $('.go', element).click();
+        } catch(e) {
+            equal($('.error').text(), error, 'text ' + str);
+            equal(e[1], error, 'catch ' + str);
+            caught = true;
+        }
+        ok(caught, 'caught', str);
+    });
     equal($('.error').text(), error, 'error is set');
     $.bug.ajax = $.ajax;
 


More information about the Libreoffice-commits mailing list