Add specs for InputComponentManagerService
All checks were successful
continuous-integration/drone the build was successful
All checks were successful
continuous-integration/drone the build was successful
This commit is contained in:
parent
2e1abbbd3d
commit
56ae9f2acd
2 changed files with 61 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { TestBed, inject } from '@angular/core/testing';
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import { InputComponentManagerService } from './input-component-manager.service';
|
import {InputComponentManagerService} from './input-component-manager.service';
|
||||||
|
import {Step} from './step';
|
||||||
|
|
||||||
describe('InputComponentManagerService', () => {
|
describe('InputComponentManagerService', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -12,4 +13,59 @@ describe('InputComponentManagerService', () => {
|
||||||
it('should be created', inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
it('should be created', inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should create a component if requesting the first one',
|
||||||
|
inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
|
const firstStep: Step = service.getFirst();
|
||||||
|
expect(firstStep).toBeTruthy();
|
||||||
|
expect(service.getFirst()).toBe(firstStep);
|
||||||
|
expect(service.getAllComponents().length).toEqual(1);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
it('must not add a null Step', inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
|
expect(() => service.register(null)).toThrowError();
|
||||||
|
expect(service.getAllComponents().length).toEqual(0);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('must not add an undefined Step', inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
|
expect(() => service.register(undefined)).toThrowError();
|
||||||
|
expect(service.getAllComponents().length).toEqual(0);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should register new Steps', inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
|
service.register(new Step(99));
|
||||||
|
expect(service.getAllComponents().length).toEqual(1);
|
||||||
|
service.register(new Step(100));
|
||||||
|
expect(service.getAllComponents().length).toEqual(2);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should return a new step if the next step doesn\'t exist',
|
||||||
|
inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
|
// arrange
|
||||||
|
const firstStep: Step = new Step(0);
|
||||||
|
service.register(firstStep);
|
||||||
|
|
||||||
|
// act
|
||||||
|
const nextStep: Step = service.getNext(firstStep);
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(service.getAllComponents().length).toEqual(2);
|
||||||
|
expect(nextStep.index).toEqual(1);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
it('should return the next step if requested', inject([InputComponentManagerService], (service: InputComponentManagerService) => {
|
||||||
|
// arrange
|
||||||
|
const firstStep: Step = new Step(0);
|
||||||
|
const nextStep: Step = new Step(1);
|
||||||
|
service.register(firstStep);
|
||||||
|
service.register(nextStep);
|
||||||
|
|
||||||
|
// act
|
||||||
|
const requestedStep: Step = service.getNext(firstStep);
|
||||||
|
// assert
|
||||||
|
expect(service.getAllComponents().length).toEqual(2);
|
||||||
|
expect(requestedStep).toEqual(nextStep);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,6 +11,9 @@ export class InputComponentManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public register(component: Step): void {
|
public register(component: Step): void {
|
||||||
|
if (!component) {
|
||||||
|
throw new Error('component to add must not be empty or undefined');
|
||||||
|
}
|
||||||
this.components.push(component);
|
this.components.push(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue