mattermost-mobile/app/screens/gallery/gallery.test.js.disabled
Elias Nahum b226d451f3
update dependencies (#4958)
* update dependencies

* revert keychain update

* Update dependencies & Fastlane

* set path agnostic for bash in scrips

* Fix open from push notification race

* patch react-native-localize
2020-11-18 19:45:07 -07:00

88 lines
2.5 KiB
Text

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallowWithIntl} from 'test/intl-test-helper';
import Preferences from '@mm-redux/constants/preferences';
import * as NavigationActions from 'app/actions/navigation';
import Gallery from './gallery';
jest.useFakeTimers();
jest.mock('react-native-file-viewer', () => ({
open: jest.fn(),
}));
jest.mock('react-native-reanimated', () => {
const Reanimated = require('react-native-reanimated/mock');
// The mock for `call` immediately calls the callback which is incorrect
// So we override it with a no-op
Reanimated.default.call = () => jest.fn();
return Reanimated;
});
describe('Gallery', () => {
const baseProps = {
canDownloadFiles: true,
deviceHeight: 400,
deviceWidth: 300,
files: [
{caption: 'Caption 1', source: 'source', data: 'data'},
{caption: 'Caption 2', source: 'source', data: 'data'},
],
index: 0,
theme: Preferences.THEMES.default,
componentId: 'component-id',
};
test('should match snapshot', () => {
const wrapper = shallowWithIntl(
<Gallery {...baseProps}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match state on handleChangeImage', () => {
const wrapper = shallowWithIntl(
<Gallery {...baseProps}/>,
);
wrapper.setState({index: 0});
wrapper.instance().handlePageSelected(1);
expect(wrapper.state('index')).toEqual(1);
});
test('should match call popTopScreen & mergeNavigationOptions on close', () => {
const mergeNavigationOptions = jest.spyOn(NavigationActions, 'mergeNavigationOptions');
const popTopScreen = jest.spyOn(NavigationActions, 'popTopScreen');
const wrapper = shallowWithIntl(
<Gallery
{...baseProps}
/>,
);
wrapper.instance().close();
expect(mergeNavigationOptions).toHaveBeenCalledTimes(1);
expect(popTopScreen).toHaveBeenCalled();
expect(mergeNavigationOptions).toHaveBeenCalledWith(
baseProps.componentId,
{
layout: {
backgroundColor: '#000',
componentBackgroundColor: '#000',
},
topBar: {
visible: true,
},
},
);
});
});