Skip to content

Commit

Permalink
fix(lazy-load): lazyLoadOffset option does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
sipayRT committed Dec 25, 2018
1 parent 24fe0f7 commit f107096
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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', () => {
const getLazyLoadComponent_ = ({lazyLoadOffset = 1} = {}) => {
const screenshotComponent = mkConnectedComponent(
<Screenshot image={{path: ''}} />,
{initialState: {view: {lazyLoadOffset}}}
);

return screenshotComponent.find(LazyLoad);
};

describe('LazyLoad component', () => {
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}}}
);

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

0 comments on commit f107096

Please sign in to comment.