mattermost-mobile/app/components/swiper.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

67 lines
2 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 Swiper from './swiper.js';
describe('Swiper', () => {
const baseProps = {
children: [],
};
test('should match snapshot', async () => {
const wrapper = shallow(
<Swiper {...baseProps}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should not call scrollView.scrollTo and updateIndex when children < 2', () => {
const children = [];
while (children.length < 2) {
const props = {...baseProps, children};
const wrapper = shallow(
<Swiper {...props}/>,
);
const instance = wrapper.instance();
instance.updateIndex = jest.fn();
instance.refScrollView({
scrollTo: jest.fn(),
});
instance.scrollToIndex(1, false);
expect(instance.scrollView.scrollTo).not.toHaveBeenCalled();
expect(instance.updateIndex).not.toHaveBeenCalled();
children.push('test');
}
expect(children.length).toBe(2);
});
test('should call scrollView.scrollTo and updateIndex when children >= 2', () => {
const children = [1, 2, 3];
while (children.length >= 2) {
const props = {...baseProps, children};
const wrapper = shallow(
<Swiper {...props}/>,
);
const instance = wrapper.instance();
instance.updateIndex = jest.fn();
instance.refScrollView({
scrollTo: jest.fn(),
});
instance.scrollToIndex(1, false);
expect(instance.scrollView.scrollTo).toHaveBeenCalled();
expect(instance.updateIndex).toHaveBeenCalled();
children.pop();
}
expect(children.length).toBe(1);
});
});