fix unit tests after introduction of animations - adds delays for click trigger

This commit is contained in:
Morris Jobke 2014-06-02 18:09:26 +02:00
parent cd61fb06eb
commit fbe42a771f
1 changed files with 7 additions and 0 deletions

View File

@ -359,8 +359,10 @@ describe('Core base tests', function() {
var oldMatchMedia; var oldMatchMedia;
var $toggle; var $toggle;
var $navigation; var $navigation;
var clock;
beforeEach(function() { beforeEach(function() {
clock = sinon.useFakeTimers();
oldMatchMedia = OC._matchMedia; oldMatchMedia = OC._matchMedia;
// a separate method was needed because window.matchMedia // a separate method was needed because window.matchMedia
// cannot be stubbed due to a bug in PhantomJS: // cannot be stubbed due to a bug in PhantomJS:
@ -376,6 +378,7 @@ describe('Core base tests', function() {
afterEach(function() { afterEach(function() {
OC._matchMedia = oldMatchMedia; OC._matchMedia = oldMatchMedia;
clock.restore();
}); });
it('Sets up menu toggle in mobile mode', function() { it('Sets up menu toggle in mobile mode', function() {
OC._matchMedia.returns({matches: true}); OC._matchMedia.returns({matches: true});
@ -413,8 +416,10 @@ describe('Core base tests', function() {
$navigation.hide(); // normally done through media query triggered CSS $navigation.hide(); // normally done through media query triggered CSS
expect($navigation.is(':visible')).toEqual(false); expect($navigation.is(':visible')).toEqual(false);
$toggle.click(); $toggle.click();
clock.tick(1 * 1000);
expect($navigation.is(':visible')).toEqual(true); expect($navigation.is(':visible')).toEqual(true);
$toggle.click(); $toggle.click();
clock.tick(1 * 1000);
expect($navigation.is(':visible')).toEqual(false); expect($navigation.is(':visible')).toEqual(false);
}); });
it('Clicking menu toggle does not toggle navigation in desktop mode', function() { it('Clicking menu toggle does not toggle navigation in desktop mode', function() {
@ -448,6 +453,7 @@ describe('Core base tests', function() {
window.initCore(); window.initCore();
expect($navigation.is(':visible')).toEqual(false); expect($navigation.is(':visible')).toEqual(false);
$toggle.click(); $toggle.click();
clock.tick(1 * 1000);
expect($navigation.is(':visible')).toEqual(true); expect($navigation.is(':visible')).toEqual(true);
mq.matches = false; mq.matches = false;
$(window).trigger('resize'); $(window).trigger('resize');
@ -456,6 +462,7 @@ describe('Core base tests', function() {
$(window).trigger('resize'); $(window).trigger('resize');
expect($navigation.is(':visible')).toEqual(false); expect($navigation.is(':visible')).toEqual(false);
$toggle.click(); $toggle.click();
clock.tick(1 * 1000);
expect($navigation.is(':visible')).toEqual(true); expect($navigation.is(':visible')).toEqual(true);
}); });
}); });