2015-12-26 20:44:39 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-21 01:09:42 +03:00
|
|
|
import { getChildDebugElementByType } from 'tests/helpers';
|
2016-03-27 18:25:46 +03:00
|
|
|
import {Component, provide} from 'angular2/core';
|
2015-12-26 20:44:39 +03:00
|
|
|
import {BrowserDomAdapter} from 'angular2/platform/browser';
|
|
|
|
|
|
|
|
import {
|
|
|
|
TestComponentBuilder,
|
|
|
|
inject,
|
|
|
|
beforeEach,
|
|
|
|
beforeEachProviders,
|
|
|
|
it
|
|
|
|
} from 'angular2/testing';
|
|
|
|
|
|
|
|
import StickySidebar from 'lib/common/components/StickySidebar/sticky-sidebar';
|
|
|
|
|
|
|
|
describe('Common components', () => {
|
|
|
|
describe('StickySidebar Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
beforeEachProviders(() => [
|
|
|
|
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()})
|
|
|
|
]);
|
|
|
|
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
|
|
|
builder = tcb;
|
|
|
|
}));
|
|
|
|
beforeEach((done) => {
|
|
|
|
builder.createAsync(TestApp).then(_fixture => {
|
|
|
|
fixture = _fixture;
|
2016-01-21 01:09:42 +03:00
|
|
|
let debugEl = getChildDebugElementByType(fixture.debugElement, StickySidebar);
|
2016-04-30 00:45:53 +03:00
|
|
|
component = debugEl.injector.get(StickySidebar);
|
2015-12-26 20:44:39 +03:00
|
|
|
done();
|
|
|
|
}, err => done.fail(err));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should init component', () => {
|
|
|
|
expect(component).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should start unsticked', () => {
|
|
|
|
spyOn(component, 'stick').and.callThrough();
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(component.stick).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2015-12-27 00:12:10 +03:00
|
|
|
it('should stick if scrolled more than scrollYOffset', () => {
|
2015-12-26 20:44:39 +03:00
|
|
|
spyOn(component, 'stick').and.callThrough();
|
|
|
|
fixture.detectChanges();
|
2016-01-17 22:50:42 +03:00
|
|
|
component.scrollParent = {
|
|
|
|
pageYOffset: 40
|
|
|
|
};
|
2015-12-26 20:44:39 +03:00
|
|
|
component.updatePosition();
|
|
|
|
expect(component.stick).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** Test component that contains an ApiInfo. */
|
2016-03-27 18:25:46 +03:00
|
|
|
@Component({
|
|
|
|
selector: 'test-app',
|
2015-12-26 20:44:39 +03:00
|
|
|
directives: [StickySidebar],
|
|
|
|
template:
|
|
|
|
`<div style="padding-top: 20px">
|
|
|
|
<div style="height: 20px; position: fixed; top: 0;"> </div>
|
|
|
|
<div style="position: relative">
|
2016-01-21 01:09:42 +03:00
|
|
|
<div sticky-sidebar [scrollParent]="scrollParent" [scrollYOffset]="options.scrollYOffset">
|
|
|
|
</div>
|
2015-12-26 20:44:39 +03:00
|
|
|
</div>
|
|
|
|
</div>`
|
|
|
|
|
|
|
|
})
|
|
|
|
class TestApp {
|
|
|
|
constructor() {
|
|
|
|
this.options = {};
|
2015-12-27 00:12:10 +03:00
|
|
|
this.scrollParent = window;
|
2015-12-27 02:02:17 +03:00
|
|
|
this.options.scrollYOffset = () => 20;
|
2015-12-26 20:44:39 +03:00
|
|
|
}
|
|
|
|
}
|