From de2c2d48c2305b8b9400557a2302c32110620730 Mon Sep 17 00:00:00 2001 From: nikni Date: Sat, 5 Jan 2019 19:47:40 +0100 Subject: [PATCH] Add unit tests --- .../step/joyride-step.component.spec.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/lib/src/components/step/joyride-step.component.spec.ts b/src/lib/src/components/step/joyride-step.component.spec.ts index 7269cdaf..1838d8eb 100644 --- a/src/lib/src/components/step/joyride-step.component.spec.ts +++ b/src/lib/src/components/step/joyride-step.component.spec.ts @@ -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; @@ -82,6 +83,7 @@ describe('JoyrideStepComponent', () => { optionsService = TestBed.get(JoyrideOptionsService); documentService = TestBed.get(DocumentService); templatesService = TestBed.get(TemplatesService); + logger = TestBed.get(LoggerService); }); describe('ngOnInit', () => { @@ -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.'); + }); + }); });