mirror of
https://gitlab.silvrtree.co.uk/martind2000/aodb.git
synced 2025-01-28 22:46:17 +00:00
114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
|
|
import {Directive, Controller} from './frame'
|
|
import {ComponentTest} from '../../infrastructure/ComponentHelper'
|
|
import {Mod as Core} from '../../core/core.mod';
|
|
import {Mod as Auth} from '../../authentication/auth.mod';
|
|
|
|
class FrameViewTest extends ComponentTest {
|
|
public $state: ng.ui.IStateService;
|
|
public $window: ng.IWindowService;
|
|
public $rootScope: ng.IRootScopeService;
|
|
public $ionicHistory: ionic.navigation.IonicHistoryService;
|
|
constructor() {
|
|
super(Directive.$componentName, 'app/core/frame/frame.tpl.html');
|
|
}
|
|
}
|
|
|
|
describe('Frame: ', () => {
|
|
let test: FrameViewTest,
|
|
ctrl: Controller;
|
|
|
|
beforeEach(() => {
|
|
new Core(angular);
|
|
new Auth(angular);
|
|
|
|
angular.mock.module('ui.router');
|
|
angular.mock.module('ionic');
|
|
angular.mock.module('chroma.configuration');
|
|
angular.mock.module('ngCookies');
|
|
|
|
angular.mock.module(Core.$componentName);
|
|
angular.mock.module(Auth.$componentName);
|
|
});
|
|
|
|
beforeEach(() => {
|
|
angular.mock.inject(($state, $window, $rootScope, $ionicHistory) => {
|
|
test = new FrameViewTest();
|
|
test.$state = $state;
|
|
test.$window = $window;
|
|
test.$rootScope = $rootScope;
|
|
test.$ionicHistory = $ionicHistory;
|
|
ctrl = test.compile<Controller>();
|
|
});
|
|
});
|
|
|
|
it('Directive can be compiled', () => {
|
|
expect(ctrl).toBeDefined();
|
|
})
|
|
|
|
it('When no matches, IonicBack is not called', () => {
|
|
spyOn(test.$ionicHistory, 'goBack');
|
|
ctrl.currentState = 'chroma.undefined-state';
|
|
ctrl.back();
|
|
expect(test.$ionicHistory.goBack).not.toHaveBeenCalled();
|
|
})
|
|
|
|
|
|
it('Logout called if back pressed without state', () => {
|
|
spyOn(ctrl.authenticationService, 'logout');
|
|
ctrl.back();
|
|
expect(ctrl.authenticationService.logout).toHaveBeenCalled();
|
|
})
|
|
|
|
it('Logout called if back pressed on Site Selection state', () => {
|
|
spyOn(ctrl.authenticationService, 'logout');
|
|
ctrl.currentState = 'chroma.site-selection';
|
|
ctrl.back();
|
|
expect(ctrl.authenticationService.logout).toHaveBeenCalled();
|
|
})
|
|
|
|
it('Window List called if back pressed on flight List state', () => {
|
|
spyOn(test.$state, 'go');
|
|
ctrl.currentState = 'chroma.flight-list';
|
|
ctrl.back();
|
|
expect(test.$state.go).toHaveBeenCalledWith('chroma.window-list');
|
|
})
|
|
|
|
it('Site Selection List called if back pressed on Window List state', () => {
|
|
spyOn(test.$state, 'go');
|
|
ctrl.currentState = 'chroma.window-list';
|
|
ctrl.back();
|
|
expect(test.$state.go).toHaveBeenCalledWith('chroma.site-selection');
|
|
})
|
|
|
|
it('Flight List NOT called if back pressed on Flight Detail state and not saved filter', () => {
|
|
spyOn(test.$state, 'go');
|
|
spyOn(test.$window.sessionStorage, 'getItem').and.returnValue(undefined);
|
|
ctrl.currentState = 'chroma.flight-detail';
|
|
ctrl.back();
|
|
expect(test.$state.go).not.toHaveBeenCalledWith('chroma.flight-list', { filter: 'test-filter' });
|
|
})
|
|
|
|
it('Flight List called if back pressed on Flight Detail state', () => {
|
|
spyOn(test.$state, 'go');
|
|
spyOn(test.$window.sessionStorage, 'getItem').and.returnValue('test-filter');
|
|
ctrl.currentState = 'chroma.flight-detail';
|
|
ctrl.back();
|
|
expect(test.$state.go)
|
|
.toHaveBeenCalledWith('chroma.flight-list', { filter: 'test-filter' });
|
|
})
|
|
|
|
it('Current State is updated on $steChangeStart event', () =>{
|
|
let testState : string = 'test-state123';
|
|
test.$rootScope.$emit('$stateChangeStart', {name : testState});
|
|
expect(ctrl.currentState).toBe(testState);
|
|
});
|
|
|
|
it('isFlightDetailState stays insync with current state', () =>{
|
|
let testState : string = 'flight-detail';
|
|
test.$rootScope.$emit('$stateChangeStart', {name : testState});
|
|
expect(ctrl.currentState).toBe(testState);
|
|
expect(ctrl.isFlightDetailState).toBe(true);
|
|
});
|
|
})
|