Add unit tests for "OC.Notification.hide()"

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2019-07-26 18:29:00 +02:00
parent 03f2e8a10e
commit abd5d10253
1 changed files with 56 additions and 0 deletions

View File

@ -1027,6 +1027,62 @@ describe('Core base tests', function() {
expect($row.length).toEqual(1); expect($row.length).toEqual(1);
}); });
}); });
describe('hide', function() {
it('hides a temporary notification before its timeout expires', function() {
var hideCallback = sinon.spy();
var notification = OC.Notification.showTemporary('');
var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);
OC.Notification.hide(notification, hideCallback);
// Give time to the hide animation to finish
clock.tick(1000);
$row = $('#testArea .toastify');
expect($row.length).toEqual(0);
expect(hideCallback.calledOnce).toEqual(true);
});
it('hides a notification before its timeout expires', function() {
var hideCallback = sinon.spy();
var notification = OC.Notification.show('', {timeout: 10});
var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);
OC.Notification.hide(notification, hideCallback);
// Give time to the hide animation to finish
clock.tick(1000);
$row = $('#testArea .toastify');
expect($row.length).toEqual(0);
expect(hideCallback.calledOnce).toEqual(true);
});
it('hides a notification without timeout', function() {
var hideCallback = sinon.spy();
var notification = OC.Notification.show('');
var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);
OC.Notification.hide(notification, hideCallback);
// Give time to the hide animation to finish
clock.tick(1000);
$row = $('#testArea .toastify');
expect($row.length).toEqual(0);
expect(hideCallback.calledOnce).toEqual(true);
});
});
it('cumulates several notifications', function() { it('cumulates several notifications', function() {
var $row1 = OC.Notification.showTemporary('One'); var $row1 = OC.Notification.showTemporary('One');
var $row2 = OC.Notification.showTemporary('Two', {timeout: 2}); var $row2 = OC.Notification.showTemporary('Two', {timeout: 2});