2017-02-21 23:59:26 +00:00
|
|
|
import { LinearWorkflowSectionComponent } from './linear-workflow-section.component';
|
|
|
|
import { LinearWorkflowComponent } from './linear-workflow.component';
|
2017-04-05 21:14:08 +00:00
|
|
|
import { SimpleChanges } from 'ng-metadata/core';
|
2017-05-26 18:50:11 +00:00
|
|
|
import { Mock } from 'ts-mocks';
|
2017-02-21 23:59:26 +00:00
|
|
|
import Spy = jasmine.Spy;
|
|
|
|
|
|
|
|
|
|
|
|
describe("LinearWorkflowSectionComponent", () => {
|
|
|
|
var component: LinearWorkflowSectionComponent;
|
2017-05-26 18:50:11 +00:00
|
|
|
var parentMock: Mock<LinearWorkflowComponent>;
|
2017-02-21 23:59:26 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-05-26 18:50:11 +00:00
|
|
|
parentMock = new Mock<LinearWorkflowComponent>();
|
|
|
|
component = new LinearWorkflowSectionComponent(parentMock.Object);
|
|
|
|
component.sectionId = "mysection";
|
2017-02-21 23:59:26 +00:00
|
|
|
});
|
|
|
|
|
2017-04-05 21:14:08 +00:00
|
|
|
describe("ngOnInit", () => {
|
2017-02-21 23:59:26 +00:00
|
|
|
|
|
|
|
it("calls parent component to add itself as a section", () => {
|
2017-05-26 18:50:11 +00:00
|
|
|
parentMock.setup(mock => mock.addSection).is((section) => null);
|
2017-04-05 21:14:08 +00:00
|
|
|
component.ngOnInit();
|
2017-02-21 23:59:26 +00:00
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect((<Spy>parentMock.Object.addSection).calls.argsFor(0)[0]).toBe(component);
|
2017-02-21 23:59:26 +00:00
|
|
|
});
|
|
|
|
});
|
2017-02-22 23:44:20 +00:00
|
|
|
|
2017-04-05 21:14:08 +00:00
|
|
|
describe("ngOnChanges", () => {
|
|
|
|
var changesObj: SimpleChanges;
|
2017-02-22 23:44:20 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-05-26 18:50:11 +00:00
|
|
|
parentMock.setup(mock => mock.onSectionInvalid).is((section) => null);
|
2017-02-22 23:44:20 +00:00
|
|
|
changesObj = {
|
|
|
|
sectionValid: {
|
|
|
|
currentValue: true,
|
|
|
|
previousValue: false,
|
|
|
|
isFirstChange: () => false,
|
|
|
|
},
|
2017-05-22 20:59:12 +00:00
|
|
|
skipSection: {
|
|
|
|
currentValue: true,
|
|
|
|
previousValue: false,
|
|
|
|
isFirstChange: () => false,
|
|
|
|
},
|
2017-02-22 23:44:20 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does nothing if 'sectionValid' input not changed", () => {
|
2017-04-05 21:14:08 +00:00
|
|
|
component.ngOnChanges({});
|
2017-02-22 23:44:20 +00:00
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect((<Spy>parentMock.Object.onSectionInvalid)).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does nothing if 'sectionValid' input's previous value is falsy", () => {
|
|
|
|
changesObj['sectionValid'].previousValue = null;
|
|
|
|
component.ngOnChanges(changesObj);
|
|
|
|
|
|
|
|
expect((<Spy>parentMock.Object.onSectionInvalid)).not.toHaveBeenCalled();
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does nothing if 'sectionValid' input is true", () => {
|
2017-04-05 21:14:08 +00:00
|
|
|
component.ngOnChanges(changesObj);
|
2017-02-22 23:44:20 +00:00
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect((<Spy>parentMock.Object.onSectionInvalid)).not.toHaveBeenCalled();
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("calls parent method to inform that section is invalid if 'sectionValid' input changed to false", () => {
|
2017-05-26 18:50:11 +00:00
|
|
|
changesObj['sectionValid'].previousValue = true;
|
2017-02-22 23:44:20 +00:00
|
|
|
changesObj['sectionValid'].currentValue = false;
|
2017-04-05 21:14:08 +00:00
|
|
|
component.ngOnChanges(changesObj);
|
2017-02-22 23:44:20 +00:00
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect((<Spy>parentMock.Object.onSectionInvalid).calls.argsFor(0)[0]).toEqual(component.sectionId);
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
2017-05-22 20:59:12 +00:00
|
|
|
|
|
|
|
it("calls parent method to go to next section if 'skipSection' input is true and is current section", () => {
|
|
|
|
delete changesObj['sectionValid'];
|
2017-05-26 18:50:11 +00:00
|
|
|
parentMock.setup(mock => mock.onNextSection).is(() => null);
|
2017-05-22 20:59:12 +00:00
|
|
|
component.isCurrentSection = true;
|
|
|
|
component.ngOnChanges(changesObj);
|
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect(<Spy>parentMock.Object.onNextSection).toHaveBeenCalled();
|
2017-05-22 20:59:12 +00:00
|
|
|
});
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("onSubmitSection", () => {
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-05-26 18:50:11 +00:00
|
|
|
parentMock.setup(mock => mock.onNextSection).is(() => null);
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("does nothing if section is invalid", () => {
|
|
|
|
component.sectionValid = false;
|
|
|
|
component.onSubmitSection();
|
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect(<Spy>parentMock.Object.onNextSection).not.toHaveBeenCalled();
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("calls parent method to go to next section if section is valid", () => {
|
|
|
|
component.sectionValid = true;
|
|
|
|
component.onSubmitSection();
|
|
|
|
|
2017-05-26 18:50:11 +00:00
|
|
|
expect(<Spy>parentMock.Object.onNextSection).toHaveBeenCalled();
|
2017-02-22 23:44:20 +00:00
|
|
|
});
|
|
|
|
});
|
2017-02-21 23:59:26 +00:00
|
|
|
});
|