added tests for linear workflow components
This commit is contained in:
parent
b0cc8d0f19
commit
ff07533d80
8 changed files with 198 additions and 86 deletions
|
@ -1,5 +1,6 @@
|
|||
import { LinearWorkflowComponent, SectionInfo } from './linear-workflow.component';
|
||||
import { LinearWorkflowSectionComponent } from './linear-workflow-section.component';
|
||||
import Spy = jasmine.Spy;
|
||||
|
||||
|
||||
describe("LinearWorkflowComponent", () => {
|
||||
|
@ -10,10 +11,103 @@ describe("LinearWorkflowComponent", () => {
|
|||
});
|
||||
|
||||
describe("addSection", () => {
|
||||
var newSection: LinearWorkflowSectionComponent;
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe("onNextSection", () => {
|
||||
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) => {
|
||||
section.sectionVisible = true;
|
||||
section.isCurrentSection = true;
|
||||
component.addSection(section);
|
||||
});
|
||||
});
|
||||
|
||||
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", () => {
|
||||
component.onSectionInvalid(invalidSection.sectionId);
|
||||
|
||||
sections.forEach((section) => {
|
||||
expect(section.sectionVisible).toBe(false);
|
||||
expect(section.isCurrentSection).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue