diff --git a/webapp/channels/src/components/post_view/combined_system_message/__snapshots__/last_users.test.tsx.snap b/webapp/channels/src/components/post_view/combined_system_message/__snapshots__/last_users.test.tsx.snap
deleted file mode 100644
index a2fa0cb748..0000000000
--- a/webapp/channels/src/components/post_view/combined_system_message/__snapshots__/last_users.test.tsx.snap
+++ /dev/null
@@ -1,74 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`components/post_view/combined_system_message/LastUsers should match snapshot 1`] = `
-
-
-
- 2 others
-
-
-
-`;
-
-exports[`components/post_view/combined_system_message/LastUsers should match snapshot, expanded 1`] = `
-
-`;
diff --git a/webapp/channels/src/components/post_view/combined_system_message/last_users.test.tsx b/webapp/channels/src/components/post_view/combined_system_message/last_users.test.tsx
index dd07b32151..c4bd1c8030 100644
--- a/webapp/channels/src/components/post_view/combined_system_message/last_users.test.tsx
+++ b/webapp/channels/src/components/post_view/combined_system_message/last_users.test.tsx
@@ -5,9 +5,11 @@ import React from 'react';
import {Posts} from 'mattermost-redux/constants';
-import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
-
import LastUsers from './last_users';
+import {renderWithIntlAndStore} from 'tests/react_testing_utils';
+import {screen} from '@testing-library/react';
+import {TestHelper} from 'utils/test_helper';
+import userEvent from '@testing-library/user-event';
describe('components/post_view/combined_system_message/LastUsers', () => {
const formatOptions = {
@@ -26,31 +28,75 @@ describe('components/post_view/combined_system_message/LastUsers', () => {
usernames: ['@username2', '@username3', '@username4 '],
};
- test('should match snapshot', () => {
- const wrapper = shallowWithIntl(
- ,
+ const initialState = {
+ entities: {
+ general: {config: {}},
+ users: {
+ currentUserId: 'current_user_id',
+ profiles: {
+ user_1: TestHelper.getUserMock({}),
+ },
+ },
+ groups: {groups: {}, myGroups: []},
+ emojis: {customEmoji: {}},
+ channels: {},
+ teams: {
+ teams: {},
+ },
+ preferences: {
+ myPreferences: {},
+ },
+ },
+ } as any;
+
+ test('should match component state', () => {
+ renderWithIntlAndStore(
+ , initialState,
);
- expect(wrapper).toMatchSnapshot();
+ expect(screen.getByText(getMentionKeyAt(0))).toBeInTheDocument();
+ expect(screen.getByText(getMentionKeyAt(0))).toHaveAttribute('data-mention', 'username2');
+
+ expect(screen.getByText('and')).toBeInTheDocument();
+
+ //there are 3 mention keys, so the text should read
+ userEvent.click(screen.getByText(`${formatOptions.mentionKeys.length - 1} others`));
+
+ expect(screen.getByText('added to the channel')).toBeInTheDocument();
+ expect(screen.getByText(`by ${baseProps.actor}`, {exact: false})).toBeInTheDocument();
});
- test('should match snapshot, expanded', () => {
- const wrapper = shallowWithIntl(
- ,
+ test('should match component state, expanded', () => {
+ renderWithIntlAndStore(
+ , initialState,
);
- wrapper.setState({expand: true});
- expect(wrapper).toMatchSnapshot();
+ //first key should be visible
+ expect(screen.getByText(getMentionKeyAt(0))).toBeInTheDocument();
+ expect(screen.getByText(getMentionKeyAt(0))).toHaveAttribute('data-mention', 'username2');
+
+ //other keys should be hidden
+ expect(screen.queryByText(getMentionKeyAt(1))).not.toBeInTheDocument();
+ expect(screen.queryByText(getMentionKeyAt(2))).not.toBeInTheDocument();
+ expect(screen.getByText('were', {exact: false})).toBeInTheDocument();
+
+ //setting {expand: true} in the state
+ userEvent.click(screen.getByText(`${formatOptions.mentionKeys.length - 1} others`));
+
+ expect(screen.queryByText('were', {exact: false})).not.toBeInTheDocument();
+
+ //hidden keys should be visible
+ expect(screen.getByText(getMentionKeyAt(1))).toBeInTheDocument();
+ expect(screen.getByText(getMentionKeyAt(1))).toHaveAttribute('data-mention', 'username3');
+
+ expect(screen.getByText(getMentionKeyAt(2))).toBeInTheDocument();
+ expect(screen.getByText(getMentionKeyAt(2))).toHaveAttribute('data-mention', 'username4');
+
+ expect(screen.getByText('added to the channel')).toBeInTheDocument();
+ expect(screen.getByText(`by ${baseProps.actor}`, {exact: false})).toBeInTheDocument();
});
- test('should match state on handleOnClick', () => {
- const wrapper = shallowWithIntl(
- ,
- );
-
- wrapper.setState({expand: false});
- const e = {preventDefault: jest.fn()};
- wrapper.find('a').simulate('click', e);
- expect(wrapper.state('expand')).toBe(true);
- });
+ function getMentionKeyAt(index: number) {
+ return baseProps.formatOptions.mentionKeys[index].key;
+ }
});
diff --git a/webapp/channels/src/components/post_view/commented_on_files_message/__snapshots__/commented_on_files_message.test.tsx.snap b/webapp/channels/src/components/post_view/commented_on_files_message/__snapshots__/commented_on_files_message.test.tsx.snap
deleted file mode 100644
index 88a84ae137..0000000000
--- a/webapp/channels/src/components/post_view/commented_on_files_message/__snapshots__/commented_on_files_message.test.tsx.snap
+++ /dev/null
@@ -1,24 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`components/CommentedOnFilesMessage Snapshot when no files 1`] = `""`;
-
-exports[`components/CommentedOnFilesMessage should match snapshot for multiple files 1`] = `
-
- image_3.png
-
-
-`;
-
-exports[`components/CommentedOnFilesMessage should match snapshot for single file 1`] = `
-
- image_1.png
-
-`;
diff --git a/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.test.tsx b/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.test.tsx
index d8a376f041..af69fa34e8 100644
--- a/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.test.tsx
+++ b/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.test.tsx
@@ -2,37 +2,38 @@
// See LICENSE.txt for license information.
import React from 'react';
-import {shallow} from 'enzyme';
import CommentedOnFilesMessage from './commented_on_files_message';
+import {render, screen} from '@testing-library/react';
+import {renderWithIntl} from 'tests/react_testing_utils';
describe('components/CommentedOnFilesMessage', () => {
const baseProps = {
parentPostId: 'parentPostId',
};
- test('Snapshot when no files', () => {
- const wrapper = shallow(
+ test('component state when no files', () => {
+ render(
,
);
- expect(wrapper).toMatchSnapshot();
+ //no file is given in props
+ expect(screen.queryByTestId('fileInfo')).not.toBeInTheDocument();
});
- test('should match snapshot for single file', () => {
+ test('should match component state for single file', () => {
const props = {
...baseProps,
fileInfos: [{id: 'file_id_1', name: 'image_1.png', extension: 'png', create_at: 1}],
};
- const wrapper = shallow(
+ render(
,
);
-
- expect(wrapper).toMatchSnapshot();
+ expect(screen.getByTestId('fileInfo')).toHaveTextContent('image_1.png');
});
- test('should match snapshot for multiple files', () => {
+ test('should match component state for multiple files', () => {
const fileInfos = [
{id: 'file_id_3', name: 'image_3.png', extension: 'png', create_at: 3},
{id: 'file_id_2', name: 'image_2.png', extension: 'png', create_at: 2},
@@ -44,10 +45,11 @@ describe('components/CommentedOnFilesMessage', () => {
fileInfos,
};
- const wrapper = shallow(
+ renderWithIntl(
,
);
- expect(wrapper).toMatchSnapshot();
+ // total files = 3
+ expect(screen.getByTestId('fileInfo')).toHaveTextContent('image_3.png plus 2 other files');
});
});
diff --git a/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.tsx b/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.tsx
index 01a6562668..60b3e001e5 100644
--- a/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.tsx
+++ b/webapp/channels/src/components/post_view/commented_on_files_message/commented_on_files_message.tsx
@@ -37,7 +37,7 @@ export default class CommentedOnFilesMessage extends React.PureComponent
}
return (
-
+
{this.props.fileInfos[0].name}
{plusMore}
diff --git a/webapp/channels/src/components/post_view/date_separator/__snapshots__/date_separator.test.tsx.snap b/webapp/channels/src/components/post_view/date_separator/__snapshots__/date_separator.test.tsx.snap
deleted file mode 100644
index 56022df6ca..0000000000
--- a/webapp/channels/src/components/post_view/date_separator/__snapshots__/date_separator.test.tsx.snap
+++ /dev/null
@@ -1,35 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`components/post_view/DateSeparator should render Timestamp inside of a BasicSeparator and pass date/value to it 1`] = `
-
- ,
- "equals": Array [
- "day",
- 0,
- ],
- },
- Object {
- "display": ,
- "equals": Array [
- "day",
- -1,
- ],
- },
- ]
- }
- useSemanticOutput={false}
- useTime={false}
- value={2018-01-12T08:15:13.000Z}
- />
-
-`;
diff --git a/webapp/channels/src/components/post_view/date_separator/date_separator.test.tsx b/webapp/channels/src/components/post_view/date_separator/date_separator.test.tsx
index e390ac2910..0f78fdd86a 100644
--- a/webapp/channels/src/components/post_view/date_separator/date_separator.test.tsx
+++ b/webapp/channels/src/components/post_view/date_separator/date_separator.test.tsx
@@ -3,24 +3,31 @@
import React from 'react';
-import {shallow} from 'enzyme';
-
-import BasicSeparator from 'components/widgets/separator/basic-separator';
import DateSeparator from 'components/post_view/date_separator/date_separator';
-import Timestamp from 'components/timestamp';
+import {screen} from '@testing-library/react';
+import {renderWithIntlAndStore} from 'tests/react_testing_utils';
describe('components/post_view/DateSeparator', () => {
+ const initialState = {
+ entities: {
+ general: {
+ config: {},
+ },
+ preferences: {
+ myPreferences: {},
+ },
+ },
+ } as any;
test('should render Timestamp inside of a BasicSeparator and pass date/value to it', () => {
const value = new Date('Fri Jan 12 2018 20:15:13 GMT+1200 (+12)');
- const wrapper = shallow(
+ renderWithIntlAndStore(
,
+ />, initialState,
);
- expect(wrapper).toMatchSnapshot();
- expect(wrapper.find(BasicSeparator).exists());
+ expect(screen.getByTestId('basicSeparator')).toBeInTheDocument();
- expect(wrapper.find(Timestamp).prop('value')).toBe(value);
+ expect(screen.getByText('January 12, 2018')).toBeInTheDocument();
});
});
diff --git a/webapp/channels/src/components/post_view/embedded_bindings/button_binding/__snapshots__/button_binding.test.tsx.snap b/webapp/channels/src/components/post_view/embedded_bindings/button_binding/__snapshots__/button_binding.test.tsx.snap
deleted file mode 100644
index 41e0f97158..0000000000
--- a/webapp/channels/src/components/post_view/embedded_bindings/button_binding/__snapshots__/button_binding.test.tsx.snap
+++ /dev/null
@@ -1,23 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`components/post_view/embedded_bindings/button_binding/ should match snapshot 1`] = `
-
-`;
diff --git a/webapp/channels/src/components/post_view/embedded_bindings/button_binding/button_binding.test.tsx b/webapp/channels/src/components/post_view/embedded_bindings/button_binding/button_binding.test.tsx
index 930fdf65f3..dc7eb9e269 100644
--- a/webapp/channels/src/components/post_view/embedded_bindings/button_binding/button_binding.test.tsx
+++ b/webapp/channels/src/components/post_view/embedded_bindings/button_binding/button_binding.test.tsx
@@ -2,16 +2,15 @@
// See LICENSE.txt for license information.
import React from 'react';
-import {shallow} from 'enzyme';
import {AppBinding, AppCallResponse} from '@mattermost/types/apps';
import {Post} from '@mattermost/types/posts';
-import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
-
import ButtonBinding, {ButtonBinding as ButtonBindingUnwrapped} from './button_binding';
-
+import {renderWithIntlAndStore} from 'tests/react_testing_utils';
+import {screen, waitFor} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
describe('components/post_view/embedded_bindings/button_binding/', () => {
const post = {
id: 'some_post_id',
@@ -58,15 +57,35 @@ describe('components/post_view/embedded_bindings/button_binding/', () => {
},
};
+ const initialState = {
+ entities: {
+ general: {config: {}},
+ users: {
+ profiles: {
+ },
+ },
+ groups: {myGroups: []},
+ emojis: {},
+ channels: {},
+ teams: {
+ teams: {},
+ },
+ preferences: {
+ myPreferences: {},
+ },
+ },
+ };
+
const intl = {
formatMessage: (message: {id: string; defaultMessage: string}) => {
return message.defaultMessage;
},
} as any;
- test('should match snapshot', () => {
- const wrapper = shallowWithIntl();
- expect(wrapper).toMatchSnapshot();
+ test('should match default component state', () => {
+ renderWithIntlAndStore(, initialState);
+
+ screen.getByText('some_label');
});
test('should call doAppSubmit on click', async () => {
@@ -75,18 +94,24 @@ describe('components/post_view/embedded_bindings/button_binding/', () => {
intl,
};
- const wrapper = shallow();
- await wrapper.instance().handleClick();
+ renderWithIntlAndStore(, initialState);
+
+ screen.getByText('some_label');
+
+ const submitButton = screen.getByRole('button');
+ userEvent.click(submitButton);
expect(baseProps.actions.getChannel).toHaveBeenCalledWith('some_channel_id');
- expect(baseProps.actions.handleBindingClick).toHaveBeenCalledWith(binding, {
- app_id: 'some_app_id',
- channel_id: 'some_channel_id',
- location: '/in_post/some_location',
- post_id: 'some_post_id',
- root_id: 'some_root_id',
- team_id: 'some_team_id',
- }, expect.anything());
+ await waitFor(() => {
+ expect(baseProps.actions.handleBindingClick).toHaveBeenCalledWith(binding, {
+ app_id: 'some_app_id',
+ channel_id: 'some_channel_id',
+ location: '/in_post/some_location',
+ post_id: 'some_post_id',
+ root_id: 'some_root_id',
+ team_id: 'some_team_id',
+ }, expect.anything());
+ });
expect(baseProps.actions.postEphemeralCallResponseForPost).toHaveBeenCalledWith(callResponse, 'Nice job!', post);
});
@@ -118,9 +143,15 @@ describe('components/post_view/embedded_bindings/button_binding/', () => {
intl,
};
- const wrapper = shallow();
- await wrapper.instance().handleClick();
+ renderWithIntlAndStore(, initialState);
- expect(props.actions.postEphemeralCallResponseForPost).toHaveBeenCalledWith(errorCallResponse, 'The error', post);
+ screen.getByText('some_label');
+
+ const submitButton = screen.getByRole('button');
+ userEvent.click(submitButton);
+
+ await waitFor(() => {
+ expect(props.actions.postEphemeralCallResponseForPost).toHaveBeenCalledWith(errorCallResponse, 'The error', post);
+ });
});
});
diff --git a/webapp/channels/src/components/post_view/failed_post_options/__snapshots__/failed_post_options.test.tsx.snap b/webapp/channels/src/components/post_view/failed_post_options/__snapshots__/failed_post_options.test.tsx.snap
deleted file mode 100644
index 4454f009d5..0000000000
--- a/webapp/channels/src/components/post_view/failed_post_options/__snapshots__/failed_post_options.test.tsx.snap
+++ /dev/null
@@ -1,29 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`components/post_view/FailedPostOptions should match snapshot 1`] = `
-
-
-
-
- -
-
-
-
-
-`;
diff --git a/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.test.tsx b/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.test.tsx
index aa37a28a35..9f508dc2bf 100644
--- a/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.test.tsx
+++ b/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.test.tsx
@@ -2,11 +2,13 @@
// See LICENSE.txt for license information.
import React from 'react';
-import {shallow} from 'enzyme';
import {TestHelper} from 'utils/test_helper';
import FailedPostOptions from 'components/post_view/failed_post_options/failed_post_options';
+import {renderWithIntl} from 'tests/react_testing_utils';
+import {screen} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
describe('components/post_view/FailedPostOptions', () => {
const baseProps = {
@@ -17,9 +19,21 @@ describe('components/post_view/FailedPostOptions', () => {
},
};
- test('should match snapshot', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ test('should match default component state', () => {
+ renderWithIntl();
+
+ const retryLink = screen.getByText('Retry');
+ const cancelLink = screen.getByText('Cancel');
+
+ expect(retryLink).toBeInTheDocument();
+ expect(retryLink).toHaveClass('post-retry');
+ expect(retryLink).toHaveAttribute('href', '#');
+
+ expect(cancelLink).toBeInTheDocument();
+ expect(cancelLink).toHaveClass('post-cancel');
+ expect(cancelLink).toHaveAttribute('href', '#');
+
+ expect(screen.getAllByRole('link')).toHaveLength(2);
});
test('should create post on retry', () => {
@@ -31,13 +45,16 @@ describe('components/post_view/FailedPostOptions', () => {
},
};
- const wrapper = shallow();
- const e = {preventDefault: jest.fn()};
+ renderWithIntl();
+
+ const retryLink = screen.getByText('Retry');
+
+ userEvent.click(retryLink);
- wrapper.find('.post-retry').simulate('click', e);
expect(props.actions.createPost.mock.calls.length).toBe(1);
- wrapper.find('.post-retry').simulate('click', e);
+ userEvent.click(retryLink);
+
expect(props.actions.createPost.mock.calls.length).toBe(2);
});
@@ -50,10 +67,12 @@ describe('components/post_view/FailedPostOptions', () => {
},
};
- const wrapper = shallow();
- const e = {preventDefault: jest.fn()};
+ renderWithIntl();
+
+ const cancelLink = screen.getByText('Cancel');
+
+ userEvent.click(cancelLink);
- wrapper.find('.post-cancel').simulate('click', e);
expect(props.actions.removePost.mock.calls.length).toBe(1);
});
});