aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2019-07-26 18:00:07 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2019-07-26 18:46:59 +0200
commit03f2e8a10e7c900b7a66683798309010a9428b16 (patch)
tree5d0712b5be99cb50d1035b3bc10c8fe27a70b1ef /core/js/tests
parent14006b548ec76a351c2adfeb27cc2aebaf8cf7dc (diff)
downloadnextcloud-server-03f2e8a10e7c900b7a66683798309010a9428b16.tar.gz
nextcloud-server-03f2e8a10e7c900b7a66683798309010a9428b16.zip
Fix default timeouts in OC.Notification
When no timeout was given "show()" used the default timeout of "OCP.Toast", which is 7 seconds instead of indefinitely as stated in the documentation of "show()". "showHtml()" should also indefinitely show the notification if no timeout is given, but due to the strict comparison the notification was indefinitely shown only when a timeout of 0 was explicitly given. Now both methods show the notification indefinitely (or until it is explicitly hidden) when no timeout is given. The unit tests did not catch this error because "showHtml()" had no tests (as before the move to Toastify it was called from "show()" and thus implicitly tested), and because "show()" verified that "hide()" was not called after some time; "hide()" is no longer called from "show()" since "OCP.Toast" is used internally, so the test always passed even if the notification was indeed hidden. Now the test is based on whether the element is found or not, and explicit tests were added too for "showHtml()". Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'core/js/tests')
-rw-r--r--core/js/tests/specs/coreSpec.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 4a8e8f4f657..e4247c51e10 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -897,7 +897,6 @@ describe('Core base tests', function() {
describe('Notifications', function() {
var showSpy;
var showHtmlSpy;
- var hideSpy;
var clock;
/**
@@ -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();
@@ -995,10 +992,39 @@ 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);
- expect(hideSpy.notCalled).toEqual(true);
+ $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);
+
+ $row = $('#testArea .toastify');
+ expect($row.length).toEqual(1);
});
});
it('cumulates several notifications', function() {