Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/js/dist/login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/login.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/maintenance.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/maintenance.js.map

Large diffs are not rendered by default.

118 changes: 109 additions & 9 deletions core/js/tests/specs/coreSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ describe('Core base tests', function() {
describe('Notifications', function() {
var showSpy;
var showHtmlSpy;
var hideSpy;
var clock;

/**
Expand All @@ -914,13 +913,11 @@ describe('Core base tests', function() {
beforeEach(function() {
clock = sinon.useFakeTimers();
showSpy = sinon.spy(OCP.Toast, 'message');
hideSpy = sinon.spy(OC.Notification, 'hide');

$('#testArea').append('<div id="content"></div>');
});
afterEach(function() {
showSpy.restore();
hideSpy.restore();
// jump past animations
clock.tick(10000);
clock.restore();
Expand All @@ -935,7 +932,7 @@ describe('Core base tests', function() {
//expect(showSpy.firstCall.args[1]).toEqual({isHTML: false, timeout: 7});

var $row = $('#testArea .toastify');
expect($row).toBeDefined();
expect($row.length).toEqual(1);
expect(getNotificationText($row)).toEqual('My notification test');
});
it('shows a HTML notification with default timeout', function() {
Expand All @@ -946,28 +943,46 @@ describe('Core base tests', function() {
expect(showSpy.firstCall.args[1].isHTML).toEqual(true)

var $row = $('#testArea .toastify');
expect($row).toBeDefined();
expect($row.length).toEqual(1);
expect(getNotificationText($row)).toEqual('<a>My notification test</a>');
});
it('hides itself after 7 seconds', function() {
OC.Notification.showTemporary('');

var $row = $('#testArea .toastify');
expect($row).toBeDefined();
expect($row.length).toEqual(1);

// travel in time +7000 milliseconds
clock.tick(7500);

$row = $('#testArea .toastify');
expect($row.length).toEqual(0);
});
it('hides itself after a given time', function() {
OC.Notification.showTemporary('', {timeout: 10});

var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);

// travel in time +7000 milliseconds
clock.tick(7500);

$row = $('#testArea .toastify');
expect($row.length).toEqual(1);

// travel in time another 4000 milliseconds
clock.tick(4000);

$row = $('#testArea .toastify');
expect($row.length).toEqual(0);
});
});
describe('show', function() {
it('hides itself after a given time', function() {
OC.Notification.showTemporary('', {timeout: 10});
OC.Notification.show('', {timeout: 10});

var $row = $('#testArea .toastify');
expect($row).toBeDefined();
expect($row.length).toEqual(1);

clock.tick(11500);

Expand All @@ -977,10 +992,95 @@ describe('Core base tests', function() {
it('does not hide itself if no timeout given to show', function() {
OC.Notification.show('');

var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);

// travel in time +1000 seconds
clock.tick(1000000);

$row = $('#testArea .toastify');
expect($row.length).toEqual(1);
});
});
describe('showHtml', function() {
it('hides itself after a given time', function() {
OC.Notification.showHtml('<p></p>', {timeout: 10});

var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);

clock.tick(11500);

$row = $('#testArea .toastify');
expect($row.length).toEqual(0);
});
it('does not hide itself if no timeout given to show', function() {
OC.Notification.showHtml('<p></p>');

var $row = $('#testArea .toastify');
expect($row.length).toEqual(1);

// travel in time +1000 seconds
clock.tick(1000000);

expect(hideSpy.notCalled).toEqual(true);
$row = $('#testArea .toastify');
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() {
Expand Down
4 changes: 3 additions & 1 deletion core/src/OC/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default {
showHtml: function (html, options) {
options = options || {}
options.isHTML = true
options.timeout = (options.timeout === 0) ? -1 : options.timeout
options.timeout = (!options.timeout) ? -1 : options.timeout
const toast = window.OCP.Toast.message(html, options)
return $(toast.toastElement)
},
Expand All @@ -113,6 +113,8 @@ export default {
* @deprecated 17.0.0 use OCP.Toast
*/
show: function (text, options) {
options = options || {};
options.timeout = (!options.timeout) ? -1 : options.timeout;
const toast = window.OCP.Toast.message(text, options);
return $(toast.toastElement);
},
Expand Down