community-app/test/spec/controllers/MainControllerSpec.js

88 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

2014-03-02 12:09:27 +00:00
describe("MainController", function () {
var eventListener, sessionCallback;
beforeEach(function () {
this.scope = jasmine.createSpyObj("$scope", ['$on', '$watch']);
this.scope.$on.andCallFake(function (event, listener) {
eventListener = listener;
});
this.location = jasmine.createSpyObj("$location", ['path', 'replace']);
this.location.path.andReturn(this.location);
this.sessionManager = jasmine.createSpyObj("sessionManager", ['get', 'clear', 'restore']);
this.sessionManager.restore.andCallFake(function (callback) {
sessionCallback = callback;
});
this.keyboardManager = jasmine.createSpyObj('keyboardManager', ['bind']);
2013-11-19 09:17:38 +00:00
2017-01-24 10:03:32 +00:00
this.translate = jasmine.createSpyObj("translate", ["use"]);
this.rootScope = jasmine.createSpyObj("$rootScope", ['$broadcast']);
this.localStorageService = jasmine.createSpyObj("localStorageService", ["addToLocalStorage", "getFromLocalStorage"]);
this.promise = jasmine.createSpyObj('Promise', ['success','then']);
this.http = jasmine.createSpyObj("$http", ['get']);
this.http.get.andReturn(this.promise);
2014-03-02 12:09:27 +00:00
this.idle = jasmine.createSpyObj("$idle", ['watch', 'unwatch']);
this.tmhDynamicLocale = jasmine.createSpyObj("tmhDynamicLocale", ["set"]);
2015-03-13 08:41:11 +00:00
this.uiConfigService = jasmine.createSpyObj("uiConfigService", ["init"]);
2014-03-02 12:09:27 +00:00
this.controller = new mifosX.controllers.MainController(this.scope,
this.location,
this.sessionManager,
this.translate,
this.rootScope,
this.localStorageService,
this.keyboardManager,
this.idle,
2015-03-13 08:41:11 +00:00
this.tmhDynamicLocale,
this.uiConfigService,
this.http);
});
2014-03-02 12:09:27 +00:00
describe("on initialisation", function () {
it("should listen to 'UserAuthenticationSuccessEvent'", function () {
expect(this.scope.$on).toHaveBeenCalledWith("UserAuthenticationSuccessEvent", jasmine.any(Function));
});
it("should restore the session", function () {
sessionCallback("test_session");
expect(this.scope.currentSession).toEqual("test_session");
});
2014-03-02 12:09:27 +00:00
it("should set the dateformat in the scope", function () {
expect(this.scope.dateformat).toEqual("dd MMMM yyyy");
expect(this.scope.df).toEqual("dd MMMM yyyy");
});
});
2013-06-03 08:35:49 +00:00
2014-03-02 12:09:27 +00:00
describe("on receving 'UserAuthenticationSuccessEvent'", function () {
beforeEach(function () {
this.sessionManager.get.andReturn("test_session");
2013-12-11 17:14:56 +00:00
2014-03-02 12:09:27 +00:00
eventListener({}, "test_data");
});
2013-06-03 08:35:49 +00:00
2014-03-02 12:09:27 +00:00
it("should start a new session", function () {
expect(this.sessionManager.get).toHaveBeenCalledWith("test_data");
expect(this.scope.currentSession).toEqual("test_session");
});
it("should redirect to the home page", function () {
expect(this.location.path).toHaveBeenCalledWith('/home');
});
2013-06-03 08:35:49 +00:00
});
2014-03-02 12:09:27 +00:00
describe("User logout", function () {
beforeEach(function () {
this.sessionManager.clear.andReturn("test_session");
2013-12-11 17:14:56 +00:00
2014-03-02 12:09:27 +00:00
this.scope.logout();
});
2014-03-02 12:09:27 +00:00
it("should clear the session", function () {
expect(this.sessionManager.clear).toHaveBeenCalled();
expect(this.scope.currentSession).toEqual("test_session");
});
it("should redirect to the start page", function () {
expect(this.location.path).toHaveBeenCalledWith('/');
});
});
});