From 4a8217744e1d1ca60d158c3497a09b92f857a7fd Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Wed, 18 Feb 2015 13:17:30 -0200 Subject: #294 - using server error message on ajax if message is provided --- .../test/spec/helpers/monitored_ajax_call.spec.js | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 web-ui/test/spec/helpers/monitored_ajax_call.spec.js (limited to 'web-ui/test/spec/helpers') diff --git a/web-ui/test/spec/helpers/monitored_ajax_call.spec.js b/web-ui/test/spec/helpers/monitored_ajax_call.spec.js new file mode 100644 index 00000000..bf7a2db4 --- /dev/null +++ b/web-ui/test/spec/helpers/monitored_ajax_call.spec.js @@ -0,0 +1,41 @@ +define(['helpers/monitored_ajax'], function (monitoredAjax) { + 'use strict'; + describe('monitoredAjaxCall', function () { + describe('when dealing with errors', function () { + + _.each( + { + timeout: 'a timeout occurred', + error: 'problems talking to server', + parseerror: 'got invalid response from server' + }, function (errorMessage, errorType) { + it('shows message for a server ' + errorType, function () { + var component = { trigger: function () {}}; + spyOn(component, 'trigger'); + var d = $.Deferred(); + spyOn($, 'ajax').and.returnValue(d); + + monitoredAjax(component, '/', {}); + d.reject({ responseJSON: {}}, errorType, ''); + + expect(component.trigger).toHaveBeenCalledWith(document, Pixelated.events.ui.userAlerts.displayMessage, + { message: errorMessage }); + }); + }); + + it('shows the error message sent by the server if it exists', function () { + var component = { trigger: function () {}}; + spyOn(component, 'trigger'); + var d = $.Deferred(); + spyOn($, 'ajax').and.returnValue(d); + + monitoredAjax(component, '/', {}); + d.reject({ responseJSON: { message: 'Server Message'}}, 'error', ''); + + expect(component.trigger).toHaveBeenCalledWith(document, Pixelated.events.ui.userAlerts.displayMessage, + { message: 'Server Message' }); + }); + + }); + }); +}); \ No newline at end of file -- cgit v1.2.3