2017-02-21 23:59:26 +00:00
|
|
|
import { LinearWorkflowComponent, SectionInfo } from './linear-workflow.component';
|
|
|
|
import { LinearWorkflowSectionComponent } from './linear-workflow-section.component';
|
2017-02-22 23:44:20 +00:00
|
|
|
import Spy = jasmine.Spy;
|
2017-02-21 23:59:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe("LinearWorkflowComponent", () => {
|
|
|
|
var component: LinearWorkflowComponent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
component = new LinearWorkflowComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("addSection", () => {
|
2017-02-22 23:44:20 +00:00
|
|
|
var newSection: LinearWorkflowSectionComponent;
|
2017-02-21 23:59:26 +00:00
|
|
|
|
2017-02-22 23:44:20 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
newSection = new LinearWorkflowSectionComponent;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not set 'sectionVisible' or 'isCurrentSection' of given section if not the first section added", () => {
|
|
|
|
component.addSection(new LinearWorkflowSectionComponent);
|
|
|
|
component.addSection(newSection);
|
|
|
|
|
|
|
|
expect(newSection.sectionVisible).toBe(false);
|
|
|
|
expect(newSection.isCurrentSection).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets 'sectionVisible' of given section to true if it is the first section added", () => {
|
|
|
|
component.addSection(newSection);
|
|
|
|
|
|
|
|
expect(newSection.sectionVisible).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets 'isCurrentSection' of given section to true if it is the first section added", () => {
|
|
|
|
component.addSection(newSection);
|
|
|
|
|
|
|
|
expect(newSection.isCurrentSection).toBe(true);
|
|
|
|
});
|
2017-02-21 23:59:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("onNextSection", () => {
|
2017-02-22 23:44:20 +00:00
|
|
|
var currentSection: LinearWorkflowSectionComponent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
component.onWorkflowComplete = jasmine.createSpy("onWorkflowComplete").and.returnValue(null);
|
|
|
|
currentSection = new LinearWorkflowSectionComponent;
|
|
|
|
currentSection.sectionValid = true;
|
|
|
|
component.addSection(currentSection);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not complete workflow or change current section if current section is invalid", () => {
|
|
|
|
currentSection.sectionValid = false;
|
|
|
|
component.onNextSection();
|
|
|
|
|
|
|
|
expect(component.onWorkflowComplete).not.toHaveBeenCalled();
|
|
|
|
expect(currentSection.isCurrentSection).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calls workflow completed output callback if current section is the last section and is valid", () => {
|
|
|
|
component.onNextSection();
|
|
|
|
|
|
|
|
expect(component.onWorkflowComplete).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets the current section to the next section if there are remaining sections and current section valid", () => {
|
|
|
|
var nextSection: LinearWorkflowSectionComponent = new LinearWorkflowSectionComponent();
|
|
|
|
component.addSection(nextSection);
|
|
|
|
component.onNextSection();
|
|
|
|
|
|
|
|
expect(currentSection.isCurrentSection).toBe(false);
|
|
|
|
expect(nextSection.isCurrentSection).toBe(true);
|
|
|
|
expect(nextSection.sectionVisible).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("onSectionInvalid", () => {
|
|
|
|
var invalidSection: LinearWorkflowSectionComponent;
|
|
|
|
var sections: LinearWorkflowSectionComponent[];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
invalidSection = new LinearWorkflowSectionComponent();
|
|
|
|
invalidSection.sectionId = "Git Repository";
|
|
|
|
invalidSection.sectionValid = false;
|
|
|
|
component.addSection(invalidSection);
|
|
|
|
|
|
|
|
sections = [
|
|
|
|
new LinearWorkflowSectionComponent(),
|
|
|
|
new LinearWorkflowSectionComponent(),
|
|
|
|
new LinearWorkflowSectionComponent(),
|
|
|
|
];
|
|
|
|
sections.forEach((section) => {
|
2017-02-23 00:33:34 +00:00
|
|
|
section.sectionVisible = false;
|
|
|
|
section.isCurrentSection = false;
|
2017-02-22 23:44:20 +00:00
|
|
|
component.addSection(section);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-23 00:33:34 +00:00
|
|
|
it("does nothing if invalid section is after the current section", () => {
|
|
|
|
sections[sections.length - 1].sectionValid = false;
|
|
|
|
sections[sections.length - 1].sectionId = "Some Section";
|
|
|
|
component.onSectionInvalid(sections[sections.length - 1].sectionId);
|
|
|
|
|
|
|
|
expect(sections[sections.length - 1].isCurrentSection).toBe(false);
|
|
|
|
expect(sections[sections.length - 1].sectionVisible).toBe(false);
|
|
|
|
});
|
|
|
|
|
2017-02-22 23:44:20 +00:00
|
|
|
it("sets the section with the given id to be the current section", () => {
|
|
|
|
component.onSectionInvalid(invalidSection.sectionId);
|
|
|
|
|
|
|
|
expect(invalidSection.isCurrentSection).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hides all sections after the section with the given id", () => {
|
2017-02-23 00:33:34 +00:00
|
|
|
sections.forEach((section) => {
|
|
|
|
section.sectionVisible = true;
|
|
|
|
section.isCurrentSection = true;
|
|
|
|
component.addSection(section);
|
|
|
|
});
|
2017-02-22 23:44:20 +00:00
|
|
|
component.onSectionInvalid(invalidSection.sectionId);
|
2017-02-21 23:59:26 +00:00
|
|
|
|
2017-02-22 23:44:20 +00:00
|
|
|
sections.forEach((section) => {
|
|
|
|
expect(section.sectionVisible).toBe(false);
|
|
|
|
expect(section.isCurrentSection).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2017-02-21 23:59:26 +00:00
|
|
|
});
|
|
|
|
});
|