Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-10-20 18:11:59 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-12-14 21:17:40 +0300
commit173f28a09d4b88e91fe1c2db16f2aab9f171a627 (patch)
tree77a2811a32e2f9917f10ffb52866e5df399fbe0f
parentb19b1379699cf7790a13575f27a05b2f6db14f6a (diff)
Add unit tests for the navigation bar slide gesture
The slide gesture is enabled or disabled depending on the width of the browser window. In order to easily control that width the karma-viewport plugin is now used in the unit tests. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--build/package.json1
-rw-r--r--core/js/tests/specs/coreSpec.js104
-rw-r--r--tests/karma.config.js2
3 files changed, 106 insertions, 1 deletions
diff --git a/build/package.json b/build/package.json
index b078727805d..e6688966693 100644
--- a/build/package.json
+++ b/build/package.json
@@ -22,6 +22,7 @@
"karma-jasmine-sinon": "^1.0.4",
"karma-junit-reporter": "*",
"karma-phantomjs-launcher": "*",
+ "karma-viewport": "^0.4.2",
"phantomjs-prebuilt": "*",
"node-sass": "~4.1.1",
"sinon": "*"
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 9848fb46ffc..0a26a44d599 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -1112,4 +1112,108 @@ describe('Core base tests', function() {
expect(OC._ajaxConnectionLostHandler.calls.count()).toBe(1);
});
});
+ describe('Snapper', function() {
+ var snapConstructorStub;
+ var snapperStub;
+ var clock;
+
+ beforeEach(function() {
+ snapConstructorStub = sinon.stub(window, 'Snap');
+
+ snapperStub = {};
+ snapperStub.enable = sinon.stub();
+ snapperStub.disable = sinon.stub();
+ snapperStub.close = sinon.stub();
+
+ snapConstructorStub.returns(snapperStub);
+
+ clock = sinon.useFakeTimers();
+
+ // _.now could have been set to Date.now before Sinon replaced it
+ // with a fake version, so _.now must be stubbed to ensure that the
+ // fake Date.now will be called instead of the original one.
+ _.now = sinon.stub(_, 'now').callsFake(function() {
+ return new Date().getTime();
+ });
+
+ $('#testArea').append('<div id="app-navigation">The navigation bar</div><div id="app-content">Content</div>');
+ });
+ afterEach(function() {
+ snapConstructorStub.restore();
+
+ clock.restore();
+
+ _.now.restore();
+
+ // Remove the event handler for the resize event added to the window
+ // due to calling window.initCore() when there is an #app-navigation
+ // element.
+ $(window).off('resize');
+
+ viewport.reset();
+ });
+
+ it('is enabled on a narrow screen', function() {
+ viewport.set(480);
+
+ window.initCore();
+
+ expect(snapConstructorStub.calledOnce).toBe(true);
+ expect(snapperStub.enable.calledOnce).toBe(true);
+ expect(snapperStub.disable.called).toBe(false);
+ });
+ it('is disabled on a wide screen', function() {
+ viewport.set(1280);
+
+ window.initCore();
+
+ expect(snapConstructorStub.calledOnce).toBe(true);
+ expect(snapperStub.enable.called).toBe(false);
+ expect(snapperStub.disable.calledOnce).toBe(true);
+ });
+ it('is enabled when resizing to a narrow screen', function() {
+ viewport.set(1280);
+
+ window.initCore();
+
+ expect(snapperStub.enable.called).toBe(false);
+ expect(snapperStub.disable.calledOnce).toBe(true);
+
+ viewport.set(480);
+
+ // Setting the viewport width does not automatically trigger a
+ // resize.
+ $(window).resize();
+
+ // The resize handler is debounced to be executed a few milliseconds
+ // after the resize event.
+ clock.tick(1000);
+
+ expect(snapperStub.enable.calledOnce).toBe(true);
+ expect(snapperStub.disable.calledOnce).toBe(true);
+ });
+ it('is disabled when resizing to a wide screen', function() {
+ viewport.set(480);
+
+ window.initCore();
+
+ expect(snapperStub.enable.calledOnce).toBe(true);
+ expect(snapperStub.disable.called).toBe(false);
+ expect(snapperStub.close.called).toBe(false);
+
+ viewport.set(1280);
+
+ // Setting the viewport width does not automatically trigger a
+ // resize.
+ $(window).resize();
+
+ // The resize handler is debounced to be executed a few milliseconds
+ // after the resize event.
+ clock.tick(1000);
+
+ expect(snapperStub.enable.calledOnce).toBe(true);
+ expect(snapperStub.disable.calledOnce).toBe(true);
+ expect(snapperStub.close.calledOnce).toBe(true);
+ });
+ });
});
diff --git a/tests/karma.config.js b/tests/karma.config.js
index fb613857e91..0254d6a3335 100644
--- a/tests/karma.config.js
+++ b/tests/karma.config.js
@@ -237,7 +237,7 @@ module.exports = function(config) {
basePath: '..',
// frameworks to use
- frameworks: ['jasmine', 'jasmine-sinon'],
+ frameworks: ['jasmine', 'jasmine-sinon', 'viewport'],
// list of files / patterns to load in the browser
files: files,