Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicola committed Jan 5, 2019
1 parent 004c9de commit de2c2d4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lib/src/components/step/joyride-step.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('JoyrideStepComponent', () => {
let joyrideStepService: JoyrideStepFakeService = new JoyrideStepFakeService();
let documentService: DocumentServiceFake;
let templatesService: TemplatesFakeService;
let logger: LoggerFake;
let STEP: JoyrideStep;
let STEP_CONTAINER: ElementRef;
let TEMPLATE: TemplateRef<any>;
Expand Down Expand Up @@ -82,6 +83,7 @@ describe('JoyrideStepComponent', () => {
optionsService = TestBed.get(JoyrideOptionsService);
documentService = TestBed.get(DocumentService);
templatesService = TestBed.get(TemplatesService);
logger = TestBed.get(LoggerService);
});

describe('ngOnInit', () => {
Expand Down Expand Up @@ -604,4 +606,34 @@ describe('JoyrideStepComponent', () => {
expect(component.topPosition).toBe(targetAbsoluteLeft + targetHeight + DISTANCE_FROM_TARGET);
});
});

describe('autofixTopPosition()', () => {
// TODO: Improve these tests since they are calling a private method
it(`should NOT log 'No step positions found...' if called once`, () => {
component['autofixTopPosition']();
expect(logger.warn).not.toHaveBeenCalled();
});
it(`should log 'No step positions found...' if called twice and the step does not fit the TOP position`, () => {
const targetHeight = 50;
let elemRef = new FakeElementRef(19, targetHeight);
let STEP = new JoyrideStep();
STEP.targetViewContainer = new FakeViewContainerRef(elemRef);
STEP.position = 'top';

// Set targetAbsoluteLeft
const targetAbsoluteHeight = 20;
STEP.isElementOrAncestorFixed = false;
documentService.getElementAbsoluteTop.and.returnValue(targetAbsoluteHeight);

// Set stepHeight
const stepHeight = 100;
spyOn(component, 'adjustDimensions').and.returnValue({ width: 100, height: stepHeight });

component.step = STEP;
component.ngAfterViewInit(); // autofixTopPosition called for the first time
component['autofixTopPosition']();

expect(logger.warn).toHaveBeenCalledWith('No step positions found for this step. The step will be centered.');
});
});
});

0 comments on commit de2c2d4

Please sign in to comment.