Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lazy-load): lazyLoadOffset option does not work #177

Merged
merged 1 commit into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/static/components/state/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Screenshot extends Component {
const {lazyLoadOffset: offset} = this.props;

return offset
? <LazyLoad offsetVertical={offset} debounce={50} placeholder={placeholder} once>{elem}</LazyLoad>
? <LazyLoad offset={offset} debounce={50} placeholder={placeholder} once>{elem}</LazyLoad>
: elem;
}

Expand Down
51 changes: 51 additions & 0 deletions test/lib/static/components/section/screenshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import LazyLoad from '@gemini-testing/react-lazyload';
import Screenshot from 'lib/static/components/state/screenshot';
import Placeholder from 'lib/static/components/state/placeholder';
import {mkConnectedComponent} from '../utils';

describe('Screenshot component', () => {
describe('LazyLoad component', () => {
const getLazyLoadComponent_ = ({lazyLoadOffset = 1} = {}) => {
const screenshotComponent = mkConnectedComponent(
<Screenshot image={{path: ''}} />,
{initialState: {view: {lazyLoadOffset}}}
);

return screenshotComponent.find(LazyLoad);
};

it('should set "debounce" option', () => {
const lazyLoadComponent = getLazyLoadComponent_();

assert.equal(lazyLoadComponent.props().debounce, 50);
});

it('should set "once" option', () => {
const lazyLoadComponent = getLazyLoadComponent_();

assert.isTrue(lazyLoadComponent.props().once);
});

it('should pass offset from store to LazyLoad component', () => {
const lazyLoadComponent = getLazyLoadComponent_({lazyLoadOffset: 333});

assert.equal(lazyLoadComponent.props().offset, 333);
});

it('should not set placeholder by default', () => {
const lazyLoadComponent = getLazyLoadComponent_();

assert.lengthOf(lazyLoadComponent.find(Placeholder), 0);
});

it('should set placeholder to LazyLoad component if passed image has size', () => {
const screenshotComponent = mkConnectedComponent(
<Screenshot image={{path: '', size: {}}} />,
{initialState: {view: {lazyLoadOffset: 1}}}
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно в отдельный хелпер вынести - сейчас дублирование.


assert.lengthOf(screenshotComponent.find(Placeholder), 1);
});
});
});