2018-04-18 07:47:05 +00:00
|
|
|
import './step-control.js';
|
|
|
|
|
|
|
|
describe('Component vnStepControl', () => {
|
|
|
|
let controller;
|
|
|
|
let $state;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-04-18 07:47:05 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_) => {
|
2018-04-18 07:47:05 +00:00
|
|
|
$state = _$state_;
|
2018-08-30 14:15:10 +00:00
|
|
|
spyOn($state, 'go');
|
2018-04-18 07:47:05 +00:00
|
|
|
controller = $componentController('vnStepControl', {$state: $state});
|
|
|
|
}));
|
|
|
|
|
2018-08-30 14:15:10 +00:00
|
|
|
describe('steps()', () => {
|
|
|
|
it(`should do nothing if called without args`, () => {
|
|
|
|
controller.steps = undefined;
|
|
|
|
|
|
|
|
expect(controller._steps).not.toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set _steps property in the controller and call state.go()`, () => {
|
|
|
|
controller.$state.current.name = 'test';
|
|
|
|
controller.steps = [{state: 'nothing'}, {state: 'test'}];
|
|
|
|
|
|
|
|
expect(controller._steps).toEqual([{state: 'nothing'}, {state: 'test'}]);
|
|
|
|
expect(controller.currentStepIndex).toEqual(1);
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('nothing');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-18 07:47:05 +00:00
|
|
|
describe('currentState()', () => {
|
2018-08-30 14:15:10 +00:00
|
|
|
it(`should call the go method if the's no onStepChange`, () => {
|
|
|
|
controller.currentState = 'hello state!';
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('hello state!');
|
|
|
|
});
|
|
|
|
|
2018-04-18 07:47:05 +00:00
|
|
|
it(`should call the onStepChange method then return false and never call the go method`, () => {
|
|
|
|
controller.onStepChange = jasmine.createSpy(controller, 'onStepChange').and.returnValue(false);
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
controller.currentState = 'something';
|
2018-04-18 07:47:05 +00:00
|
|
|
|
|
|
|
expect(controller.onStepChange).toHaveBeenCalledWith({state: 'something'});
|
2018-12-22 10:59:26 +00:00
|
|
|
expect(controller.$state.go).not.toHaveBeenCalledWith('something');
|
2018-04-18 07:47:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call the onStepChange method then return true and finally call the go method`, () => {
|
|
|
|
controller.onStepChange = jasmine.createSpy(controller, 'onStepChange').and.returnValue(true);
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
controller.currentState = 'something';
|
2018-04-18 07:47:05 +00:00
|
|
|
|
|
|
|
expect(controller.onStepChange).toHaveBeenCalledWith({state: 'something'});
|
2018-12-22 10:59:26 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('something');
|
2018-04-18 07:47:05 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('currentStepIndex()', () => {
|
|
|
|
it('should get the current state index from an Array of states', () => {
|
|
|
|
controller.$state.current.name = 'iam_a_current_state';
|
|
|
|
controller.steps = [{state: 'iam_not_current_state'}, {state: 'iam_a_current_state'}];
|
|
|
|
|
|
|
|
let result = controller.currentStepIndex;
|
2018-08-01 07:47:34 +00:00
|
|
|
|
2018-04-18 07:47:05 +00:00
|
|
|
expect(result).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|