mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +03:00
Created ScrollToTop test
This commit is contained in:
parent
d020ed0b13
commit
056286636d
2 changed files with 31 additions and 2 deletions
|
@ -7,10 +7,10 @@ const ScrollToTop = ({ scrollTo }) => class ScrollToTop extends React.Component
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate({ location: prevLocation }) {
|
||||||
const { location } = this.props;
|
const { location } = this.props;
|
||||||
|
|
||||||
if (location !== prevProps.location) {
|
if (location !== prevLocation) {
|
||||||
scrollTo(0, 0);
|
scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
29
test/common/ScrollToTop.test.js
Normal file
29
test/common/ScrollToTop.test.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
import * as sinon from 'sinon';
|
||||||
|
import createScrollToTop from '../../src/common/ScrollToTop';
|
||||||
|
|
||||||
|
describe('<ScrollToTop />', () => {
|
||||||
|
let wrapper;
|
||||||
|
const window = {
|
||||||
|
scrollTo: sinon.spy(),
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
const ScrollToTop = createScrollToTop(window);
|
||||||
|
|
||||||
|
wrapper = shallow(<ScrollToTop locaction={{ href: 'foo' }}>Foobar</ScrollToTop>);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper.unmount();
|
||||||
|
window.scrollTo.resetHistory();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('just renders children', () => expect(wrapper.text()).toEqual('Foobar'));
|
||||||
|
|
||||||
|
it('scrolls to top when location changes', () => {
|
||||||
|
wrapper.instance().componentDidUpdate({ location: { href: 'bar' } });
|
||||||
|
expect(window.scrollTo.calledOnce).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue