mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
Update tests after refactoring
This commit is contained in:
parent
5485df84fe
commit
9744cddb16
|
@ -61,6 +61,7 @@ module.exports = function (config) {
|
|||
|
||||
proxies: {
|
||||
'/tests/': '/base/tests/',
|
||||
'/lib/components/Redoc/redoc-loading-styles.css': '/base/.tmp/lib/components/Redoc/redoc-loading-styles.css',
|
||||
'/lib/': '/base/lib/',
|
||||
'/jspm_packages/': '/base/jspm_packages/',
|
||||
'/node_modules/': '/base/node_modules/',
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import { getChildDebugElement } from 'tests/helpers';
|
||||
import {Component, View, provide} from 'angular2/core';
|
||||
import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component_loader';
|
||||
import {BrowserDomAdapter} from 'angular2/platform/browser';
|
||||
|
||||
import {
|
||||
TestComponentBuilder,
|
||||
|
@ -14,6 +15,7 @@ import {
|
|||
|
||||
import JsonSchemaLazy from 'lib/components/JsonSchema/json-schema-lazy';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
import OptionsManager from 'lib/options';
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('JsonSchemaLazy Component', () => {
|
||||
|
@ -26,7 +28,10 @@ describe('Redoc components', () => {
|
|||
instance: {}
|
||||
};
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: schemaMgr})
|
||||
provide(SchemaManager, {useValue: schemaMgr}),
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
|
||||
provide('OPTION_NAMES', {useValue: []}),
|
||||
provide(OptionsManager, {useClass: OptionsManager})
|
||||
]);
|
||||
beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
import {Component, View, provide} from 'angular2/core';
|
||||
import OptionsManager from 'lib/options';
|
||||
|
||||
import {
|
||||
TestComponentBuilder,
|
||||
|
@ -21,7 +22,9 @@ describe('Redoc components', () => {
|
|||
let schemaMgr = new SchemaManager();
|
||||
let fixture;
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: schemaMgr})
|
||||
provide(SchemaManager, {useValue: schemaMgr}),
|
||||
provide('OPTION_NAMES', {useValue: []}),
|
||||
provide(OptionsManager, {useClass: OptionsManager})
|
||||
]);
|
||||
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import { getChildDebugElement } from 'tests/helpers';
|
||||
import {Component, View, provide} from 'angular2/core';
|
||||
import {BrowserDomAdapter} from 'angular2/platform/browser';
|
||||
|
||||
import {
|
||||
TestComponentBuilder,
|
||||
|
@ -13,13 +14,17 @@ import {
|
|||
|
||||
import Method from 'lib/components/Method/method';
|
||||
import SchemaManager from 'lib/utils/SchemaManager';
|
||||
import OptionsManager from 'lib/options';
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('Method Component', () => {
|
||||
let builder;
|
||||
let component;
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()})
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
|
||||
provide('OPTION_NAMES', {useValue: []}),
|
||||
provide(OptionsManager, {useClass: OptionsManager})
|
||||
]);
|
||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import { getChildDebugElement, mouseclick} from 'tests/helpers';
|
||||
import {Component, View, provide, ViewMetadata} from 'angular2/core';
|
||||
import {BrowserDomAdapter} from 'angular2/platform/browser';
|
||||
import OptionsManager from 'lib/options';
|
||||
|
||||
import {
|
||||
TestComponentBuilder,
|
||||
|
@ -15,15 +16,14 @@ import {
|
|||
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
|
||||
},
|
||||
let testOptions = new OptionsManager();
|
||||
testOptions.options = {
|
||||
scrollYOffset: () => 0,
|
||||
scrollParent: window
|
||||
};
|
||||
|
||||
describe('Redoc components', () => {
|
||||
describe('SideMenu Component', () => {
|
||||
let builder;
|
||||
|
@ -32,7 +32,8 @@ describe('Redoc components', () => {
|
|||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
|
||||
provide(Redoc, {useValue: _mockRedoc})
|
||||
provide('OPTION_NAMES', {useValue: []}),
|
||||
provide(OptionsManager, {useValue: testOptions})
|
||||
]);
|
||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
|
@ -61,7 +62,7 @@ describe('Redoc components', () => {
|
|||
});
|
||||
|
||||
it('should run hashScroll when redoc bootstrapped', (done) => {
|
||||
spyOn(component.adapter, 'getLocation').and.returnValue({hash: ''});
|
||||
spyOn(component.dom, 'getLocation').and.returnValue({hash: ''});
|
||||
spyOn(component, 'hashScroll').and.stub();
|
||||
spyOn(window, 'scrollTo').and.stub();
|
||||
redocEvents.bootstrapped.next();
|
||||
|
@ -77,7 +78,7 @@ describe('Redoc components', () => {
|
|||
|
||||
it('should scroll to method when location hash is present [jp]', (done) => {
|
||||
let hash = '#tag/pet/paths/~1pet~1findByStatus/get';
|
||||
spyOn(component.adapter, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component.dom, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component, 'hashScroll').and.callThrough();
|
||||
spyOn(window, 'scrollTo').and.stub();
|
||||
redocEvents.bootstrapped.next();
|
||||
|
@ -91,7 +92,7 @@ describe('Redoc components', () => {
|
|||
|
||||
it('should scroll to method when location hash is present [operation]', (done) => {
|
||||
let hash = '#operation/getPetById';
|
||||
spyOn(component.adapter, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component.dom, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component, 'hashScroll').and.callThrough();
|
||||
spyOn(window, 'scrollTo').and.stub();
|
||||
redocEvents.bootstrapped.next();
|
||||
|
@ -104,7 +105,7 @@ describe('Redoc components', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('scollable div parent case', () => {
|
||||
describe('scrollable div parent case', () => {
|
||||
let menuNativeEl;
|
||||
beforeEach((done) => {
|
||||
let scollableDivTmpl =
|
||||
|
@ -114,14 +115,13 @@ describe('Redoc components', () => {
|
|||
</div>`;
|
||||
builder = builder.overrideView(
|
||||
TestApp, new ViewMetadata({template: scollableDivTmpl, directives: [MethodsList, SideMenu]}));
|
||||
|
||||
builder.createAsync(TestApp).then(_fixture => {
|
||||
fixture = _fixture;
|
||||
component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance;
|
||||
menuNativeEl = getChildDebugElement(fixture.debugElement, 'side-menu').nativeElement;
|
||||
component.scrollParent = _fixture.nativeElement.children[0];
|
||||
component.options.scrollParent = _fixture.nativeElement.children[0];
|
||||
component.$scrollParent = _fixture.nativeElement.children[0];
|
||||
fixture.detectChanges();
|
||||
|
||||
done();
|
||||
}, err => {
|
||||
throw err;
|
||||
|
@ -137,24 +137,24 @@ describe('Redoc components', () => {
|
|||
|
||||
it('should scroll to method when location hash is present [jp]', (done) => {
|
||||
let hash = '#tag/pet/paths/~1pet~1findByStatus/get';
|
||||
spyOn(component.adapter, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component.dom, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component, 'hashScroll').and.callThrough();
|
||||
redocEvents.bootstrapped.next();
|
||||
setTimeout(() => {
|
||||
expect(component.hashScroll).toHaveBeenCalled();
|
||||
expect(component.scrollParent.scrollTop).toBeGreaterThan(0);
|
||||
expect(component.$scrollParent.scrollTop).toBeGreaterThan(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should scroll to method when location hash is present [operation]', (done) => {
|
||||
let hash = '#operation/getPetById';
|
||||
spyOn(component.adapter, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component.dom, 'getLocation').and.returnValue({hash: hash});
|
||||
spyOn(component, 'hashScroll').and.callThrough();
|
||||
redocEvents.bootstrapped.next();
|
||||
setTimeout(() => {
|
||||
expect(component.hashScroll).toHaveBeenCalled();
|
||||
expect(component.scrollParent.scrollTop).toBeGreaterThan(0);
|
||||
expect(component.$scrollParent.scrollTop).toBeGreaterThan(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -164,14 +164,14 @@ describe('Redoc components', () => {
|
|||
component.activeMethodIdx.should.be.equal(-1);
|
||||
let elTop = component.getCurrentMethodEl().getBoundingClientRect().bottom;
|
||||
|
||||
component.scrollParent.scrollTop = elTop + 1;
|
||||
component.$scrollParent.scrollTop = elTop + 1;
|
||||
//simulate scroll down
|
||||
spyOn(component, 'scrollY').and.returnValue(elTop + 2);
|
||||
component.scrollHandler();
|
||||
component.activeCatIdx.should.be.equal(1);
|
||||
|
||||
|
||||
component.scrollParent.scrollTop = elTop - 1;
|
||||
component.$scrollParent.scrollTop = elTop - 1;
|
||||
//simulate scroll up
|
||||
component.scrollY.and.returnValue(elTop - 2);
|
||||
component.scrollHandler();
|
||||
|
@ -187,10 +187,10 @@ describe('Redoc components', () => {
|
|||
});
|
||||
|
||||
it('should scroll to appropriate element when click on menu label', () => {
|
||||
component.scrollParent.scrollTop.should.be.equal(0);
|
||||
component.$scrollParent.scrollTop.should.be.equal(0);
|
||||
let menuItemEl = menuNativeEl.querySelector('li');
|
||||
mouseclick(menuItemEl);
|
||||
component.scrollParent.scrollTop.should.be.above(0);
|
||||
component.$scrollParent.scrollTop.should.be.above(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user