mattermost-mobile/app/components/post_draft/post_draft.test.js
Joseph Baylon 5f6fd6df7a
MM-30286 Detox/E2E: Add e2e test for MM-T3236 and added basic unit tests (#4969)
* MM-30286 Detox/E2E: Add e2e test for MM-T3236

* Fix more testID hierarchies

* Fix typo

* Fix failing test

* Remove extra lines

* Updated to use string interpolation

* Update channels list element query

* Updated channel item unit test to be more consistent

* Fix error text testID hierarchies; fix edit channel info testIDs

* Fix snap file

* Fix line return
2020-11-24 16:58:09 +08:00

150 lines
4.6 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 = {
testID: 'post_draft',
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_draft.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_draft.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_draft.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_draft.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_draft.post.input')).toBeNull();
// Should match text description
expect(getByText('This channel is read-only.')).toBeTruthy();
expect(queryByText('Close Channel')).toBeNull();
});
});