Update tests after refactoring

This commit is contained in:
Roman Hotsiy 2016-02-10 17:18:36 +02:00
parent 5485df84fe
commit 9744cddb16
5 changed files with 38 additions and 24 deletions

View File

@ -61,6 +61,7 @@ module.exports = function (config) {
proxies: { proxies: {
'/tests/': '/base/tests/', '/tests/': '/base/tests/',
'/lib/components/Redoc/redoc-loading-styles.css': '/base/.tmp/lib/components/Redoc/redoc-loading-styles.css',
'/lib/': '/base/lib/', '/lib/': '/base/lib/',
'/jspm_packages/': '/base/jspm_packages/', '/jspm_packages/': '/base/jspm_packages/',
'/node_modules/': '/base/node_modules/', '/node_modules/': '/base/node_modules/',

View File

@ -3,6 +3,7 @@
import { getChildDebugElement } from 'tests/helpers'; import { getChildDebugElement } from 'tests/helpers';
import {Component, View, provide} from 'angular2/core'; import {Component, View, provide} from 'angular2/core';
import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component_loader'; import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component_loader';
import {BrowserDomAdapter} from 'angular2/platform/browser';
import { import {
TestComponentBuilder, TestComponentBuilder,
@ -14,6 +15,7 @@ import {
import JsonSchemaLazy from 'lib/components/JsonSchema/json-schema-lazy'; import JsonSchemaLazy from 'lib/components/JsonSchema/json-schema-lazy';
import SchemaManager from 'lib/utils/SchemaManager'; import SchemaManager from 'lib/utils/SchemaManager';
import OptionsManager from 'lib/options';
describe('Redoc components', () => { describe('Redoc components', () => {
describe('JsonSchemaLazy Component', () => { describe('JsonSchemaLazy Component', () => {
@ -26,7 +28,10 @@ describe('Redoc components', () => {
instance: {} instance: {}
}; };
beforeEachProviders(() => [ 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) => { beforeEach(inject([TestComponentBuilder, DynamicComponentLoader], (tcb, dcl) => {
builder = tcb; builder = tcb;

View File

@ -2,6 +2,7 @@
import { getChildDebugElement } from 'tests/helpers'; import { getChildDebugElement } from 'tests/helpers';
import {Component, View, provide} from 'angular2/core'; import {Component, View, provide} from 'angular2/core';
import OptionsManager from 'lib/options';
import { import {
TestComponentBuilder, TestComponentBuilder,
@ -21,7 +22,9 @@ describe('Redoc components', () => {
let schemaMgr = new SchemaManager(); let schemaMgr = new SchemaManager();
let fixture; let fixture;
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: schemaMgr}) provide(SchemaManager, {useValue: schemaMgr}),
provide('OPTION_NAMES', {useValue: []}),
provide(OptionsManager, {useClass: OptionsManager})
]); ]);
beforeEach(inject([TestComponentBuilder], (tcb) => { beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb; builder = tcb;

View File

@ -2,6 +2,7 @@
import { getChildDebugElement } from 'tests/helpers'; import { getChildDebugElement } from 'tests/helpers';
import {Component, View, provide} from 'angular2/core'; import {Component, View, provide} from 'angular2/core';
import {BrowserDomAdapter} from 'angular2/platform/browser';
import { import {
TestComponentBuilder, TestComponentBuilder,
@ -13,13 +14,17 @@ import {
import Method from 'lib/components/Method/method'; import Method from 'lib/components/Method/method';
import SchemaManager from 'lib/utils/SchemaManager'; import SchemaManager from 'lib/utils/SchemaManager';
import OptionsManager from 'lib/options';
describe('Redoc components', () => { describe('Redoc components', () => {
describe('Method Component', () => { describe('Method Component', () => {
let builder; let builder;
let component; let component;
beforeEachProviders(() => [ 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) => { beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;

View File

@ -3,6 +3,7 @@
import { getChildDebugElement, mouseclick} from 'tests/helpers'; import { getChildDebugElement, mouseclick} from 'tests/helpers';
import {Component, View, provide, ViewMetadata} from 'angular2/core'; import {Component, View, provide, ViewMetadata} from 'angular2/core';
import {BrowserDomAdapter} from 'angular2/platform/browser'; import {BrowserDomAdapter} from 'angular2/platform/browser';
import OptionsManager from 'lib/options';
import { import {
TestComponentBuilder, TestComponentBuilder,
@ -15,15 +16,14 @@ import {
import {redocEvents} from 'lib/events'; import {redocEvents} from 'lib/events';
import MethodsList from 'lib/components/MethodsList/methods-list'; import MethodsList from 'lib/components/MethodsList/methods-list';
import SideMenu from 'lib/components/SideMenu/side-menu'; import SideMenu from 'lib/components/SideMenu/side-menu';
import Redoc from 'lib/components/Redoc/redoc';
import SchemaManager from 'lib/utils/SchemaManager'; import SchemaManager from 'lib/utils/SchemaManager';
let _mockRedoc = { let testOptions = new OptionsManager();
options: { testOptions.options = {
scrollYOffset: () => 0 scrollYOffset: () => 0,
},
scrollParent: window scrollParent: window
}; };
describe('Redoc components', () => { describe('Redoc components', () => {
describe('SideMenu Component', () => { describe('SideMenu Component', () => {
let builder; let builder;
@ -32,7 +32,8 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(Redoc, {useValue: _mockRedoc}) provide('OPTION_NAMES', {useValue: []}),
provide(OptionsManager, {useValue: testOptions})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
@ -61,7 +62,7 @@ describe('Redoc components', () => {
}); });
it('should run hashScroll when redoc bootstrapped', (done) => { 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(component, 'hashScroll').and.stub();
spyOn(window, 'scrollTo').and.stub(); spyOn(window, 'scrollTo').and.stub();
redocEvents.bootstrapped.next(); redocEvents.bootstrapped.next();
@ -77,7 +78,7 @@ describe('Redoc components', () => {
it('should scroll to method when location hash is present [jp]', (done) => { it('should scroll to method when location hash is present [jp]', (done) => {
let hash = '#tag/pet/paths/~1pet~1findByStatus/get'; 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(component, 'hashScroll').and.callThrough();
spyOn(window, 'scrollTo').and.stub(); spyOn(window, 'scrollTo').and.stub();
redocEvents.bootstrapped.next(); redocEvents.bootstrapped.next();
@ -91,7 +92,7 @@ describe('Redoc components', () => {
it('should scroll to method when location hash is present [operation]', (done) => { it('should scroll to method when location hash is present [operation]', (done) => {
let hash = '#operation/getPetById'; 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(component, 'hashScroll').and.callThrough();
spyOn(window, 'scrollTo').and.stub(); spyOn(window, 'scrollTo').and.stub();
redocEvents.bootstrapped.next(); redocEvents.bootstrapped.next();
@ -104,7 +105,7 @@ describe('Redoc components', () => {
}); });
}); });
describe('scollable div parent case', () => { describe('scrollable div parent case', () => {
let menuNativeEl; let menuNativeEl;
beforeEach((done) => { beforeEach((done) => {
let scollableDivTmpl = let scollableDivTmpl =
@ -114,14 +115,13 @@ describe('Redoc components', () => {
</div>`; </div>`;
builder = builder.overrideView( builder = builder.overrideView(
TestApp, new ViewMetadata({template: scollableDivTmpl, directives: [MethodsList, SideMenu]})); TestApp, new ViewMetadata({template: scollableDivTmpl, directives: [MethodsList, SideMenu]}));
builder.createAsync(TestApp).then(_fixture => { builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture; fixture = _fixture;
component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance; component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance;
menuNativeEl = getChildDebugElement(fixture.debugElement, 'side-menu').nativeElement; 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(); fixture.detectChanges();
done(); done();
}, err => { }, err => {
throw err; throw err;
@ -137,24 +137,24 @@ describe('Redoc components', () => {
it('should scroll to method when location hash is present [jp]', (done) => { it('should scroll to method when location hash is present [jp]', (done) => {
let hash = '#tag/pet/paths/~1pet~1findByStatus/get'; 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(component, 'hashScroll').and.callThrough();
redocEvents.bootstrapped.next(); redocEvents.bootstrapped.next();
setTimeout(() => { setTimeout(() => {
expect(component.hashScroll).toHaveBeenCalled(); expect(component.hashScroll).toHaveBeenCalled();
expect(component.scrollParent.scrollTop).toBeGreaterThan(0); expect(component.$scrollParent.scrollTop).toBeGreaterThan(0);
done(); done();
}); });
}); });
it('should scroll to method when location hash is present [operation]', (done) => { it('should scroll to method when location hash is present [operation]', (done) => {
let hash = '#operation/getPetById'; 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(component, 'hashScroll').and.callThrough();
redocEvents.bootstrapped.next(); redocEvents.bootstrapped.next();
setTimeout(() => { setTimeout(() => {
expect(component.hashScroll).toHaveBeenCalled(); expect(component.hashScroll).toHaveBeenCalled();
expect(component.scrollParent.scrollTop).toBeGreaterThan(0); expect(component.$scrollParent.scrollTop).toBeGreaterThan(0);
done(); done();
}); });
}); });
@ -164,14 +164,14 @@ describe('Redoc components', () => {
component.activeMethodIdx.should.be.equal(-1); component.activeMethodIdx.should.be.equal(-1);
let elTop = component.getCurrentMethodEl().getBoundingClientRect().bottom; let elTop = component.getCurrentMethodEl().getBoundingClientRect().bottom;
component.scrollParent.scrollTop = elTop + 1; component.$scrollParent.scrollTop = elTop + 1;
//simulate scroll down //simulate scroll down
spyOn(component, 'scrollY').and.returnValue(elTop + 2); spyOn(component, 'scrollY').and.returnValue(elTop + 2);
component.scrollHandler(); component.scrollHandler();
component.activeCatIdx.should.be.equal(1); component.activeCatIdx.should.be.equal(1);
component.scrollParent.scrollTop = elTop - 1; component.$scrollParent.scrollTop = elTop - 1;
//simulate scroll up //simulate scroll up
component.scrollY.and.returnValue(elTop - 2); component.scrollY.and.returnValue(elTop - 2);
component.scrollHandler(); component.scrollHandler();
@ -187,10 +187,10 @@ describe('Redoc components', () => {
}); });
it('should scroll to appropriate element when click on menu label', () => { 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'); let menuItemEl = menuNativeEl.querySelector('li');
mouseclick(menuItemEl); mouseclick(menuItemEl);
component.scrollParent.scrollTop.should.be.above(0); component.$scrollParent.scrollTop.should.be.above(0);
}); });
}); });
}); });