From 6bbc682c4b24212d36ef595d3692653dca1c67b1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 25 Apr 2017 22:01:56 +0200 Subject: handle 404 separately Signed-off-by: Georg Ehrke --- core/js/jquery.contactsmenu.js | 11 +++++++++-- core/js/tests/specs/jquery.contactsmenuSpec.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'core/js') diff --git a/core/js/jquery.contactsmenu.js b/core/js/jquery.contactsmenu.js index 84f5a3f9eab..1ea9f732f79 100644 --- a/core/js/jquery.contactsmenu.js +++ b/core/js/jquery.contactsmenu.js @@ -78,13 +78,20 @@ if (actions.length === 0) { } - }, function() { + }, function(jqXHR) { $list.find('ul').find('li').addClass('hidden'); + var title; + if (jqXHR.status === 404) { + title = t('core', 'No action available'); + } else { + title = t('core', 'Error fetching contact actions'); + } + var template = Handlebars.compile(ENTRY); $list.find('ul').append(template({ hyperlink: '#', - title: t('core', 'Error fetching contact actions') + title: title })); }); }); diff --git a/core/js/tests/specs/jquery.contactsmenuSpec.js b/core/js/tests/specs/jquery.contactsmenuSpec.js index b979be8883f..7287648f5a2 100644 --- a/core/js/tests/specs/jquery.contactsmenuSpec.js +++ b/core/js/tests/specs/jquery.contactsmenuSpec.js @@ -184,6 +184,21 @@ describe('jquery.contactsMenu tests', function() { expect($appendTo.html()).toEqual(''); }); + + it('should handle 404', function() { + $('#selector1, #selector2').contactsMenu('user', 0, $appendTo); + $selector1.click(); + + fakeServer.requests[0].respond( + 404, + { 'Content-Type': 'application/json; charset=utf-8' }, + JSON.stringify([]) + ); + expect(fakeServer.requests[0].method).toEqual('POST'); + expect(fakeServer.requests[0].url).toEqual('http://localhost/index.php/contactsmenu/findOne'); + + expect($appendTo.html()).toEqual(''); + }); }); it('click anywhere else to close the menu', function() { -- cgit v1.2.3