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-section.component.spec.ts

105 lines
3.3 KiB
TypeScript
Raw Normal View History

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