[Libreoffice-commits] .: 3 commits - bug/bug
Loic Dachary
loic at kemper.freedesktop.org
Sat Sep 17 08:24:58 PDT 2011
bug/bug/bug.js | 60 ++++++++++++++++++++++++++------------------------------
bug/bug/test.js | 59 ++++++++++++++++++++++++++++++++++---------------------
2 files changed, 65 insertions(+), 54 deletions(-)
New commits:
commit fb3275c53e3cad3f1ec91bbaac2faa3e1ec838f3
Author: Loic Dachary <loic at dachary.org>
Date: Sat Sep 17 17:07:28 2011 +0200
analyze attach upload results with regexp instead of string lookups
diff --git a/bug/bug/bug.js b/bug/bug/bug.js
index c90adaa..2f6b7f2 100644
--- a/bug/bug/bug.js
+++ b/bug/bug/bug.js
@@ -174,22 +174,18 @@
}
},
- state_attach_error_string: 'class="throw_error">',
- state_attach_success_string: 'Attachment #',
+ state_attach_error_regexp: 'class="throw_error">([^<]*)',
+ state_attach_success_regexp: 'Attachment #([0-9]+)',
state_attach: function() {
var element = $('.state_attach');
var bug = $('.state_submit .bug').text();
$('.bug', element).val(bug);
$('form', element).iframePostForm({ complete: function(data) {
- var error = data.indexOf($.bug.state_attach_error_string);
- if(error >= 0) {
- $('.error').text(data.substring(error + $.bug.state_attach_error_string.length, data.indexOf('<', error)));
- } else {
- var success = data.indexOf($.bug.state_attach_success_string);
- var attachment = data.substring(success + $.bug.state_attach_success_string.length, data.indexOf('<', success));
- $('img', element).attr('src', '/attachment.cgi?id=' + attachment);
- }
+ var attachment = $.bug.lookup_result(data,
+ $.bug.state_attach_error_regexp,
+ $.bug.state_attach_success_regexp);
+ $('img', element).attr('src', '/attachment.cgi?id=' + attachment);
}});
element.show();
},
diff --git a/bug/bug/test.js b/bug/bug/test.js
index 0464471..f8c6c86 100644
--- a/bug/bug/test.js
+++ b/bug/bug/test.js
@@ -263,7 +263,7 @@ test("state_success", function() {
});
test("state_attach", function() {
- expect(6);
+ expect(8);
var bug = '4242';
var data;
@@ -285,12 +285,19 @@ test("state_attach", function() {
equal($('.bug', element).val(), bug);
var error = 'ERROR';
- data = $.bug.state_attach_error_string + error + '<';
- $('form', element).submit();
- equal($('.error').text(), error);
+ data = ' ... class="throw_error">' + error + '<';
+ var caught = false;
+ try {
+ $('form', element).submit();
+ } catch(e) {
+ equal($('.error').text(), error);
+ equal(e[1], error);
+ caught = true;
+ }
+ ok(caught, 'caught');
var attachment = '888';
- data = $.bug.state_attach_success_string + attachment + '<';
+ data = 'Attachment #' + attachment;
$('form', element).submit();
ok($('img', element).attr('src').indexOf(attachment) > 0, 'found attachment ' + attachment);
commit fcc986929c967a0444eeb84c17dbb9823add409c
Author: Loic Dachary <loic at dachary.org>
Date: Sat Sep 17 16:58:15 2011 +0200
analyze submit results with regexp instead of string lookups
diff --git a/bug/bug/bug.js b/bug/bug/bug.js
index 42eb9b3..c90adaa 100644
--- a/bug/bug/bug.js
+++ b/bug/bug/bug.js
@@ -140,8 +140,8 @@
}
},
- state_submit_error_string: 'font size="+2">',
- state_submit_success_string: 'title>Bug ',
+ state_submit_error_regexp: 'font size="\\+2">([^<]*)',
+ state_submit_success_regexp: 'title>Bug ([0-9]+)',
state_submit: function() {
var element = $('.state_submit');
@@ -159,17 +159,14 @@
short_desc: $('.state_subcomponent .active_subcomponent .subcomponent').val() + ': ' + $('.state_description .short').val(),
version: $('.state_version .versions').val(),
comment: $('.state_description .long').val()
- }, function(data) {
- var error = data.indexOf($.bug.state_submit_error_string);
- if(error >= 0) {
- $('.error').text(data.substring(error + $.bug.state_submit_error_string.length, data.indexOf('<', error)));
- } else {
- var success = data.indexOf($.bug.state_submit_success_string);
- var start = success + $.bug.state_submit_success_string.length;
- $('.bug', element).text(data.substring(start, data.indexOf(' ', start)));
- $.bug.state_success();
- $.bug.state_attach();
- }
+ }).pipe(function(data) {
+ return $.bug.lookup_result(data,
+ $.bug.state_submit_error_regexp,
+ $.bug.state_submit_success_regexp);
+ }).pipe(function(data) {
+ $('.bug', element).text(data);
+ $.bug.state_success();
+ $.bug.state_attach();
});
});
element.addClass('initialized');
diff --git a/bug/bug/test.js b/bug/bug/test.js
index 42b654c..0464471 100644
--- a/bug/bug/test.js
+++ b/bug/bug/test.js
@@ -201,7 +201,7 @@ test("state_description", function() {
});
test("state_submit", function() {
- expect(8);
+ expect(11);
var state_success = $.bug.state_success;
$.bug.state_success = function() { ok(true, 'state_success'); };
@@ -217,12 +217,12 @@ test("state_submit", function() {
var version = $('.state_version .versions').val();
var comment = $('.state_description .long').val();
var bug = '40763';
- $.bug.ajax = function(type, url, data, callback) {
+ $.bug.ajax = function(type, url, data) {
if(data.component == component &&
data.short_desc == subcomponent &&
data.comment == comment &&
data.version == version) {
- callback('<title>Bug ' + bug + ' Submitted');
+ return $.Deferred().resolve('<title>Bug ' + bug + ' Submitted');
}
};
$('.go', element).click();
@@ -230,10 +230,18 @@ test("state_submit", function() {
var error = ' ERROR ';
equal($('.error').text(), '', 'error is not set');
- $.bug.ajax = function(type, url, data, callback) {
- callback('<table cellpadding="20"> <tr> <td bgcolor="#ff0000"> <font size="+2">' + error + '</font> </td> </tr> </table>');
+ $.bug.ajax = function(type, url, data) {
+ return $.Deferred().resolve('<table cellpadding="20"> <tr> <td bgcolor="#ff0000"> <font size="+2">' + error + '</font> </td> </tr> </table>');
};
- $('.go', element).click();
+ var caught = false;
+ try {
+ $('.go', element).click();
+ } catch(e) {
+ equal($('.error').text(), error);
+ equal(e[1], error);
+ caught = true;
+ }
+ ok(caught, 'caught');
equal($('.error').text(), error, 'error is set');
$.bug.ajax = $.ajax;
commit 501b66aa51555e85f2d854cb62bbbb3e580119e8
Author: Loic Dachary <loic at dachary.org>
Date: Sat Sep 17 15:05:46 2011 +0200
Change the .get and .post into a single ajax call catching and displaying errors.
diff --git a/bug/bug/bug.js b/bug/bug/bug.js
index daaae32..42eb9b3 100644
--- a/bug/bug/bug.js
+++ b/bug/bug/bug.js
@@ -18,9 +18,14 @@
$.bug = {
- post: function(url, args, callback) {
- return $.post(url, args, callback).pipe(null, function(error) {
- var message = url + ' XHR error. ';
+ ajax: function(type, url, args, callback) {
+ return $.ajax({
+ type: type,
+ url: url,
+ data: args,
+ success: callback
+ }).pipe(null, function(error) {
+ var message = url + '(' + $.param(args) + ') XHR error. ';
if('status' in error) {
message += 'status = ' + error.status + ' ';
}
@@ -35,8 +40,6 @@
});
},
- get: $.get,
-
lookup_result: function(data, error_regexp, success_regexp) {
var error = data.match(error_regexp);
if(error !== null) {
@@ -60,7 +63,7 @@
var element = $('.signin');
$('.go', element).click(function() {
$('.error').empty();
- $.bug.post('/index.cgi', {
+ $.bug.ajax('POST', '/index.cgi', {
Bugzilla_login: $('.user', element).val(),
Bugzilla_password: $('.password', element).val()
}).pipe(function(data) {
@@ -144,7 +147,7 @@
var element = $('.state_submit');
if(!element.hasClass('initialized')) {
$('.go', element).click(function() {
- $.bug.post('/post_bug.cgi', {
+ $.bug.ajax('POST', '/post_bug.cgi', {
product: 'LibreOffice',
bug_status: 'UNCONFIRMED',
rep_platform: 'Other',
@@ -208,7 +211,7 @@
logged_in: function() {
$("body").css("cursor", "progress");
- return $.bug.get('/enter_bug.cgi').pipe(function(data) {
+ return $.bug.ajax('GET', '/enter_bug.cgi').pipe(function(data) {
$("body").css("cursor", "default");
return data.indexOf($.bug.logged_in_false) < 0;
});
@@ -219,7 +222,7 @@
var component = $('.state_component .component').val().replace('_','%20');
var subcomponent = $('.state_subcomponent .subcomponent').val();
var list = '/buglist.cgi?columnlist=short_desc&component=' + component + '&product=LibreOffice&query_format=advanced&short_desc_type=allwordssubstr&ctype=csv&short_desc=' + subcomponent;
- $.bug.get(list, undefined, function(data) {
+ $.bug.ajax('GET', list, undefined, function(data) {
var lines = data.split('\n');
var bug_urls = [];
for(var i = 1; i < lines.length; i++) {
diff --git a/bug/bug/test.js b/bug/bug/test.js
index ca517ed..42b654c 100644
--- a/bug/bug/test.js
+++ b/bug/bug/test.js
@@ -16,14 +16,14 @@
//
module("bug");
-test("post", function() {
+test("ajax", function() {
expect(4);
var status = 404;
var statusText = 'Status text';
var responseText = 'Error text';
- var post = $.post;
- $.post = function(url, args) {
+ var ajax = $.ajax;
+ $.ajax = function(settings) {
return $.Deferred().reject({
status: status,
statusText: statusText,
@@ -32,7 +32,7 @@ test("post", function() {
};
try {
- $.bug.post('DOESNOTEXIST', null);
+ $.bug.ajax('POST', 'DOESNOTEXIST', {});
} catch(e) {
ok($('.error').text().indexOf(status) >= 0, status);
ok($('.error').text().indexOf(statusText) >= 0, statusText);
@@ -40,7 +40,7 @@ test("post", function() {
equal(e.status, status);
}
- $.post = post;
+ $.ajax = ajax;
});
test("lookup_result", function() {
@@ -83,7 +83,7 @@ test("state_signin", function() {
equal($('.signin').css('display'), 'none');
var user = 'gooduser';
var password = 'goodpassword';
- $.bug.post = function(url, data, callback) {
+ $.bug.ajax = function(type, url, data, callback) {
var d = $.Deferred();
if(data.Bugzilla_login == user &&
data.Bugzilla_password == password) {
@@ -113,7 +113,7 @@ test("state_signin", function() {
equal($('.error').text().length, 0, 'no error');
equal($('.username').text(), user);
- $.bug.post = $.post;
+ $.bug.ajax = $.ajax;
$.bug.state_component = state_component;
});
@@ -217,7 +217,7 @@ test("state_submit", function() {
var version = $('.state_version .versions').val();
var comment = $('.state_description .long').val();
var bug = '40763';
- $.bug.post = function(url, data, callback) {
+ $.bug.ajax = function(type, url, data, callback) {
if(data.component == component &&
data.short_desc == subcomponent &&
data.comment == comment &&
@@ -230,12 +230,12 @@ test("state_submit", function() {
var error = ' ERROR ';
equal($('.error').text(), '', 'error is not set');
- $.bug.post = function(url, data, callback) {
+ $.bug.ajax = function(type, url, data, callback) {
callback('<table cellpadding="20"> <tr> <td bgcolor="#ff0000"> <font size="+2">' + error + '</font> </td> </tr> </table>');
};
$('.go', element).click();
equal($('.error').text(), error, 'error is set');
- $.bug.post = $.post;
+ $.bug.ajax = $.ajax;
$.bug.state_success = state_success;
});
@@ -292,19 +292,19 @@ test("state_attach", function() {
test("logged_in", function() {
expect(2);
- $.bug.get = function(url) {
+ $.bug.ajax = function(type, url) {
return $.Deferred().resolve($.bug.logged_in_false);
};
$.bug.logged_in().done(function(status) {
equal(status, false, 'user not logged in');
});
- $.bug.get = function(url) {
+ $.bug.ajax = function(type, url) {
return $.Deferred().resolve('logged in ok');
};
$.bug.logged_in().done(function(status) {
equal(status, true, 'user is logged in');
});
- $.bug.get = $.get;
+ $.bug.ajax = $.ajax;
});
More information about the Libreoffice-commits
mailing list