diff options
Diffstat (limited to 'web-ui')
-rw-r--r-- | web-ui/app/js/helpers/monitored_ajax.js | 2 | ||||
-rw-r--r-- | web-ui/app/js/search/results_highlighter.js | 2 | ||||
-rw-r--r-- | web-ui/test/spec/helpers/monitored_ajax_call.spec.js | 38 | ||||
-rw-r--r-- | web-ui/test/spec/search/results_highlighter.spec.js | 4 | ||||
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 18 |
5 files changed, 43 insertions, 21 deletions
diff --git a/web-ui/app/js/helpers/monitored_ajax.js b/web-ui/app/js/helpers/monitored_ajax.js index d05fdc4c..1cb720de 100644 --- a/web-ui/app/js/helpers/monitored_ajax.js +++ b/web-ui/app/js/helpers/monitored_ajax.js @@ -54,6 +54,8 @@ define(['page/events', 'views/i18n', 'helpers/browser'], function (events, i18n, if (xmlhttprequest.status === 302) { var redirectUrl = xmlhttprequest.getResponseHeader('Location'); browser.redirect(redirectUrl); + }else if (xmlhttprequest.status === 401) { + browser.redirect('/'); } }.bind(this)); diff --git a/web-ui/app/js/search/results_highlighter.js b/web-ui/app/js/search/results_highlighter.js index 2c7d1cc7..9e3ba167 100644 --- a/web-ui/app/js/search/results_highlighter.js +++ b/web-ui/app/js/search/results_highlighter.js @@ -40,7 +40,7 @@ define( var domIdent = data.where; if(this.attr.keywords) { _.each(this.attr.keywords, function (keyword) { - $(domIdent).highlightRegex(new RegExp('\\b' + keyword, 'i'), { + $(domIdent).highlightRegex(new RegExp(keyword, 'i'), { tagType: 'em', className: 'search-highlight' }); diff --git a/web-ui/test/spec/helpers/monitored_ajax_call.spec.js b/web-ui/test/spec/helpers/monitored_ajax_call.spec.js index bf7a2db4..972ca3ae 100644 --- a/web-ui/test/spec/helpers/monitored_ajax_call.spec.js +++ b/web-ui/test/spec/helpers/monitored_ajax_call.spec.js @@ -35,6 +35,44 @@ define(['helpers/monitored_ajax'], function (monitoredAjax) { expect(component.trigger).toHaveBeenCalledWith(document, Pixelated.events.ui.userAlerts.displayMessage, { message: 'Server Message' }); }); + }); + + describe('when user seems to be logged out', function () { + var component, browser; + + beforeEach(function () { + component = { trigger: function () {}}; + browser = require('helpers/browser'); + + }); + + it('will redirect the browser to the location specified', function () { + var redirectUrl = '/some/redirect/url'; + var deferred = $.Deferred(); + spyOn($, 'ajax').and.returnValue(deferred); + var spyRedirect = spyOn(browser, 'redirect').and.returnValue($.Deferred()); + + monitoredAjax(component, '/some/url', {}); + + deferred.reject({status: 302, getResponseHeader: function (_) {return redirectUrl;}}, '', ''); + + expect(spyRedirect).toHaveBeenCalled(); + expect(spyRedirect.calls.mostRecent().args[0]).toEqual(redirectUrl); + }); + + it ('will redirect the browser to root if authentication is required', function () { + var redirectUrl = '/'; + var deferred = $.Deferred(); + spyOn($, 'ajax').and.returnValue(deferred); + var spyRedirect = spyOn(browser, 'redirect').and.returnValue($.Deferred()); + + monitoredAjax(component, '/some/url', {}); + + deferred.reject({status: 401}, '', ''); + + expect(spyRedirect).toHaveBeenCalled(); + expect(spyRedirect.calls.mostRecent().args[0]).toEqual(redirectUrl); + }); }); }); diff --git a/web-ui/test/spec/search/results_highlighter.spec.js b/web-ui/test/spec/search/results_highlighter.spec.js index 523c3599..cfb61e9c 100644 --- a/web-ui/test/spec/search/results_highlighter.spec.js +++ b/web-ui/test/spec/search/results_highlighter.spec.js @@ -1,7 +1,7 @@ describeComponent('search/results_highlighter', function () { 'use strict'; - it('highlights only words that matches with the keywords given', function () { + it('highlights words or parts of words that match with the keywords given', function () { this.setupComponent('<div id="text">Any one seeing too many open bugs</div>'); this.component.attr = {keywords: ['any']}; @@ -9,7 +9,7 @@ describeComponent('search/results_highlighter', function () { var highlightedWords = this.component.$node.find('.search-highlight').length; - expect(highlightedWords).toEqual(1); + expect(highlightedWords).toEqual(2); }); it('resets highlights when a new search is performed', function() { diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js index 2cf69a9d..7fb2bfda 100644 --- a/web-ui/test/spec/services/mail_service.spec.js +++ b/web-ui/test/spec/services/mail_service.spec.js @@ -130,24 +130,6 @@ describeComponent('services/mail_service', function () { expect(spyAjax.calls.mostRecent().args[1].type).toEqual('DELETE'); }); - describe('when request fails', function () { - it ('will redirect the browser to the location specified', function () { - var browser = require('helpers/browser'); - var redirectUrl = '/some/redirect/url'; - var me = {}; - var deferred = $.Deferred(); - spyOn($, 'ajax').and.returnValue(deferred); - var spyRedirect = spyOn(browser, 'redirect').and.returnValue($.Deferred()); - - this.component.trigger(Pixelated.events.mail.want, { caller: me, mail: email1.ident }); - - deferred.reject({status: 302, getResponseHeader: function (_) {return redirectUrl;}}, '', ''); - - expect(spyRedirect).toHaveBeenCalled(); - expect(spyRedirect.calls.mostRecent().args[0]).toEqual(redirectUrl); - }); - }); - describe('when successfuly deletes an email', function () { var displayMessageEvent, uncheckAllEvent, mailsDeletedEvent; |