2018-04-18 07:47:05 +00:00
|
|
|
import './step-control.js';
|
|
|
|
|
|
|
|
describe('Component vnStepControl', () => {
|
|
|
|
let $componentController;
|
|
|
|
let controller;
|
|
|
|
let $state;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('ticket');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
|
|
|
|
$componentController = _$componentController_;
|
|
|
|
$state = _$state_;
|
|
|
|
controller = $componentController('vnStepControl', {$state: $state});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('currentState()', () => {
|
|
|
|
it(`should call the onStepChange method then return false and never call the go method`, () => {
|
|
|
|
controller.onStepChange = jasmine.createSpy(controller, 'onStepChange').and.returnValue(false);
|
|
|
|
spyOn(controller.$state, 'go');
|
|
|
|
|
|
|
|
controller.currentState = "something";
|
|
|
|
|
|
|
|
expect(controller.onStepChange).toHaveBeenCalledWith({state: 'something'});
|
|
|
|
expect(controller.$state.go).not.toHaveBeenCalledWith("something");
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call the onStepChange method then return true and finally call the go method`, () => {
|
|
|
|
controller.onStepChange = jasmine.createSpy(controller, 'onStepChange').and.returnValue(true);
|
|
|
|
spyOn(controller.$state, 'go');
|
|
|
|
|
|
|
|
controller.currentState = "something";
|
|
|
|
|
|
|
|
expect(controller.onStepChange).toHaveBeenCalledWith({state: 'something'});
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith("something");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|