Fix ChannelLoader prop warning (#5055) (#5056)

* Fix ChannelLoader prop warning

* Missing semicolon

(cherry picked from commit f577685264)

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
Mattermost Build
2020-12-18 21:57:52 +01:00
committed by GitHub
parent 1c4aeece20
commit a31f2acd78
2 changed files with 20 additions and 8 deletions

View File

@@ -42,7 +42,7 @@ export default class ChannelLoader extends PureComponent {
style: CustomPropTypes.Style,
theme: PropTypes.object.isRequired,
height: PropTypes.number,
retryLoad: PropTypes.func.isRequired,
retryLoad: PropTypes.func,
};
constructor(props) {
@@ -75,8 +75,10 @@ export default class ChannelLoader extends PureComponent {
}
componentDidMount() {
this.stillLoadingTimeout = setTimeout(this.showIndicator, 10000);
this.retryLoadInterval = setInterval(this.props.retryLoad, 10000);
if (this.props.retryLoad) {
this.stillLoadingTimeout = setTimeout(this.showIndicator, 10000);
this.retryLoadInterval = setInterval(this.props.retryLoad, 10000);
}
}
componentWillUnmount() {

View File

@@ -14,7 +14,6 @@ describe('ChannelLoader', () => {
const baseProps = {
channelIsLoading: true,
theme: Preferences.THEMES.default,
retryLoad: jest.fn(),
};
test('should match snapshot', () => {
@@ -23,15 +22,26 @@ describe('ChannelLoader', () => {
});
test('should call setTimeout and setInterval for showIndicator and retryLoad on mount', () => {
const wrapper = shallow(<ChannelLoader {...baseProps}/>);
const instance = wrapper.instance();
shallow(<ChannelLoader {...baseProps}/>);
expect(setTimeout).not.toHaveBeenCalled();
expect(setInterval).not.toHaveBeenCalled();
const props = {
...baseProps,
retryLoad: jest.fn(),
};
const wrapper = shallow(<ChannelLoader {...props}/>);
const instance = wrapper.instance();
expect(setTimeout).toHaveBeenCalledWith(instance.showIndicator, 10000);
expect(setInterval).toHaveBeenCalledWith(baseProps.retryLoad, 10000);
expect(setInterval).toHaveBeenCalledWith(props.retryLoad, 10000);
});
test('should clear timer and interval on unmount', () => {
const wrapper = shallow(<ChannelLoader {...baseProps}/>);
const props = {
...baseProps,
retryLoad: jest.fn(),
};
const wrapper = shallow(<ChannelLoader {...props}/>);
const instance = wrapper.instance();
instance.componentWillUnmount();