mail/test/unit/util/backbutton-handler-test.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-11-21 07:33:22 -05:00
var btnHandler = require('../../../src/js/util/backbutton-handler');
2014-10-07 14:32:23 -04:00
describe('Backbutton Handler', function() {
2014-11-05 08:27:34 -05:00
chai.config.includeStack = true;
2014-10-07 14:32:23 -04:00
var scope, event;
2014-10-07 14:32:23 -04:00
beforeEach(function() {
scope = {
state: {},
$apply: function() {}
};
2014-10-07 14:32:23 -04:00
event = new CustomEvent('backbutton');
2014-10-07 14:32:23 -04:00
// this is a precondition for the test. throw an exception
// if this would produce side effects
expect(navigator.app).to.not.exist;
navigator.app = {};
2014-10-07 14:32:23 -04:00
btnHandler.attachHandler(scope);
btnHandler.start();
});
2014-10-07 14:32:23 -04:00
afterEach(function() {
btnHandler.stop();
delete navigator.app;
});
2014-10-07 14:32:23 -04:00
it('should close lightbox', function() {
scope.state.lightbox = 'asd';
document.dispatchEvent(event);
expect(scope.state.lightbox).to.be.undefined;
});
2014-10-07 14:32:23 -04:00
it('should close reader', function() {
scope.state.read = {
open: true,
toggle: function(state) {
scope.state.read.open = state;
}
};
document.dispatchEvent(event);
expect(scope.state.read.open).to.be.false;
});
2014-10-07 14:32:23 -04:00
it('should close navigation', function() {
scope.state.nav = {
open: true,
toggle: function(state) {
scope.state.nav.open = state;
}
};
document.dispatchEvent(event);
expect(scope.state.nav.open).to.be.false;
});
2014-10-07 14:32:23 -04:00
it('should close app', function(done) {
navigator.app.exitApp = done;
document.dispatchEvent(event);
});
});