Skip to content

Commit

Permalink
handle 404 separately
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <[email protected]>
  • Loading branch information
georgehrke committed Apr 26, 2017
1 parent 99b201a commit 6bbc682
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/js/jquery.contactsmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));
});
});
Expand Down
15 changes: 15 additions & 0 deletions core/js/tests/specs/jquery.contactsmenuSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ describe('jquery.contactsMenu tests', function() {

expect($appendTo.html()).toEqual('<div class="menu popovermenu bubble contactsmenu-popover loaded" style="display: block;"> <ul> <li class="hidden"> <a> <span class="icon-loading-small"></span> </a> </li> <li> <a href="#"> <span>Error fetching contact actions</span> </a></li></ul></div>');
});

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('<div class="menu popovermenu bubble contactsmenu-popover loaded" style="display: block;"> <ul> <li class="hidden"> <a> <span class="icon-loading-small"></span> </a> </li> <li> <a href="#"> <span>No action available</span> </a></li></ul></div>');
});
});

it('click anywhere else to close the menu', function() {
Expand Down

0 comments on commit 6bbc682

Please sign in to comment.