mattermost-mobile/app/components/post_draft/post_draft.test.js
Elias Nahum 48f1875cf1
MM-23090 MM-26078 && MM-26876 Refactor post draft component (#4621)
* Refactor post draft component
Re-styled ReadOnly channels
Remove filename from upload error

* Update canSubmit based on file attachment changes

* Fix error message for max file size

* Fix select autocomplete values on iOS

* Style readonly and refactor accessory view for iOS

* Make PostDraft scrollViewNativeID prop not required

* Update ReadOnly to have a background with 0.40 opacity

* Update max file size error message

* Fix shift+enter with HW keyboard
2020-08-06 19:39:25 -04:00

134 lines
No EOL
4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import TestRenderer from 'react-test-renderer';
import {IntlProvider} from 'react-intl';
import {Provider} from 'react-redux';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import Preferences from '@mm-redux/constants/preferences';
import intitialState from '@store/initial_state';
import PostDraft from './post_draft';
const mockStore = configureMockStore([thunk]);
const state = {
...intitialState,
entities: {
...intitialState.entities,
channels: {
...intitialState.entities.channels,
channels: {
'channel-id': {
id: 'channel-id',
name: 'test-channel',
display_name: 'Display Name',
type: 'O',
},
},
channelMemberCountsByGroup: {},
},
},
device: {
...intitialState.device,
dimension: {
deviceWidth: 375,
deviceHeight: 812,
},
},
};
const store = mockStore(state);
jest.mock('react-native-image-picker', () => ({
launchCamera: jest.fn(),
}));
describe('PostDraft', () => {
const baseProps = {
canPost: true,
channelId: 'channel-id',
channelIsArchived: false,
channelIsReadOnly: false,
deactivatedChannel: false,
registerTypingAnimation: jest.fn(),
rootId: '',
screenId: 'NavigationScreen1',
theme: Preferences.THEMES.default,
};
test('Should render the DraftInput', () => {
const wrapper = renderWithRedux(
<PostDraft
{...baseProps}
/>,
);
expect(wrapper.toJSON()).toMatchSnapshot();
const element = wrapper.root.find((el) => el.type === 'TextInput');
expect(element).toBeTruthy();
});
test('Should render the Archived for channelIsArchived', () => {
const wrapper = renderWithRedux(
<PostDraft
{...baseProps}
channelIsArchived={true}
/>,
);
expect(wrapper.toJSON()).toMatchSnapshot();
const element = wrapper.root.find((el) => el.type === 'Text' && el.children && el.children[0] === 'archived channel');
expect(element).toBeTruthy();
});
test('Should render the Archived for deactivatedChannel', () => {
const wrapper = renderWithRedux(
<PostDraft
{...baseProps}
deactivatedChannel={true}
/>,
);
expect(wrapper.toJSON()).toMatchSnapshot();
const element = wrapper.root.find((el) => el.type === 'Text' && el.children && el.children[0] === 'archived channel');
expect(element).toBeTruthy();
});
test('Should render the ReadOnly for channelIsReadOnly', () => {
const wrapper = renderWithRedux(
<PostDraft
{...baseProps}
channelIsReadOnly={true}
/>,
);
expect(wrapper.toJSON()).toMatchSnapshot();
const element = wrapper.root.find((el) => el.type === 'Text' && el.children && el.children[0] === 'This channel is read-only.');
expect(element).toBeTruthy();
});
test('Should render the ReadOnly for canPost', () => {
const wrapper = renderWithRedux(
<PostDraft
{...baseProps}
canPost={false}
/>,
);
expect(wrapper.toJSON()).toMatchSnapshot();
const element = wrapper.root.find((el) => el.type === 'Text' && el.children && el.children[0] === 'This channel is read-only.');
expect(element).toBeTruthy();
});
});
function renderWithRedux(component) {
return TestRenderer.create(
<Provider store={store}>
<IntlProvider locale='en'>
{component}
</IntlProvider>
</Provider>,
);
}