salix/front/core/components/step-control/step-control.spec.js

69 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

import './step-control.js';
describe('Component vnStepControl', () => {
let controller;
let $state;
beforeEach(ngModule('vnCore'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, _$state_) => {
$state = _$state_;
2020-02-26 12:22:52 +00:00
jest.spyOn($state, 'go');
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');
});
});
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!');
});
it(`should call the onStepChange method then return false and never call the go method`, () => {
controller.onStepChange = jasmine.createSpy(controller, 'onStepChange').and.returnValue(false);
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);
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;
expect(result).toEqual(1);
});
});
});