mattermost-mobile/app/components/retriable_fast_image/retriable_fast_image.test.js
Daniel Espino García 4c8594d330
Add linter rules for import order and type member delimiters (#5514)
* Add linter rules for import order and type member delimiters

* Remove unneeded group

* Group all app/* imports before the internal imports

* Move app/ imports before parent imports

* Separate @node_modules imports into a different group

* Substitute app paths by aliases

* Fix @node_modules import order and add test related modules

* Add aliases for types and test, and group import types
2021-07-23 11:06:04 +02:00

52 lines
1.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FastImage from 'react-native-fast-image';
import RetriableFastImage, {FAST_IMAGE_MAX_RETRIES} from './index';
describe('RetriableFastImage', () => {
const baseProps = {
id: 'id',
onError: jest.fn(),
};
it('should update the FastImage element key on error until max retries has been reached', () => {
const wrapper = shallow(
<RetriableFastImage {...baseProps}/>,
);
const instance = wrapper.instance();
let retry = 0;
expect(wrapper.containsMatchingElement(<FastImage key={`${baseProps.id}-${retry}`}/>)).toEqual(true);
while (instance.state.retry < FAST_IMAGE_MAX_RETRIES) {
instance.onError();
retry += 1;
expect(wrapper.containsMatchingElement(<FastImage key={`${baseProps.id}-${retry}`}/>)).toEqual(true);
}
instance.onError();
expect(wrapper.containsMatchingElement(<FastImage key={`${baseProps.id}-${retry}`}/>)).toEqual(true);
});
it('should call props.onError only after max retries has been reached', () => {
const wrapper = shallow(
<RetriableFastImage {...baseProps}/>,
);
const instance = wrapper.instance();
let retry = 0;
while (instance.state.retry < FAST_IMAGE_MAX_RETRIES) {
instance.onError();
retry += 1;
expect(instance.state.retry).toEqual(retry);
expect(baseProps.onError).not.toHaveBeenCalled();
}
instance.onError();
expect(instance.state.retry).toEqual(retry);
expect(baseProps.onError).toHaveBeenCalled();
});
});