'use strict'; import { getChildDebugElement, mouseclick} from 'tests/helpers'; import {Component, provide, ViewMetadata} from 'angular2/core'; import {BrowserDomAdapter} from 'angular2/platform/browser'; import OptionsManager from 'lib/options'; import { TestComponentBuilder, inject, async, beforeEach, beforeEachProviders, it } from 'angular2/testing'; import {redocEvents} from 'lib/events'; import MethodsList from 'lib/components/MethodsList/methods-list'; import SideMenu from 'lib/components/SideMenu/side-menu'; import SchemaManager from 'lib/utils/SchemaManager'; let testOptions = new OptionsManager(); testOptions.options = { scrollYOffset: () => 0, scrollParent: window }; describe('Redoc components', () => { describe('SideMenu Component', () => { let builder; let component; let fixture; beforeEachProviders(() => [ provide(SchemaManager, {useValue: new SchemaManager()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(OptionsManager, {useValue: testOptions}) ]); beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { builder = tcb; return schemaMgr.load('/tests/schemas/extended-petstore.yml'); }))); afterEach(() => { if (fixture) fixture.destroy(); }); describe('window parent case', () => { beforeEach((done) => { builder.createAsync(TestApp).then(_fixture => { fixture = _fixture; component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance; fixture.detectChanges(); done(); }, err => { throw err; }); }); it('should init component and component data', () => { expect(component).not.toBeNull(); expect(component.data).not.toBeNull(); }); it('should run hashScroll when redoc bootstrapped', (done) => { spyOn(component.dom, 'getLocation').and.returnValue({hash: ''}); spyOn(component, 'hashScroll').and.stub(); spyOn(window, 'scrollTo').and.stub(); redocEvents.bootstrapped.next(); setTimeout(() => { expect(component.hashScroll).toHaveBeenCalled(); expect(window.scrollTo).not.toHaveBeenCalled(); window.scrollTo.and.callThrough(); component.hashScroll.and.callThrough(); done(); }); }); it('should scroll to method when location hash is present [jp]', (done) => { let hash = '#tag/pet/paths/~1pet~1findByStatus/get'; spyOn(component.dom, 'getLocation').and.returnValue({hash: hash}); spyOn(component, 'hashScroll').and.callThrough(); spyOn(window, 'scrollTo').and.stub(); redocEvents.bootstrapped.next(); setTimeout(() => { expect(component.hashScroll).toHaveBeenCalled(); let scrollY = window.scrollTo.calls.argsFor(0)[1]; expect(scrollY).toBeGreaterThan(0); done(); }); }); it('should scroll to method when location hash is present [operation]', (done) => { let hash = '#operation/getPetById'; spyOn(component.dom, 'getLocation').and.returnValue({hash: hash}); spyOn(component, 'hashScroll').and.callThrough(); spyOn(window, 'scrollTo').and.stub(); redocEvents.bootstrapped.next(); setTimeout(() => { expect(component.hashScroll).toHaveBeenCalled(); let scrollY = window.scrollTo.calls.argsFor(0)[1]; expect(scrollY).toBeGreaterThan(0); done(); }); }); }); describe('scrollable div parent case', () => { let menuNativeEl; beforeEach((done) => { let scollableDivTmpl = `