added tests for linear workflow components

This commit is contained in:
alecmerdler 2017-02-22 15:44:20 -08:00 committed by Joseph Schorr
parent b0cc8d0f19
commit ff07533d80
8 changed files with 198 additions and 86 deletions

View file

@ -18,15 +18,6 @@ export class LinearWorkflowComponent implements ng.IComponentController {
private sections: SectionInfo[] = [];
private currentSection: SectionInfo;
constructor() {
}
public $onInit(): void {
}
public addSection(component: LinearWorkflowSectionComponent): void {
this.sections.push({
index: this.sections.length,
@ -34,20 +25,34 @@ export class LinearWorkflowComponent implements ng.IComponentController {
});
if (this.sections.length == 1) {
this.sections[0].component.sectionVisible = true;
this.currentSection = this.sections[0];
this.currentSection.component.sectionVisible = true;
this.currentSection.component.isCurrentSection = true;
}
}
public onNextSection(): void {
if (this.currentSection.component.sectionValid) {
if (this.currentSection.index + 1 >= this.sections.length) {
this.onWorkflowComplete({});
}
else {
this.currentSection = this.sections[this.currentSection.index];
}
if (this.currentSection.component.sectionValid && this.currentSection.index + 1 >= this.sections.length) {
this.onWorkflowComplete({});
}
else if (this.currentSection.component.sectionValid && this.currentSection.index + 1 < this.sections.length) {
this.currentSection.component.isCurrentSection = false;
this.currentSection = this.sections[this.currentSection.index + 1];
this.currentSection.component.sectionVisible = true;
this.currentSection.component.isCurrentSection = true;
}
}
public onSectionInvalid(sectionId: string): void {
var invalidSection = this.sections.filter(section => section.component.sectionId == sectionId)[0];
invalidSection.component.isCurrentSection = true;
this.currentSection = invalidSection;
this.sections.forEach((section) => {
if (section.index > invalidSection.index) {
section.component.sectionVisible = false;
section.component.isCurrentSection = false;
}
});
}
}