Skip to content

Commit

Permalink
Merge pull request #5110 from FinalAngel/feature/unit-tests/cms-toolbar
Browse files Browse the repository at this point in the history
CMS Toolbar unit tests
  • Loading branch information
vxsx committed Mar 31, 2016
2 parents d030724 + 8b002c0 commit 391f2ec
Show file tree
Hide file tree
Showing 11 changed files with 625 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ install:
script:
- if [ "$FRONTEND" == 1 ] && [ "$UNIT" == 1 ]; then gulp tests:unit; fi;
- if [ "$FRONTEND" == 1 ] && [ "$LINT" == 1 ]; then gulp lint; fi;
- if [ "$FRONTEND" == 1 ] && [ "$INTEGRATION" == 1 ]; then pip install -e .; pip freeze; sh cms/tests/frontend/integration/run_testserver.sh; sleep 45; gulp tests:integration; fi;
- if [ "$FRONTEND" == 1 ] && [ "$INTEGRATION" == 1 ]; then pip install -e .; pip freeze; sh cms/tests/frontend/integration/run_testserver.sh; sleep 60; gulp tests:integration; fi;
- if [ "$FRONTEND" != 1 ]; then coverage run --parallel-mode manage.py test $MIGRATE_OPTION; fi;
- if [ "$FRONTEND" != 1 ]; then coverage combine; fi;

Expand Down
14 changes: 7 additions & 7 deletions cms/static/cms/js/dist/bundle.admin.base.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cms/static/cms/js/dist/bundle.admin.pagetree.min.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions cms/static/cms/js/dist/bundle.toolbar.min.js

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions cms/static/cms/js/modules/cms.toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* @module CMS
*/
/* istanbul ignore next */
var CMS = window.CMS || {};

// #############################################################################
Expand Down Expand Up @@ -60,14 +61,15 @@ var CMS = window.CMS || {};
this.click = 'click.cms.toolbar';
this.touchStart = 'touchstart.cms.toolbar';
this.pointerUp = 'pointerup.cms.toolbar';
this.pointerOverOut = 'pointerover.cms.toolbar pointerout.csm.toolbar';
this.pointerOverOut = 'pointerover.cms.toolbar pointerout.cms.toolbar';
this.pointerLeave = 'pointerleave.csm.toolbar';
this.mouseEnter = 'mouseenter.cms.toolbar';
this.mouseLeave = 'mouseleave.cms.toolbar';
this.resize = 'resize.cms.toolbar';
this.scroll = 'scroll.cms.toolbar';
this.key = 'keydown.cms.toolbar keyup.cms.toolbar';

// istanbul ignore next: function is always reassigned
this.timer = function () {};
this.lockToolbar = false;

Expand Down Expand Up @@ -153,11 +155,12 @@ var CMS = window.CMS || {};
that.ui.document.off(that.click);
that.ui.toolbar.off(that.click, reset);
that.ui.structureBoard.off(that.click);
that.ui.window.off(that.resize + '.menu.reset');
that._handleLongMenus();
}

// remove events from first level
navigation.find('a').on(that.click + ', ' + that.key, function (e) {
navigation.find('a').on(that.click + ' ' + that.key, function (e) {
var el = $(this);
// we need to restore the default behaviour once a user
// presses ctrl/cmd and clicks on the entry. In this
Expand All @@ -182,7 +185,7 @@ var CMS = window.CMS || {};

if (cmdPressed) {
// control the behaviour when ctrl/cmd is pressed
window.open(el.attr('href'), '_blank');
CMS.API.Helpers._getWindow().open(el.attr('href'), '_blank');
} else {
// otherwise delegate as usual
that._delegate($(this));
Expand Down Expand Up @@ -239,7 +242,7 @@ var CMS = window.CMS || {};
that.ui.document.on(that.click, reset);
that.ui.structureBoard.on(that.click, reset);
that.ui.toolbar.on(that.click, reset);
that.ui.window.on('resize', CMS.API.Helpers.throttle(reset, 1000));
that.ui.window.on(that.resize + '.menu.reset', CMS.API.Helpers.throttle(reset, 1000));
// update states
open = true;
});
Expand Down Expand Up @@ -324,7 +327,7 @@ var CMS = window.CMS || {};
},
'success': function () {
var url = CMS.API.Helpers.makeURL(
window.location.href.split('?')[0],
CMS.API.Helpers._getWindow().location.href.split('?')[0],
[CMS.settings.edit_off + '=true']
);
CMS.API.Helpers.reloadBrowser(url);
Expand Down Expand Up @@ -642,7 +645,7 @@ var CMS = window.CMS || {};
});
break;
default:
window.location.href = el.attr('href');
CMS.API.Helpers._getWindow().location.href = el.attr('href');
}
},

Expand Down Expand Up @@ -673,6 +676,7 @@ var CMS = window.CMS || {};
*/
_debug: function _debug() {
var timeout = 1000;
// istanbul ignore next: function always reassigned
var timer = function () {};

// bind message event
Expand Down Expand Up @@ -705,16 +709,16 @@ var CMS = window.CMS || {};
var sideframe = $('.cms-sideframe');

// automatically resize screenblock window according to given attributes
$(window).on(this.resize, function () {
that.ui.window.on(that.resize + '.screenblock', function () {
blocker.css({
'width': $(this).width() - sideframe.width(),
'height': $(window).height()
'width': that.ui.window.width() - sideframe.width(),
'height': that.ui.window.height()
});
}).trigger('resize');
}).trigger(that.resize + '.screenblock');

// set update interval
setInterval(function () {
$(window).trigger(that.resize);
that.ui.window.trigger(that.resize + '.screenblock');
}, interval);
},

Expand Down
18 changes: 17 additions & 1 deletion cms/tests/frontend/unit/cms.sideframe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ describe('CMS.Sideframe', function () {
var sideframe;
beforeEach(function (done) {
$(function () {
CMS.settings = {
sideframe: {}
};
sideframe = new CMS.Sideframe();
done();
});
Expand Down Expand Up @@ -92,12 +95,16 @@ describe('CMS.Sideframe', function () {
spyOn(sideframe, 'setSettings').and.callFake(function (input) {
return input;
});
spyOn(sideframe, 'getSettings').and.callFake(function () {
return { sideframe: {} };
});
url = '/base/cms/tests/frontend/unit/html/sideframe_iframe.html';
done();
});
});

afterEach(function () {
sideframe.ui.body.off();
fixture.cleanup();
});

Expand Down Expand Up @@ -298,16 +305,21 @@ describe('CMS.Sideframe', function () {
});

it('is chainable', function () {
spyOn(sideframe, '_content');
expect(sideframe.open({ url: url })).toEqual(sideframe);
});

it('empties frame holder before injecting iframe (to remove events)', function () {
it('empties frame holder before injecting iframe (to remove events)', function (done) {
spyOn($.fn, 'empty').and.callThrough();
sideframe.ui.frame.append('<div>I should not be here</div>');
expect(sideframe.ui.frame).toHaveText('I should not be here');
sideframe.open({ url: url });
expect(sideframe.ui.frame).not.toHaveText('I should not be here');
expect($.fn.empty).toHaveBeenCalled();

sideframe.ui.frame.find('iframe').on('load', function () {
done();
});
});

it('adds specific classes on the iframe body', function (done) {
Expand All @@ -325,6 +337,7 @@ describe('CMS.Sideframe', function () {
CMS.config.debug = true;
sideframe.open({ url: url });

expect(CMS.settings.sideframe).toEqual({});
sideframe.ui.frame.find('iframe').on('load', function () {
expect($(this.contentDocument.body)).toHaveClass('cms-debug');
done();
Expand Down Expand Up @@ -393,6 +406,9 @@ describe('CMS.Sideframe', function () {
spyOn(sideframe, 'setSettings').and.callFake(function (input) {
return input;
});
spyOn(sideframe, 'getSettings').and.callFake(function () {
return { sideframe: {} };
});
url = '/base/cms/tests/frontend/unit/html/sideframe_iframe.html';
done();
});
Expand Down
Loading

0 comments on commit 391f2ec

Please sign in to comment.