'use strict'; import { getChildDebugElement, mouseclick} from 'tests/helpers'; import {Component, View, provide, ViewMetadata} from 'angular2/core'; import {BrowserDomAdapter} from 'angular2/platform/browser'; import { TestComponentBuilder, injectAsync, 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 Redoc from 'lib/components/Redoc/redoc'; import SchemaManager from 'lib/utils/SchemaManager'; let _mockRedoc = { 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(Redoc, {useValue: _mockRedoc}) ]); beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { builder = tcb; return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; }); })); 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.adapter, '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', (done) => { let hash = '#pet/paths/~1pet~1findByStatus/get'; spyOn(component.adapter, '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('scollable div parent case', () => { let menuNativeEl; beforeEach((done) => { let scollableDivTmpl = `