This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/linear-workflow/linear-workflow.component.spec.ts
Alec Merdler 7a352ddfbc Use ng-metadata as a Backport of Angular 2+ API (#2486)
* starting UtilService refactor

* pre find-replace angular.module('quay') => angular.module('QuayModule')

* successfully switched to ng-metadata for backported Angular2 API

* working with parent component reference in child

* fixing @Output to use EventEmitter

* fixed @Output events for custom git trigger

* more fixes

* refactored QuayPages module for backwards-compatibility

* reinitialized test.db

* use minified libraries

* replaced references for angular-ts-decorators

* fixed ng-show
2017-04-05 14:14:08 -07:00

127 lines
4.5 KiB
TypeScript

import { LinearWorkflowComponent, SectionInfo } from './linear-workflow.component';
import { LinearWorkflowSectionComponent } from './linear-workflow-section.component';
import Spy = jasmine.Spy;
describe("LinearWorkflowComponent", () => {
var component: LinearWorkflowComponent;
beforeEach(() => {
component = new LinearWorkflowComponent();
});
describe("addSection", () => {
var newSection: LinearWorkflowSectionComponent;
beforeEach(() => {
newSection = new LinearWorkflowSectionComponent(component);
});
it("does not set 'sectionVisible' or 'isCurrentSection' of given section if not the first section added", () => {
component.addSection(new LinearWorkflowSectionComponent(component));
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.createSpyObj("onWorkflowCompleteSpy", ['emit']);
currentSection = new LinearWorkflowSectionComponent(component);
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.emit).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.emit).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);
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(component);
invalidSection.sectionId = "Git Repository";
invalidSection.sectionValid = false;
component.addSection(invalidSection);
sections = [
new LinearWorkflowSectionComponent(component),
new LinearWorkflowSectionComponent(component),
new LinearWorkflowSectionComponent(component),
];
sections.forEach((section) => {
section.sectionVisible = false;
section.isCurrentSection = false;
component.addSection(section);
});
});
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);
});
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", () => {
sections.forEach((section) => {
section.sectionVisible = true;
section.isCurrentSection = true;
component.addSection(section);
});
component.onSectionInvalid(invalidSection.sectionId);
sections.forEach((section) => {
expect(section.sectionVisible).toBe(false);
expect(section.isCurrentSection).toBe(false);
});
});
});
});