mattermost-mobile/app/components/post_draft/post_draft.test.js
Saturnino Abril a819f63d99
MM-30076 Detox/E2E: Update UI test structure for reusability (#4931)
* update UI test structure for reusability

* fix Android tests

* improve autocomplete test

* minor cleanup
2020-11-03 18:11:49 +08:00

149 lines
4.5 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
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 {renderWithReduxIntl} from 'test/testing_library';
import PostDraft from './post_draft';
jest.mock('app/components/compass_icon', () => 'Icon');
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);
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 {getByTestId, queryByText, toJSON} = renderWithReduxIntl(
<PostDraft
{...baseProps}
/>,
store,
);
expect(toJSON()).toMatchSnapshot();
expect(getByTestId('post.input')).toBeTruthy();
expect(queryByText('Close Channel')).toBeNull();
});
test('Should render the Archived for channelIsArchived', () => {
const {queryByTestId, getByText, toJSON} = renderWithReduxIntl(
<PostDraft
{...baseProps}
channelIsArchived={true}
/>,
store,
);
expect(toJSON()).toMatchSnapshot();
// Should not render text input
expect(queryByTestId('post.input')).toBeNull();
// Should match text description
expect(getByText('You are viewing an ')).toBeTruthy();
expect(getByText('archived channel')).toBeTruthy();
expect(getByText('. New messages cannot be posted.')).toBeTruthy();
expect(getByText('Close Channel')).toBeTruthy();
});
test('Should render the Archived for deactivatedChannel', () => {
const {queryByTestId, getByText, toJSON} = renderWithReduxIntl(
<PostDraft
{...baseProps}
deactivatedChannel={true}
/>,
store,
);
expect(toJSON()).toMatchSnapshot();
// Should not render text input
expect(queryByTestId('post.input')).toBeNull();
// Should match text description
expect(getByText('You are viewing an ')).toBeTruthy();
expect(getByText('archived channel')).toBeTruthy();
expect(getByText('. New messages cannot be posted.')).toBeTruthy();
expect(getByText('Close Channel')).toBeTruthy();
});
test('Should render the ReadOnly for channelIsReadOnly', () => {
const {queryByTestId, getByText, queryByText, toJSON} = renderWithReduxIntl(
<PostDraft
{...baseProps}
channelIsReadOnly={true}
/>,
store,
);
expect(toJSON()).toMatchSnapshot();
// Should not render text input
expect(queryByTestId('post.input')).toBeNull();
// Should match text description
expect(getByText('This channel is read-only.')).toBeTruthy();
expect(queryByText('Close Channel')).toBeNull();
});
test('Should render the ReadOnly for canPost', () => {
const {queryByTestId, getByText, queryByText, toJSON} = renderWithReduxIntl(
<PostDraft
{...baseProps}
canPost={false}
/>,
store,
);
expect(toJSON()).toMatchSnapshot();
// Should not render text input
expect(queryByTestId('post.input')).toBeNull();
// Should match text description
expect(getByText('This channel is read-only.')).toBeTruthy();
expect(queryByText('Close Channel')).toBeNull();
});
});