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"]);
|
2017-11-27 13:20:51 +00:00
|
|
|
this.rootScope = jasmine.createSpyObj("$rootScope", ['$broadcast']);
|
2014-12-11 15:57:46 +00:00
|
|
|
this.localStorageService = jasmine.createSpyObj("localStorageService", ["addToLocalStorage", "getFromLocalStorage"]);
|
2015-03-13 20:37:23 +00:00
|
|
|
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']);
|
2014-12-04 18:23:05 +00:00
|
|
|
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,
|
2014-12-04 18:03:41 +00:00
|
|
|
this.idle,
|
2015-03-13 08:41:11 +00:00
|
|
|
this.tmhDynamicLocale,
|
2015-03-13 20:37:23 +00:00
|
|
|
this.uiConfigService,
|
|
|
|
|
this.http);
|
2013-06-29 04:31:00 +00:00
|
|
|
});
|
|
|
|
|
|
2014-12-04 18:23:05 +00:00
|
|
|
|
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-01-01 23:40:33 +00:00
|
|
|
|
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");
|
|
|
|
|
});
|
2014-01-01 23:40:33 +00:00
|
|
|
});
|
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
|
|
|
});
|
2013-06-29 04:31:00 +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();
|
|
|
|
|
});
|
2013-06-18 10:56:29 +00:00
|
|
|
|
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('/');
|
|
|
|
|
});
|
2013-06-29 04:31:00 +00:00
|
|
|
});
|
2014-12-04 18:03:41 +00:00
|
|
|
});
|