level_0
int64 0
10k
| index
int64 0
0
| repo_id
stringlengths 22
152
| file_path
stringlengths 41
203
| content
stringlengths 11
11.5M
|
---|---|---|---|---|
2,043 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delete_channel_modal/delete_channel_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Modal} from 'react-bootstrap';
import type {Channel, ChannelType} from '@mattermost/types/channels';
import DeleteChannelModal from 'components/delete_channel_modal/delete_channel_modal';
import type {Props} from 'components/delete_channel_modal/delete_channel_modal';
import {getHistory} from 'utils/browser_history';
describe('components/delete_channel_modal', () => {
const channel: Channel = {
id: 'owsyt8n43jfxjpzh9np93mx1wa',
create_at: 1508265709607,
update_at: 1508265709607,
delete_at: 0,
team_id: 'eatxocwc3bg9ffo9xyybnj4omr',
type: 'O' as ChannelType,
display_name: 'testing',
name: 'testing',
header: 'test',
purpose: 'test',
last_post_at: 1508265709635,
last_root_post_at: 1508265709635,
creator_id: 'zaktnt8bpbgu8mb6ez9k64r7sa',
scheme_id: '',
group_constrained: false,
};
const currentTeamDetails = {
name: 'mattermostDev',
};
const baseProps: Props = {
channel,
currentTeamDetails,
actions: {
deleteChannel: jest.fn(() => {
return {data: true};
}),
},
onExited: jest.fn(),
penultimateViewedChannelName: 'my-prev-channel',
};
test('should match snapshot for delete_channel_modal', () => {
const wrapper = shallow(
<DeleteChannelModal {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match state when onHide is called', () => {
const wrapper = shallow<DeleteChannelModal>(
<DeleteChannelModal {...baseProps}/>,
);
wrapper.setState({show: true});
wrapper.instance().onHide();
expect(wrapper.state('show')).toEqual(false);
});
test('should have called actions.deleteChannel when handleDelete is called', () => {
const actions = {deleteChannel: jest.fn()};
const props = {...baseProps, actions};
const wrapper = shallow<DeleteChannelModal>(
<DeleteChannelModal {...props}/>,
);
wrapper.setState({show: true});
wrapper.instance().handleDelete();
expect(actions.deleteChannel).toHaveBeenCalledTimes(1);
expect(actions.deleteChannel).toHaveBeenCalledWith(props.channel.id);
expect(getHistory().push).toHaveBeenCalledWith('/mattermostDev/channels/my-prev-channel');
expect(wrapper.state('show')).toEqual(false);
});
test('should have called props.onExited when Modal.onExited is called', () => {
const wrapper = shallow(
<DeleteChannelModal {...baseProps}/>,
);
wrapper.find(Modal).props().onExited!(document.createElement('div'));
expect(baseProps.onExited).toHaveBeenCalledTimes(1);
});
});
|
2,046 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delete_channel_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delete_channel_modal/__snapshots__/delete_channel_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/delete_channel_modal should match snapshot for delete_channel_modal 1`] = `
<Modal
animation={true}
aria-labelledby="deleteChannelModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="deleteChannelModal"
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="deleteChannelModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Confirm ARCHIVE Channel"
id="delete_channel.confirm"
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<div
className="alert alert-danger"
>
<FormattedMarkdownMessage
defaultMessage="This will archive the channel from the team and remove it from the user interface. Archived channels can be unarchived if needed again. \\\\n \\\\nAre you sure you wish to archive the {display_name} channel?"
id="delete_channel.question"
values={
Object {
"display_name": "testing",
}
}
/>
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="delete_channel.cancel"
/>
</button>
<button
autoFocus={true}
className="btn btn-danger"
data-dismiss="modal"
id="deleteChannelModalDeleteButton"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Archive"
id="delete_channel.del"
/>
</button>
</ModalFooter>
</Modal>
`;
|
2,047 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delete_post_modal/delete_post_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Modal} from 'react-bootstrap';
import type {PostType, PostMetadata} from '@mattermost/types/posts';
import DeletePostModal from 'components/delete_post_modal/delete_post_modal';
import {getHistory} from 'utils/browser_history';
describe('components/delete_post_modal', () => {
const post = {
id: '123',
message: 'test',
channel_id: '5',
type: '' as PostType,
root_id: '',
create_at: 0,
update_at: 0,
edit_at: 0,
delete_at: 0,
is_pinned: false,
user_id: '',
original_id: '',
props: {} as Record<string, any>,
hashtags: '',
pending_post_id: '',
reply_count: 0,
metadata: {} as PostMetadata,
};
const baseProps = {
post,
commentCount: 0,
isRHS: false,
actions: {
deleteAndRemovePost: jest.fn(),
},
onExited: jest.fn(),
channelName: 'channel_name',
teamName: 'team_name',
location: {
pathname: '',
},
};
test('should match snapshot for delete_post_modal with 0 comments', () => {
const wrapper = shallow(
<DeletePostModal {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot for delete_post_modal with 1 comment', () => {
const commentCount = 1;
const props = {...baseProps, commentCount};
const wrapper = shallow(
<DeletePostModal {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot for post with 1 commentCount and is not rootPost', () => {
const commentCount = 1;
const postObj = {
...post,
root_id: '1234',
};
const props = {
...baseProps,
commentCount,
post: postObj,
};
const wrapper = shallow(
<DeletePostModal {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should focus delete button on enter', () => {
const wrapper = shallow<DeletePostModal>(
<DeletePostModal {...baseProps}/>,
);
const deletePostBtn = {
current: {
focus: jest.fn(),
},
} as any;
wrapper.instance().deletePostBtn = deletePostBtn;
wrapper.instance().handleEntered();
expect(deletePostBtn.current.focus).toHaveBeenCalled();
});
test('should match state when onHide is called', () => {
const wrapper = shallow<DeletePostModal>(
<DeletePostModal {...baseProps}/>,
);
wrapper.setState({show: true});
wrapper.instance().onHide();
expect(wrapper.state('show')).toEqual(false);
});
test('should match state when the cancel button is clicked', () => {
const wrapper = shallow(
<DeletePostModal {...baseProps}/>,
);
wrapper.setState({show: true});
wrapper.find('button').at(0).simulate('click');
expect(wrapper.state('show')).toEqual(false);
});
test('should have called actions.deleteAndRemovePost when handleDelete is called', async () => {
const deleteAndRemovePost = jest.fn().mockReturnValueOnce({data: true});
const props = {
...baseProps,
actions: {
deleteAndRemovePost,
},
location: {
pathname: '/teamname/messages/@username',
},
};
const wrapper = shallow<DeletePostModal>(
<DeletePostModal {...props}/>,
);
wrapper.setState({show: true});
wrapper.instance().handleDelete();
await expect(deleteAndRemovePost).toHaveBeenCalledTimes(1);
expect(deleteAndRemovePost).toHaveBeenCalledWith(props.post);
expect(wrapper.state('show')).toEqual(false);
});
test('should have called browserHistory.replace when permalink post is deleted for DM/GM', async () => {
const deleteAndRemovePost = jest.fn().mockReturnValueOnce({data: true});
const props = {
...baseProps,
actions: {
deleteAndRemovePost,
},
location: {
pathname: '/teamname/messages/@username/123',
},
};
const wrapper = shallow<DeletePostModal>(
<DeletePostModal {...props}/>,
);
wrapper.setState({show: true});
wrapper.instance().handleDelete();
await expect(deleteAndRemovePost).toHaveBeenCalledTimes(1);
expect(getHistory().replace).toHaveBeenCalledWith('/teamname/messages/@username');
});
test('should have called browserHistory.replace when permalink post is deleted for a channel', async () => {
const deleteAndRemovePost = jest.fn().mockReturnValueOnce({data: true});
const props = {
...baseProps,
actions: {
deleteAndRemovePost,
},
location: {
pathname: '/teamname/channels/channelName/123',
},
};
const wrapper = shallow<DeletePostModal>(
<DeletePostModal {...props}/>,
);
wrapper.setState({show: true});
wrapper.instance().handleDelete();
await expect(deleteAndRemovePost).toHaveBeenCalledTimes(1);
expect(getHistory().replace).toHaveBeenCalledWith('/teamname/channels/channelName');
});
test('should have called props.onExiteed when Modal.onExited is called', () => {
const wrapper = shallow(
<DeletePostModal {...baseProps}/>,
);
const modalProps = wrapper.find(Modal).first().props();
if (modalProps.onExited) {
modalProps.onExited(document.createElement('div'));
}
expect(baseProps.onExited).toHaveBeenCalledTimes(1);
});
});
|
2,050 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delete_post_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delete_post_modal/__snapshots__/delete_post_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/delete_post_modal should match snapshot for delete_post_modal with 0 comments 1`] = `
<Modal
animation={true}
aria-labelledby="deletePostModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="deletePostModal"
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntered={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="deletePostModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Confirm {term} Delete"
id="delete_post.confirm"
values={
Object {
"term": <Memo(MemoizedFormattedMessage)
defaultMessage="Post"
id="delete_post.post"
/>,
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to delete this {term}?"
id="delete_post.question"
values={
Object {
"term": <Memo(MemoizedFormattedMessage)
defaultMessage="Post"
id="delete_post.post"
/>,
}
}
/>
<br />
<br />
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="delete_post.cancel"
/>
</button>
<button
autoFocus={true}
className="btn btn-danger"
id="deletePostModalButton"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Delete"
id="delete_post.del"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`components/delete_post_modal should match snapshot for delete_post_modal with 1 comment 1`] = `
<Modal
animation={true}
aria-labelledby="deletePostModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="deletePostModal"
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntered={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="deletePostModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Confirm {term} Delete"
id="delete_post.confirm"
values={
Object {
"term": <Memo(MemoizedFormattedMessage)
defaultMessage="Post"
id="delete_post.post"
/>,
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to delete this {term}?"
id="delete_post.question"
values={
Object {
"term": <Memo(MemoizedFormattedMessage)
defaultMessage="Post"
id="delete_post.post"
/>,
}
}
/>
<br />
<br />
<MemoizedFormattedMessage
defaultMessage="This post has {count, number} {count, plural, one {comment} other {comments}} on it."
id="delete_post.warning"
values={
Object {
"count": 1,
}
}
/>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="delete_post.cancel"
/>
</button>
<button
autoFocus={true}
className="btn btn-danger"
id="deletePostModalButton"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Delete"
id="delete_post.del"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`components/delete_post_modal should match snapshot for post with 1 commentCount and is not rootPost 1`] = `
<Modal
animation={true}
aria-labelledby="deletePostModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="deletePostModal"
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntered={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="deletePostModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Confirm {term} Delete"
id="delete_post.confirm"
values={
Object {
"term": <Memo(MemoizedFormattedMessage)
defaultMessage="Comment"
id="delete_post.comment"
/>,
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to delete this {term}?"
id="delete_post.question"
values={
Object {
"term": <Memo(MemoizedFormattedMessage)
defaultMessage="Comment"
id="delete_post.comment"
/>,
}
}
/>
<br />
<br />
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="delete_post.cancel"
/>
</button>
<button
autoFocus={true}
className="btn btn-danger"
id="deletePostModalButton"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Delete"
id="delete_post.del"
/>
</button>
</ModalFooter>
</Modal>
`;
|
2,052 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delinquency_modal/delinquency_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {ComponentProps} from 'react';
import {savePreferences} from 'mattermost-redux/actions/preferences';
import {trackEvent} from 'actions/telemetry_actions';
import {fireEvent, renderWithContext, screen} from 'tests/react_testing_utils';
import {ModalIdentifiers, Preferences, TELEMETRY_CATEGORIES} from 'utils/constants';
import DelinquencyModal from './delinquency_modal';
jest.mock('mattermost-redux/actions/preferences', () => ({
savePreferences: jest.fn(),
}));
jest.mock('actions/telemetry_actions', () => ({
trackEvent: jest.fn(),
}));
jest.mock('actions/views/modals', () => ({
openModal: jest.fn(),
}));
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useDispatch: jest.fn().mockReturnValue(() => {}),
}));
describe('components/deliquency_modal/deliquency_modal', () => {
const initialState = {
views: {
modals: {
modalState: {
[ModalIdentifiers.DELINQUENCY_MODAL_DOWNGRADE]: {
open: true,
dialogProps: {
planName: 'plan_name',
onExited: () => {},
closeModal: () => {},
isAdminConsole: false,
},
dialogType: React.Fragment as any,
},
},
showLaunchingWorkspace: false,
},
},
entities: {
users: {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'system_admin', id: 'test'},
},
},
},
};
const baseProps: ComponentProps<typeof DelinquencyModal> = {
closeModal: jest.fn(),
onExited: jest.fn(),
planName: 'planName',
isAdminConsole: false,
};
it('should save preferences and track stayOnFremium if admin click Stay on Free', () => {
renderWithContext(<DelinquencyModal {...baseProps}/>, initialState);
fireEvent.click(screen.getByText('Stay on Free'));
expect(savePreferences).toBeCalledTimes(1);
expect(savePreferences).toBeCalledWith(initialState.entities.users.profiles.current_user_id.id, [{
category: Preferences.DELINQUENCY_MODAL_CONFIRMED,
name: ModalIdentifiers.DELINQUENCY_MODAL_DOWNGRADE,
user_id: initialState.entities.users.profiles.current_user_id.id,
value: 'stayOnFremium',
}]);
expect(trackEvent).toBeCalledTimes(1);
expect(trackEvent).toBeCalledWith(TELEMETRY_CATEGORIES.CLOUD_DELINQUENCY, 'clicked_stay_on_freemium');
});
it('should save preferences and track update Billing if admin click Update Billing', () => {
renderWithContext(<DelinquencyModal {...baseProps}/>, initialState);
fireEvent.click(screen.getByText('Update Billing'));
expect(savePreferences).toBeCalledTimes(1);
expect(savePreferences).toBeCalledWith(initialState.entities.users.profiles.current_user_id.id, [{
category: Preferences.DELINQUENCY_MODAL_CONFIRMED,
name: ModalIdentifiers.DELINQUENCY_MODAL_DOWNGRADE,
user_id: initialState.entities.users.profiles.current_user_id.id,
value: 'updateBilling',
}]);
expect(trackEvent).toBeCalledTimes(2);
expect(trackEvent).toHaveBeenNthCalledWith(1, TELEMETRY_CATEGORIES.CLOUD_DELINQUENCY, 'clicked_update_billing');
expect(trackEvent).toHaveBeenNthCalledWith(2, TELEMETRY_CATEGORIES.CLOUD_ADMIN, 'click_open_delinquency_modal', {
callerInfo: 'delinquency_modal_downgrade_admin',
});
});
});
|
2,054 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delinquency_modal/delinquency_modal_controller.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {DeepPartial} from '@mattermost/types/utilities';
import * as cloudActions from 'mattermost-redux/actions/cloud';
import * as StorageSelectors from 'selectors/storage';
import ModalController from 'components/modal_controller';
import {renderWithContext, screen} from 'tests/react_testing_utils';
import {CloudProducts, ModalIdentifiers, Preferences} from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import type {GlobalState} from 'types/store';
import DelinquencyModalController from './index';
jest.mock('selectors/storage');
(StorageSelectors.makeGetItem as jest.Mock).mockReturnValue(() => false);
describe('components/delinquency_modal/delinquency_modal_controller', () => {
const initialState: DeepPartial<GlobalState> = {
views: {
modals: {
modalState: {},
},
},
entities: {
general: {
license: {
IsLicensed: 'true',
Cloud: 'true',
},
},
preferences: {
myPreferences: {},
},
users: {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'system_admin'},
},
},
cloud: {
subscription: TestHelper.getSubscriptionMock({
product_id: 'test_prod_1',
trial_end_at: 1652807380,
is_free_trial: 'false',
delinquent_since: 1652807380, // may 17 2022
}),
products: {
test_prod_1: TestHelper.getProductMock({
id: 'test_prod_1',
sku: CloudProducts.STARTER,
price_per_seat: 0,
name: 'testProd1',
}),
test_prod_2: TestHelper.getProductMock({
id: 'test_prod_2',
sku: CloudProducts.ENTERPRISE,
price_per_seat: 0,
name: 'testProd2',
}),
test_prod_3: TestHelper.getProductMock({
id: 'test_prod_3',
sku: CloudProducts.PROFESSIONAL,
price_per_seat: 0,
name: 'testProd3',
}),
},
},
},
};
it('Should show the modal if the admin hasn\'t a preference', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).toBeInTheDocument();
});
it('Shouldn\'t show the modal if the admin has a preference', () => {
const state = JSON.parse(JSON.stringify(initialState));
state.entities.preferences.myPreferences = TestHelper.getPreferencesMock(
[
{
category: Preferences.DELINQUENCY_MODAL_CONFIRMED,
name: ModalIdentifiers.DELINQUENCY_MODAL_DOWNGRADE,
value: 'updateBilling',
},
],
);
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
state,
);
expect(screen.queryByText('Your workspace has been downgraded')).not.toBeInTheDocument();
});
it('Should show the modal if the deliquency_since is equal 90 days', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-08-16'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).toBeInTheDocument();
});
it('Should show the modal if the deliquency_since is more than 90 days', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-08-17'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).toBeInTheDocument();
});
it('Shouldn\'t show the modal if the deliqeuncy_since is less than 90 days', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-08-15'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).not.toBeInTheDocument();
});
it('Should show the modal if the license is cloud', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-08-17'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).toBeInTheDocument();
});
it('Shouldn\'t show the modal if the license isn\'t cloud', () => {
const state = JSON.parse(JSON.stringify(initialState));
state.entities.general.license = {
...state.entities.general.license,
Cloud: 'false',
};
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
state,
);
expect(screen.queryByText('Your workspace has been downgraded')).not.toBeInTheDocument();
});
it('Shouldn\'t show the modal if the subscription isn\'t in delinquency state', () => {
const state = JSON.parse(JSON.stringify(initialState));
state.entities.cloud.subscription = {
...state.entities.cloud.subscription,
delinquent_since: null,
};
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
state,
);
expect(screen.queryByText('Your workspace has been downgraded')).not.toBeInTheDocument();
});
it('Should show the modal if the user is an admin', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-08-17'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).toBeInTheDocument();
});
it('Shouldn\'t show the modal if the user isn\'t an admin', () => {
const state = JSON.parse(JSON.stringify(initialState));
state.entities.users = {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'user'},
},
};
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
state,
);
expect(screen.queryByText('Your workspace has been downgraded')).not.toBeInTheDocument();
});
it('Should show the modal if the user just logged in', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-08-17'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).toBeInTheDocument();
});
it('Shouldn\'t show the modal if we aren\'t log in', () => {
(StorageSelectors.makeGetItem as jest.Mock).mockReturnValue(() => true);
jest.useFakeTimers().setSystemTime(new Date('2022-08-17'));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
initialState,
);
expect(screen.queryByText('Your workspace has been downgraded')).not.toBeInTheDocument();
});
it('Should fetch cloud products when on cloud', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
const newState = JSON.parse(JSON.stringify(initialState));
newState.entities.cloud.products = {};
const getCloudProds = jest.spyOn(cloudActions, 'getCloudProducts').mockImplementationOnce(jest.fn().mockReturnValue({type: 'mock_impl'}));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
newState,
);
expect(getCloudProds).toHaveBeenCalledTimes(1);
});
it('Should NOT fetch cloud products when NOT on cloud', () => {
jest.useFakeTimers().setSystemTime(new Date('2022-12-20'));
const newState = JSON.parse(JSON.stringify(initialState));
newState.entities.cloud.products = {};
newState.entities.general.license = {
IsLicensed: 'true',
Cloud: 'false',
};
const getCloudProds = jest.spyOn(cloudActions, 'getCloudProducts').mockImplementationOnce(jest.fn().mockReturnValue({type: 'mock_impl'}));
renderWithContext(
<>
<div id='root-portal'/>
<ModalController/>
<DelinquencyModalController/>
</>,
newState,
);
expect(getCloudProds).toHaveBeenCalledTimes(0);
});
});
|
2,056 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/delinquency_modal/freemium_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {ComponentProps} from 'react';
import type {DeepPartial} from '@mattermost/types/utilities';
import {trackEvent} from 'actions/telemetry_actions';
import useGetMultiplesExceededCloudLimit from 'components/common/hooks/useGetMultiplesExceededCloudLimit';
import {fireEvent, renderWithContext, screen} from 'tests/react_testing_utils';
import {ModalIdentifiers, TELEMETRY_CATEGORIES} from 'utils/constants';
import {LimitTypes} from 'utils/limits';
import type {GlobalState} from 'types/store';
import {FreemiumModal} from './freemium_modal';
jest.mock('actions/telemetry_actions', () => ({
trackEvent: jest.fn(),
}));
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useDispatch: jest.fn().mockReturnValue(() => {}),
}));
jest.mock('components/common/hooks/useGetMultiplesExceededCloudLimit');
describe('components/delinquency_modal/freemium_modal', () => {
const initialState: DeepPartial<GlobalState> = {
views: {
modals: {
modalState: {
[ModalIdentifiers.DELINQUENCY_MODAL_DOWNGRADE]: {
open: true,
dialogProps: {
planName: 'plan_name',
onExited: () => {},
closeModal: () => {},
isAdminConsole: false,
},
dialogType: React.Fragment as any,
},
},
showLaunchingWorkspace: false,
},
},
entities: {
users: {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'system_admin', id: 'test'},
},
},
},
};
const planName = 'Testing';
const baseProps: ComponentProps<typeof FreemiumModal> = {
onClose: jest.fn(),
planName,
isAdminConsole: false,
onExited: jest.fn(),
};
it('should track reactivate plan if admin click Re activate plan', () => {
(useGetMultiplesExceededCloudLimit as jest.Mock).mockReturnValue([LimitTypes.fileStorage]);
renderWithContext(
<FreemiumModal {...baseProps}/>,
initialState,
);
fireEvent.click(screen.getByText(`Re-activate ${planName}`));
expect(trackEvent).toBeCalledTimes(2);
expect(trackEvent).toHaveBeenNthCalledWith(1, TELEMETRY_CATEGORIES.CLOUD_DELINQUENCY, 'clicked_re_activate_plan');
expect(trackEvent).toHaveBeenNthCalledWith(2, TELEMETRY_CATEGORIES.CLOUD_ADMIN, 'click_open_delinquency_modal', {
callerInfo: 'delinquency_modal_freemium_admin',
});
});
it('should not show reactivate plan if admin limits isn\'t surpassed', () => {
(useGetMultiplesExceededCloudLimit as jest.Mock).mockReturnValue([]);
renderWithContext(
<FreemiumModal {...baseProps}/>,
initialState,
);
expect(screen.queryByText(`Re-activate ${planName}`)).not.toBeInTheDocument();
expect(trackEvent).toBeCalledTimes(0);
});
it('should display message history text when only message limit is surpassed', () => {
(useGetMultiplesExceededCloudLimit as jest.Mock).mockReturnValue([LimitTypes.messageHistory]);
renderWithContext(
<FreemiumModal {...baseProps}/>,
initialState,
);
expect(screen.queryByText(`Re-activate ${planName}`)).toBeInTheDocument();
expect(screen.getByText('Some of your workspace\'s message history are no longer accessible. Upgrade to a paid plan and get unlimited access to your message history.')).toBeInTheDocument();
});
it('should display storage text when only storage is surpassed', () => {
(useGetMultiplesExceededCloudLimit as jest.Mock).mockReturnValue([LimitTypes.fileStorage]);
renderWithContext(
<FreemiumModal {...baseProps}/>,
initialState,
);
expect(screen.queryByText(`Re-activate ${planName}`)).toBeInTheDocument();
expect(screen.getByText('Some of your workspace\'s files are no longer accessible. Upgrade to a paid plan and get unlimited access to your files.')).toBeInTheDocument();
});
it('should display update to paid plan text when only multiples limits is surpassed', () => {
(useGetMultiplesExceededCloudLimit as jest.Mock).mockReturnValue([LimitTypes.messageHistory, LimitTypes.fileStorage]);
renderWithContext(
<FreemiumModal {...baseProps}/>,
initialState,
);
expect(screen.queryByText(`Re-activate ${planName}`)).toBeInTheDocument();
expect(screen.getByText('Your workspace has reached free plan limits. Upgrade to a paid plan.')).toBeInTheDocument();
});
});
|
2,066 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu/dot_menu.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {PostType} from '@mattermost/types/posts';
import type {DeepPartial} from '@mattermost/types/utilities';
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import {fireEvent, renderWithContext, screen} from 'tests/react_testing_utils';
import {Locations} from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import type {GlobalState} from 'types/store';
import DotMenu from './dot_menu';
import type {DotMenuClass} from './dot_menu';
jest.mock('./utils');
describe('components/dot_menu/DotMenu', () => {
const latestPost = {
id: 'latest_post_id',
user_id: 'current_user_id',
message: 'test msg',
channel_id: 'other_gm_channel',
create_at: Date.now(),
};
const initialState: DeepPartial<GlobalState> = {
entities: {
general: {
config: {},
},
channels: {
myMembers: {
current_channel_id: {
channel_id: 'current_channel_id',
user_id: 'current_user_id',
},
direct_other_user: {
channel_id: 'direct_other_user',
user_id: 'current_user_id',
roles: 'channel_role',
last_viewed_at: 10,
},
channel_other_user: {
channel_id: 'channel_other_user',
},
},
channels: {
direct_other_user: {
id: 'direct_other_user',
name: 'current_user_id__other_user',
},
},
messageCounts: {
direct_other_user: {
root: 2,
total: 2,
},
},
},
preferences: {
myPreferences: {
},
},
users: {
profiles: {
current_user_id: {roles: 'system_role'},
other_user1: TestHelper.getUserMock({
id: 'otherUserId',
username: 'UserOther',
roles: '',
email: '[email protected]',
}),
},
currentUserId: 'current_user_id',
profilesInChannel: {
current_user_id: ['user_1'],
},
},
teams: {
currentTeamId: 'currentTeamId',
teams: {
currentTeamId: {
id: 'currentTeamId',
display_name: 'test',
type: 'O',
},
},
},
posts: {
posts: {
[latestPost.id]: latestPost,
},
postsInChannel: {
other_gm_channel: [
{order: [latestPost.id], recent: true},
],
},
postsInThread: {},
},
},
views: {
browser: {
focused: false,
windowSize: 'desktopView',
},
modals: {
modalState: {},
showLaunchingWorkspace: false,
},
},
};
const baseProps = {
post: TestHelper.getPostMock({id: 'post_id_1', is_pinned: false, type: '' as PostType}),
isLicensed: false,
postEditTimeLimit: '-1',
handleCommentClick: jest.fn(),
handleDropdownOpened: jest.fn(),
enableEmojiPicker: true,
components: {},
channelIsArchived: false,
currentTeamUrl: '',
actions: {
flagPost: jest.fn(),
unflagPost: jest.fn(),
setEditingPost: jest.fn(),
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
postEphemeralCallResponseForPost: jest.fn(),
setThreadFollow: jest.fn(),
addPostReminder: jest.fn(),
setGlobalItem: jest.fn(),
},
canEdit: false,
canDelete: false,
isReadOnly: false,
teamId: 'team_id_1',
isFollowingThread: false,
isCollapsedThreadsEnabled: true,
isMobileView: false,
threadId: 'post_id_1',
threadReplyCount: 0,
userId: 'user_id_1',
isMilitaryTime: false,
};
test('should match snapshot, on Center', () => {
const props = {
...baseProps,
canEdit: true,
};
const wrapper = shallowWithIntl(
<DotMenu {...props}/>,
);
expect(wrapper).toMatchSnapshot();
const instance = wrapper.instance();
const setStateMock = jest.fn();
instance.setState = setStateMock;
(wrapper.instance() as DotMenuClass).handleEditDisable();
expect(setStateMock).toBeCalledWith({canEdit: false});
});
test('should match snapshot, canDelete', () => {
const props = {
...baseProps,
canEdit: true,
canDelete: true,
};
const wrapper = renderWithContext(
<DotMenu {...props}/>,
initialState,
);
expect(wrapper).toMatchSnapshot();
});
test('should show mark as unread when channel is not archived', () => {
const props = {
...baseProps,
location: Locations.CENTER,
};
renderWithContext(
<DotMenu {...props}/>,
initialState,
);
const button = screen.getByTestId(`PostDotMenu-Button-${baseProps.post.id}`);
fireEvent.click(button);
const menuItem = screen.getByTestId(`unread_post_${baseProps.post.id}`);
expect(menuItem).toBeVisible();
});
test('should not show mark as unread when channel is archived', () => {
const props = {
...baseProps,
channelIsArchived: true,
};
renderWithContext(
<DotMenu {...props}/>,
initialState,
);
const button = screen.getByTestId(`PostDotMenu-Button-${baseProps.post.id}`);
fireEvent.click(button);
const menuItem = screen.queryByTestId(`unread_post_${baseProps.post.id}`);
expect(menuItem).toBeNull();
});
test('should not show mark as unread in search', () => {
const props = {
...baseProps,
location: Locations.SEARCH,
};
renderWithContext(
<DotMenu {...props}/>,
initialState,
);
const button = screen.getByTestId(`PostDotMenu-Button-${baseProps.post.id}`);
fireEvent.click(button);
const menuItem = screen.queryByTestId(`unread_post_${baseProps.post.id}`);
expect(menuItem).toBeNull();
});
describe('RHS', () => {
test.each([
[true, {location: Locations.RHS_ROOT, isCollapsedThreadsEnabled: true}],
[true, {location: Locations.RHS_COMMENT, isCollapsedThreadsEnabled: true}],
[true, {location: Locations.CENTER, isCollapsedThreadsEnabled: true}],
])('follow message/thread menu item should be shown only in RHS and center channel when CRT is enabled', (showing, caseProps) => {
const props = {
...baseProps,
...caseProps,
};
renderWithContext(
<DotMenu {...props}/>,
initialState,
);
const button = screen.getByTestId(`PostDotMenu-Button-${baseProps.post.id}`);
fireEvent.click(button);
const menuItem = screen.getByTestId(`follow_post_thread_${baseProps.post.id}`);
expect(menuItem).toBeVisible();
});
test.each([
[false, {location: Locations.RHS_ROOT, isCollapsedThreadsEnabled: false}],
[false, {location: Locations.RHS_COMMENT, isCollapsedThreadsEnabled: false}],
[false, {location: Locations.CENTER, isCollapsedThreadsEnabled: false}],
[false, {location: Locations.SEARCH, isCollapsedThreadsEnabled: true}],
[false, {location: Locations.NO_WHERE, isCollapsedThreadsEnabled: true}],
])('follow message/thread menu item should be shown only in RHS and center channel when CRT is enabled', (showing, caseProps) => {
const props = {
...baseProps,
...caseProps,
};
renderWithContext(
<DotMenu {...props}/>,
initialState,
);
const button = screen.getByTestId(`PostDotMenu-Button-${baseProps.post.id}`);
fireEvent.click(button);
const menuItem = screen.queryByTestId(`follow_post_thread_${baseProps.post.id}`);
expect(menuItem).toBeNull();
});
test.each([
['Follow message', {isFollowingThread: false, threadReplyCount: 0}],
['Unfollow message', {isFollowingThread: true, threadReplyCount: 0}],
['Follow thread', {isFollowingThread: false, threadReplyCount: 1}],
['Unfollow thread', {isFollowingThread: true, threadReplyCount: 1}],
])('should show correct text', (text, caseProps) => {
const props = {
...baseProps,
...caseProps,
location: Locations.RHS_ROOT,
};
renderWithContext(
<DotMenu {...props}/>,
initialState,
);
const button = screen.getByTestId(`PostDotMenu-Button-${baseProps.post.id}`);
fireEvent.click(button);
const menuItem = screen.getByTestId(`follow_post_thread_${baseProps.post.id}`);
expect(menuItem).toBeVisible();
expect(menuItem).toHaveTextContent(text);
});
});
});
|
2,068 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu/dot_menu_empty.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import DotMenu from 'components/dot_menu/dot_menu';
import {TestHelper} from 'utils/test_helper';
jest.mock('utils/utils', () => {
return {
localizeMessage: jest.fn().mockReturnValue(''),
};
});
jest.mock('utils/post_utils', () => {
const original = jest.requireActual('utils/post_utils');
return {
...original,
isSystemMessage: jest.fn(() => true),
};
});
describe('components/dot_menu/DotMenu returning empty ("")', () => {
test('should match snapshot, return empty ("") on Center', () => {
const baseProps = {
post: TestHelper.getPostMock({id: 'post_id_1'}),
isLicensed: false,
postEditTimeLimit: '-1',
handleCommentClick: jest.fn(),
handleDropdownOpened: jest.fn(),
enableEmojiPicker: true,
components: {},
channelIsArchived: false,
currentTeamUrl: '',
actions: {
flagPost: jest.fn(),
unflagPost: jest.fn(),
setEditingPost: jest.fn(),
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
handleBindingClick: jest.fn(),
postEphemeralCallResponseForPost: jest.fn(),
setThreadFollow: jest.fn(),
addPostReminder: jest.fn(),
setGlobalItem: jest.fn(),
},
canEdit: false,
canDelete: false,
appBindings: [],
pluginMenuItems: [],
appsEnabled: false,
isMobileView: false,
isReadOnly: false,
isCollapsedThreadsEnabled: false,
teamId: '',
threadId: 'post_id_1',
userId: 'user_id_1',
isMilitaryTime: false,
};
const wrapper = shallow(
<DotMenu {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,069 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu/dot_menu_mobile.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import DotMenu from 'components/dot_menu/dot_menu';
import {TestHelper} from 'utils/test_helper';
jest.mock('utils/utils', () => {
return {
localizeMessage: jest.fn(),
};
});
jest.mock('utils/post_utils', () => {
const original = jest.requireActual('utils/post_utils');
return {
...original,
isSystemMessage: jest.fn(() => true),
};
});
describe('components/dot_menu/DotMenu on mobile view', () => {
test('should match snapshot', () => {
const baseProps = {
post: TestHelper.getPostMock({id: 'post_id_1'}),
isLicensed: false,
postEditTimeLimit: '-1',
handleCommentClick: jest.fn(),
handleDropdownOpened: jest.fn(),
enableEmojiPicker: true,
components: {},
channelIsArchived: false,
currentTeamUrl: '',
actions: {
flagPost: jest.fn(),
unflagPost: jest.fn(),
setEditingPost: jest.fn(),
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
handleBindingClick: jest.fn(),
postEphemeralCallResponseForPost: jest.fn(),
setThreadFollow: jest.fn(),
addPostReminder: jest.fn(),
setGlobalItem: jest.fn(),
},
canEdit: false,
canDelete: false,
appBindings: [],
pluginMenuItems: [],
appsEnabled: false,
isMobileView: true,
isReadOnly: false,
isCollapsedThreadsEnabled: false,
teamId: '',
threadId: 'post_id_1',
userId: 'user_id_1',
isMilitaryTime: false,
};
const wrapper = shallow(
<DotMenu {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,073 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu/__snapshots__/dot_menu.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/dot_menu/DotMenu should match snapshot, canDelete 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<button
aria-controls="CENTER_dropdown_post_id_1"
aria-expanded="false"
aria-haspopup="true"
aria-label="more"
class="post-menu__item"
data-testid="PostDotMenu-Button-post_id_1"
id="CENTER_button_post_id_1"
>
<svg
fill="currentColor"
height="16"
version="1.1"
viewBox="0 0 24 24"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16,12A2,2 0 0,1 18,10A2,2 0 0,1 20,12A2,2 0 0,1 18,14A2,2 0 0,1 16,12M10,12A2,2 0 0,1 12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12M4,12A2,2 0 0,1 6,10A2,2 0 0,1 8,12A2,2 0 0,1 6,14A2,2 0 0,1 4,12Z"
/>
</svg>
</button>
</div>
</body>,
"container": <div>
<button
aria-controls="CENTER_dropdown_post_id_1"
aria-expanded="false"
aria-haspopup="true"
aria-label="more"
class="post-menu__item"
data-testid="PostDotMenu-Button-post_id_1"
id="CENTER_button_post_id_1"
>
<svg
fill="currentColor"
height="16"
version="1.1"
viewBox="0 0 24 24"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16,12A2,2 0 0,1 18,10A2,2 0 0,1 20,12A2,2 0 0,1 18,14A2,2 0 0,1 16,12M10,12A2,2 0 0,1 12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12M4,12A2,2 0 0,1 6,10A2,2 0 0,1 8,12A2,2 0 0,1 6,14A2,2 0 0,1 4,12Z"
/>
</svg>
</button>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"replaceStoreState": [Function],
"rerender": [Function],
"unmount": [Function],
"updateStoreState": [Function],
}
`;
exports[`components/dot_menu/DotMenu should match snapshot, on Center 1`] = `
<Menu
menu={
Object {
"aria-label": "Post extra options",
"id": "CENTER_dropdown_post_id_1",
"onKeyDown": [Function],
"onToggle": [Function],
"width": "264px",
}
}
menuButton={
Object {
"aria-label": "more",
"children": <DotsHorizontalIcon
size={16}
/>,
"class": "post-menu__item",
"dateTestId": "PostDotMenu-Button-post_id_1",
"id": "CENTER_button_post_id_1",
}
}
menuButtonTooltip={
Object {
"class": "hidden-xs",
"id": "PostDotMenu-ButtonTooltip-post_id_1",
"text": "More",
}
}
>
<MenuItem
data-testid="reply_to_post_post_id_1"
id="reply_to_post_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Reply"
id="post_info.reply"
/>
}
leadingElement={
<ReplyOutlineIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="R"
/>
}
/>
<MenuItem
data-testid="forward_post_post_id_1"
id="forward_post_post_id_1"
isLabelsRowLayout={true}
labels={
<span
className="dot-menu__item-new-badge"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Forward"
id="forward_post_button.label"
/>
</span>
}
leadingElement={
<ArrowRightBoldOutlineIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="Shift + F"
/>
}
/>
<MenuItem
data-testid="follow_post_thread_post_id_1"
id="follow_post_thread_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Follow message"
id="threading.threadMenu.followMessage"
/>
}
leadingElement={
<MessageCheckOutlineIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="F"
/>
}
/>
<MenuItem
data-testid="unread_post_post_id_1"
id="unread_post_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Mark as Unread"
id="post_info.unread"
/>
}
leadingElement={
<MarkAsUnreadIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="U"
/>
}
/>
<Memo(PostReminderSubmenu)
isMilitaryTime={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "post_id_1",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "",
"update_at": 0,
"user_id": "user_id",
}
}
userId="user_id_1"
/>
<MenuItem
data-testid="save_post_post_id_1"
id="save_post_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Save"
id="rhs_root.mobile.flag"
/>
}
leadingElement={
<BookmarkOutlineIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="S"
/>
}
/>
<MenuItem
data-testid="pin_post_post_id_1"
id="pin_post_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Pin"
id="post_info.pin"
/>
}
leadingElement={
<PinOutlineIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="P"
/>
}
/>
<MenuItemSeparator />
<MenuItem
data-testid="permalink_post_id_1"
id="permalink_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Copy Link"
id="post_info.permalink"
/>
}
leadingElement={
<LinkVariantIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="K"
/>
}
/>
<MenuItemSeparator />
<MenuItem
data-testid="edit_post_post_id_1"
id="edit_post_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Edit"
id="post_info.edit"
/>
}
leadingElement={
<PencilOutlineIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="E"
/>
}
/>
<MenuItem
data-testid="copy_post_id_1"
id="copy_post_id_1"
labels={
<Memo(MemoizedFormattedMessage)
defaultMessage="Copy Text"
id="post_info.copy"
/>
}
leadingElement={
<ContentCopyIcon
size={18}
/>
}
onClick={[Function]}
trailingElements={
<ShortcutKey
shortcutKey="C"
/>
}
/>
</Menu>
`;
|
2,074 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu/__snapshots__/dot_menu_empty.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/dot_menu/DotMenu returning empty ("") should match snapshot, return empty ("") on Center 1`] = `
<ContextConsumer>
<Component />
</ContextConsumer>
`;
|
2,075 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu | petrpan-code/mattermost/mattermost/webapp/channels/src/components/dot_menu/__snapshots__/dot_menu_mobile.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/dot_menu/DotMenu on mobile view should match snapshot 1`] = `
<ContextConsumer>
<Component />
</ContextConsumer>
`;
|
2,078 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_row.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import type {UserProfile, UserStatus} from '@mattermost/types/users';
import type {Draft} from 'selectors/drafts';
import mockStore from 'tests/test_store';
import DraftRow from './draft_row';
describe('components/drafts/drafts_row', () => {
const baseProps = {
draft: {
type: 'channel',
} as Draft,
user: {} as UserProfile,
status: {} as UserStatus['status'],
displayName: 'test',
isRemote: false,
};
it('should match snapshot for channel draft', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<DraftRow
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for thread draft', () => {
const store = mockStore();
const props = {
...baseProps,
draft: {
...baseProps.draft,
type: 'thread',
} as Draft,
};
const wrapper = shallow(
<Provider store={store}>
<DraftRow
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,081 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/drafts.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import type {UserProfile, UserStatus} from '@mattermost/types/users';
import type {Draft} from 'selectors/drafts';
import mockStore from 'tests/test_store';
import Drafts from './drafts';
describe('components/drafts/drafts', () => {
const baseProps = {
drafts: [] as Draft[],
user: {} as UserProfile,
displayName: 'display_name',
status: {} as UserStatus['status'],
draftRemotes: {},
};
it('should match snapshot', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<Drafts
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for local drafts disabled', () => {
const store = mockStore();
const props = {
...baseProps,
};
const wrapper = shallow(
<Provider store={store}>
<Drafts
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,085 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/__snapshots__/draft_row.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/drafts_row should match snapshot for channel draft 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftRow)
displayName="test"
draft={
Object {
"type": "channel",
}
}
isRemote={false}
status={Object {}}
user={Object {}}
/>
</ContextProvider>
`;
exports[`components/drafts/drafts_row should match snapshot for thread draft 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftRow)
displayName="test"
draft={
Object {
"type": "thread",
}
}
isRemote={false}
status={Object {}}
user={Object {}}
/>
</ContextProvider>
`;
|
2,086 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/__snapshots__/drafts.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/drafts should match snapshot 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(Drafts)
displayName="display_name"
draftRemotes={Object {}}
drafts={Array []}
status={Object {}}
user={Object {}}
/>
</ContextProvider>
`;
exports[`components/drafts/drafts should match snapshot for local drafts disabled 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(Drafts)
displayName="display_name"
draftRemotes={Object {}}
drafts={Array []}
status={Object {}}
user={Object {}}
/>
</ContextProvider>
`;
|
2,087 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/channel_draft/channel_draft.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import type {Channel} from '@mattermost/types/channels';
import type {UserProfile, UserStatus} from '@mattermost/types/users';
import mockStore from 'tests/test_store';
import type {PostDraft} from 'types/store/draft';
import ChannelDraft from './channel_draft';
describe('components/drafts/drafts_row', () => {
const baseProps = {
channel: {
id: '',
} as Channel,
channelUrl: '',
displayName: '',
draftId: '',
id: {} as Channel['id'],
status: {} as UserStatus['status'],
type: 'channel' as 'channel' | 'thread',
user: {} as UserProfile,
value: {} as PostDraft,
postPriorityEnabled: false,
isRemote: false,
};
it('should match snapshot for channel draft', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<ChannelDraft
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for undefined channel', () => {
const store = mockStore();
const props = {
...baseProps,
channel: null as unknown as Channel,
};
const wrapper = shallow(
<Provider store={store}>
<ChannelDraft
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,090 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/channel_draft | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/channel_draft/__snapshots__/channel_draft.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/drafts_row should match snapshot for channel draft 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(ChannelDraft)
channel={
Object {
"id": "",
}
}
channelUrl=""
displayName=""
draftId=""
id={Object {}}
isRemote={false}
postPriorityEnabled={false}
status={Object {}}
type="channel"
user={Object {}}
value={Object {}}
/>
</ContextProvider>
`;
exports[`components/drafts/drafts_row should match snapshot for undefined channel 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(ChannelDraft)
channel={null}
channelUrl=""
displayName=""
draftId=""
id={Object {}}
isRemote={false}
postPriorityEnabled={false}
status={Object {}}
type="channel"
user={Object {}}
value={Object {}}
/>
</ContextProvider>
`;
|
2,092 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/action.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import Action from './action';
describe('components/drafts/draft_actions/action', () => {
const baseProps = {
icon: '',
id: '',
name: '',
onClick: jest.fn(),
tooltipText: '',
};
it('should match snapshot', () => {
const wrapper = shallow(
<Action
{...baseProps}
/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,094 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/delete_draft_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import {GenericModal} from '@mattermost/components';
import mockStore from 'tests/test_store';
import DeleteDraftModal from './delete_draft_modal';
describe('components/drafts/draft_actions/delete_draft_modal', () => {
const baseProps = {
displayName: 'display_name',
onConfirm: jest.fn(),
onExited: jest.fn(),
};
it('should match snapshot', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<DeleteDraftModal
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should have called onConfirm', () => {
const wrapper = shallow(
<DeleteDraftModal {...baseProps}/>,
);
wrapper.find(GenericModal).first().props().handleConfirm!();
expect(baseProps.onConfirm).toHaveBeenCalledTimes(1);
expect(wrapper).toMatchSnapshot();
});
it('should have called onExited', () => {
const wrapper = shallow(
<DeleteDraftModal {...baseProps}/>,
);
wrapper.find(GenericModal).first().props().onExited();
expect(baseProps.onExited).toHaveBeenCalledTimes(1);
expect(wrapper).toMatchSnapshot();
});
});
|
2,096 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/draft_actions.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import mockStore from 'tests/test_store';
import DraftActions from './draft_actions';
describe('components/drafts/draft_actions', () => {
const baseProps = {
displayName: '',
draftId: '',
onDelete: jest.fn(),
onEdit: jest.fn(),
onSend: jest.fn(),
};
it('should match snapshot', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<DraftActions
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,099 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/send_draft_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import {GenericModal} from '@mattermost/components';
import mockStore from 'tests/test_store';
import SendDraftModal from './send_draft_modal';
describe('components/drafts/draft_actions/send_draft_modal', () => {
const baseProps = {
displayName: 'display_name',
onConfirm: jest.fn(),
onExited: jest.fn(),
};
it('should match snapshot', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<SendDraftModal
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should have called onConfirm', () => {
const wrapper = shallow(
<SendDraftModal {...baseProps}/>,
);
wrapper.find(GenericModal).first().props().handleConfirm!();
expect(baseProps.onConfirm).toHaveBeenCalledTimes(1);
expect(wrapper).toMatchSnapshot();
});
it('should have called onExited', () => {
const wrapper = shallow(
<SendDraftModal {...baseProps}/>,
);
wrapper.find(GenericModal).first().props().onExited();
expect(baseProps.onExited).toHaveBeenCalledTimes(1);
expect(wrapper).toMatchSnapshot();
});
});
|
2,101 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/__snapshots__/action.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/draft_actions/action should match snapshot 1`] = `
<div
className="DraftAction"
>
<OverlayTrigger
className="hidden-xs"
defaultOverlayShown={false}
delayShow={400}
overlay={
<Tooltip
bsClass="tooltip"
className="hidden-xs"
id="tooltip_"
placement="right"
>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="DraftAction__button"
id="draft_{icon}_"
onClick={[MockFunction]}
>
<i
className="icon "
/>
</button>
</OverlayTrigger>
</div>
`;
|
2,102 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/__snapshots__/delete_draft_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/draft_actions/delete_draft_modal should have called onConfirm 1`] = `
<GenericModal
autoCloseOnCancelButton={true}
autoCloseOnConfirmButton={true}
bodyPadding={true}
compassDesign={true}
confirmButtonText="Yes, delete"
enforceFocus={true}
handleCancel={[Function]}
handleConfirm={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
}
id="genericModal"
isDeleteModal={true}
keyboardEscape={true}
modalHeaderText="Delete draft"
onExited={[MockFunction]}
show={true}
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to delete this draft to <strong>{displayName}</strong>?"
id="drafts.confirm.delete.text"
values={
Object {
"displayName": "display_name",
"strong": [Function],
}
}
/>
</GenericModal>
`;
exports[`components/drafts/draft_actions/delete_draft_modal should have called onExited 1`] = `
<GenericModal
autoCloseOnCancelButton={true}
autoCloseOnConfirmButton={true}
bodyPadding={true}
compassDesign={true}
confirmButtonText="Yes, delete"
enforceFocus={true}
handleCancel={[Function]}
handleConfirm={[MockFunction]}
id="genericModal"
isDeleteModal={true}
keyboardEscape={true}
modalHeaderText="Delete draft"
onExited={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
}
show={true}
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to delete this draft to <strong>{displayName}</strong>?"
id="drafts.confirm.delete.text"
values={
Object {
"displayName": "display_name",
"strong": [Function],
}
}
/>
</GenericModal>
`;
exports[`components/drafts/draft_actions/delete_draft_modal should match snapshot 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<DeleteDraftModal
displayName="display_name"
onConfirm={[MockFunction]}
onExited={[MockFunction]}
/>
</ContextProvider>
`;
|
2,103 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/__snapshots__/draft_actions.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/draft_actions should match snapshot 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftActions)
displayName=""
draftId=""
onDelete={[MockFunction]}
onEdit={[MockFunction]}
onSend={[MockFunction]}
/>
</ContextProvider>
`;
|
2,104 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_actions/__snapshots__/send_draft_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/draft_actions/send_draft_modal should have called onConfirm 1`] = `
<GenericModal
autoCloseOnCancelButton={true}
autoCloseOnConfirmButton={true}
bodyPadding={true}
compassDesign={true}
confirmButtonText="Yes, send now"
enforceFocus={true}
handleCancel={[Function]}
handleConfirm={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
}
id="genericModal"
keyboardEscape={true}
modalHeaderText="Send message now"
onExited={[MockFunction]}
show={true}
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to send this message to <strong>{displayName}</strong>?"
id="drafts.confirm.send.text"
values={
Object {
"displayName": "display_name",
"strong": [Function],
}
}
/>
</GenericModal>
`;
exports[`components/drafts/draft_actions/send_draft_modal should have called onExited 1`] = `
<GenericModal
autoCloseOnCancelButton={true}
autoCloseOnConfirmButton={true}
bodyPadding={true}
compassDesign={true}
confirmButtonText="Yes, send now"
enforceFocus={true}
handleCancel={[Function]}
handleConfirm={[MockFunction]}
id="genericModal"
keyboardEscape={true}
modalHeaderText="Send message now"
onExited={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
}
show={true}
>
<MemoizedFormattedMessage
defaultMessage="Are you sure you want to send this message to <strong>{displayName}</strong>?"
id="drafts.confirm.send.text"
values={
Object {
"displayName": "display_name",
"strong": [Function],
}
}
/>
</GenericModal>
`;
exports[`components/drafts/draft_actions/send_draft_modal should match snapshot 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<SendDraftModal
displayName="display_name"
onConfirm={[MockFunction]}
onExited={[MockFunction]}
/>
</ContextProvider>
`;
|
2,106 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_title/draft_title.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import type {Channel} from '@mattermost/types/channels';
import type {UserProfile} from '@mattermost/types/users';
import mockStore from 'tests/test_store';
import Constants from 'utils/constants';
import DraftTitle from './draft_title';
describe('components/drafts/draft_actions', () => {
const baseProps = {
channelType: '' as Channel['type'],
channelName: '',
membersCount: 5,
selfDraft: false,
teammate: {} as UserProfile,
teammateId: '',
type: '' as 'channel' | 'thread',
};
it('should match snapshot', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for self draft', () => {
const store = mockStore();
const props = {
...baseProps,
selfDraft: true,
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for private channel', () => {
const store = mockStore();
const props = {
...baseProps,
channelType: Constants.PRIVATE_CHANNEL as Channel['type'],
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for DM channel', () => {
const store = mockStore();
const props = {
...baseProps,
channelType: Constants.DM_CHANNEL as Channel['type'],
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for DM channel with teammate', () => {
const store = mockStore();
const props = {
...baseProps,
channelType: Constants.DM_CHANNEL as Channel['type'],
teammate: {
username: 'username',
id: 'id',
last_picture_update: 1000,
} as UserProfile,
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for GM channel', () => {
const store = mockStore();
const props = {
...baseProps,
channelType: Constants.GM_CHANNEL as Channel['type'],
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for thread', () => {
const store = mockStore();
const props = {
...baseProps,
channelType: Constants.OPEN_CHANNEL as Channel['type'],
type: 'thread' as 'channel' | 'thread',
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for open channel', () => {
const store = mockStore();
const props = {
...baseProps,
channelType: Constants.OPEN_CHANNEL as Channel['type'],
type: 'channel' as 'channel' | 'thread',
};
const wrapper = shallow(
<Provider store={store}>
<DraftTitle
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,109 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_title | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/draft_title/__snapshots__/draft_title.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/draft_actions should match snapshot 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType=""
membersCount={5}
selfDraft={false}
teammate={Object {}}
teammateId=""
type=""
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for DM channel 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType="D"
membersCount={5}
selfDraft={false}
teammate={Object {}}
teammateId=""
type=""
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for DM channel with teammate 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType="D"
membersCount={5}
selfDraft={false}
teammate={
Object {
"id": "id",
"last_picture_update": 1000,
"username": "username",
}
}
teammateId=""
type=""
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for GM channel 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType="G"
membersCount={5}
selfDraft={false}
teammate={Object {}}
teammateId=""
type=""
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for open channel 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType="O"
membersCount={5}
selfDraft={false}
teammate={Object {}}
teammateId=""
type="channel"
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for private channel 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType="P"
membersCount={5}
selfDraft={false}
teammate={Object {}}
teammateId=""
type=""
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for self draft 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType=""
membersCount={5}
selfDraft={true}
teammate={Object {}}
teammateId=""
type=""
/>
</ContextProvider>
`;
exports[`components/drafts/draft_actions should match snapshot for thread 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftTitle)
channelName=""
channelType="O"
membersCount={5}
selfDraft={false}
teammate={Object {}}
teammateId=""
type="thread"
/>
</ContextProvider>
`;
|
2,111 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/drafts_link/drafts_link.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import mockStore from 'tests/test_store';
import DraftsLink from './drafts_link';
describe('components/drafts/drafts_link', () => {
it('should match snapshot', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<DraftsLink/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,113 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/drafts_link | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/drafts_link/__snapshots__/drafts_link.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/drafts_link should match snapshot 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(DraftsLink) />
</ContextProvider>
`;
|
2,116 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel/panel.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import Panel from './panel';
describe('components/drafts/panel/', () => {
const baseProps = {
children: jest.fn(),
onClick: jest.fn(),
};
it('should match snapshot', () => {
const wrapper = shallow(
<Panel
{...baseProps}
/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,119 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel/panel_body.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Provider} from 'react-redux';
import {PostPriority} from '@mattermost/types/posts';
import type {UserProfile, UserStatus} from '@mattermost/types/users';
import {mountWithIntl} from 'tests/helpers/intl-test-helper';
import mockStore from 'tests/test_store';
import * as utils from 'utils/utils';
import type {PostDraft} from 'types/store/draft';
import PanelBody from './panel_body';
describe('components/drafts/panel/panel_body', () => {
const baseProps = {
channelId: 'channel_id',
displayName: 'display_name',
fileInfos: [] as PostDraft['fileInfos'],
message: 'message',
status: 'status' as UserStatus['status'],
uploadsInProgress: [] as PostDraft['uploadsInProgress'],
userId: 'user_id' as UserProfile['id'],
username: 'username' as UserProfile['username'],
};
const initialState = {
entities: {
general: {
config: {},
},
posts: {
posts: {
root_id: {id: 'root_id', channel_id: 'channel_id'},
},
},
channels: {
currentChannelId: 'channel_id',
channels: {
channel_id: {id: 'channel_id', team_id: 'team_id'},
},
},
preferences: {
myPreferences: {},
},
groups: {
groups: {},
myGroups: [],
},
emojis: {
customEmoji: {},
},
users: {
currentUserId: 'userid1',
profiles: {userid1: {id: 'userid1', username: 'username1', roles: 'system_user'}},
profilesInChannel: {},
},
teams: {
currentTeamId: 'team_id',
teams: {
team_id: {
id: 'team_id',
name: 'team-id',
display_name: 'Team ID',
},
},
},
},
};
it('should match snapshot', () => {
const store = mockStore(initialState);
const wrapper = mountWithIntl(
<Provider store={store}>
<PanelBody
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for requested_ack', () => {
const store = mockStore(initialState);
const wrapper = mountWithIntl(
<Provider store={store}>
<PanelBody
{...baseProps}
priority={{
priority: '',
requested_ack: true,
}}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for priority', () => {
const store = mockStore(initialState);
const wrapper = mountWithIntl(
<Provider store={store}>
<PanelBody
{...baseProps}
priority={{
priority: PostPriority.IMPORTANT,
requested_ack: false,
}}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should have called handleFormattedTextClick', () => {
const handleClickSpy = jest.spyOn(utils, 'handleFormattedTextClick');
const store = mockStore(initialState);
const wrapper = mountWithIntl(
<Provider store={store}>
<PanelBody
{...baseProps}
/>
</Provider>,
);
wrapper.find('div.post__content').simulate('click');
expect(handleClickSpy).toHaveBeenCalledTimes(1);
expect(wrapper).toMatchSnapshot();
});
});
|
2,122 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel/panel_header.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import OverlayTrigger from 'components/overlay_trigger';
import PanelHeader from './panel_header';
describe('components/drafts/panel/panel_header', () => {
const baseProps = {
actions: <div>{'actions'}</div>,
hover: false,
timestamp: 12345,
remote: false,
title: <div>{'title'}</div>,
};
it('should match snapshot', () => {
const wrapper = shallow(
<PanelHeader
{...baseProps}
/>,
);
expect(wrapper.find('div.PanelHeader__actions').hasClass('PanelHeader__actions show')).toBe(false);
expect(wrapper.find(OverlayTrigger).exists()).toBe(false);
expect(wrapper).toMatchSnapshot();
});
it('should show sync icon when draft is from server', () => {
const props = {
...baseProps,
remote: true,
};
const wrapper = shallow(
<PanelHeader
{...props}
/>,
);
expect(wrapper.find(OverlayTrigger).exists()).toBe(true);
expect(wrapper).toMatchSnapshot();
});
it('should show draft actions when hovered', () => {
const props = {
...baseProps,
hover: true,
};
const wrapper = shallow(
<PanelHeader
{...props}
/>,
);
expect(wrapper.find('div.PanelHeader__actions').hasClass('PanelHeader__actions show')).toBe(true);
expect(wrapper).toMatchSnapshot();
});
});
|
2,124 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel/__snapshots__/panel.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/panel/ should match snapshot 1`] = `
<article
className="Panel"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
role="button"
/>
`;
|
2,125 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel/__snapshots__/panel_body.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/panel/panel_body should have called handleFormattedTextClick 1`] = `
<Provider
store={
Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<PanelBody
channelId="channel_id"
displayName="display_name"
fileInfos={Array []}
message="message"
status="status"
uploadsInProgress={Array []}
userId="user_id"
username="username"
>
<div
className="DraftPanelBody post"
>
<div
className="DraftPanelBody__left post__img"
>
<ProfilePicture
channelId="channel_id"
hasMention={false}
isEmoji={false}
popoverPlacement="right"
size="md"
src="/api/v4/users/user_id/image?_=0"
status="status"
userId="user_id"
username="username"
wrapperClass=""
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<Memo(Connect(injectIntl(ProfilePopover)))
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<OverlayWrapper
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
intl={
Object {
"$t": [Function],
"defaultFormats": Object {},
"defaultLocale": "en",
"defaultRichTextElements": undefined,
"fallbackOnEmptyString": true,
"formatDate": [Function],
"formatDateTimeRange": [Function],
"formatDateToParts": [Function],
"formatDisplayName": [Function],
"formatList": [Function],
"formatListToParts": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatNumberToParts": [Function],
"formatPlural": [Function],
"formatRelativeTime": [Function],
"formatTime": [Function],
"formatTimeToParts": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getDisplayNames": [Function],
"getListFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralRules": [Function],
"getRelativeTimeFormat": [Function],
},
"locale": "en",
"messages": Object {},
"onError": [Function],
"onWarn": [Function],
"textComponent": "span",
"timeZone": "Etc/UTC",
"wrapRichTextChunksInFragment": undefined,
}
}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<span
className="status-wrapper "
onClick={[Function]}
>
<RoundButton
className="style--none"
size="md"
>
<button
className="RoundButton-dvlhqG gfRzmz style--none"
size="md"
>
<span
className="profile-icon "
>
<Memo(Avatar)
size="md"
tabIndex={-1}
url="/api/v4/users/user_id/image?_=0"
username="username"
>
<img
alt="username profile image"
className="Avatar Avatar-md"
loading="lazy"
onError={[Function]}
src="/api/v4/users/user_id/image?_=0"
tabIndex={-1}
/>
</Memo(Avatar)>
</span>
</button>
</RoundButton>
<StatusIcon
button={false}
className=""
status="status"
>
<StatusOfflineIcon
className="status "
>
<span
className="status "
>
<svg
aria-label="Offline Icon"
className="offline--icon"
height="100%"
role="img"
style={
Object {
"clipRule": "evenodd",
"fillRule": "evenodd",
"strokeLinejoin": "round",
"strokeMiterlimit": 1.41421,
}
}
viewBox="0 0 20 20"
width="100%"
>
<path
d="M10,0c5.519,0 10,4.481 10,10c0,5.519 -4.481,10 -10,10c-5.519,0 -10,-4.481 -10,-10c0,-5.519 4.481,-10 10,-10Zm0,2c4.415,0 8,3.585 8,8c0,4.415 -3.585,8 -8,8c-4.415,0 -8,-3.585 -8,-8c0,-4.415 3.585,-8 8,-8Z"
/>
</svg>
</span>
</StatusOfflineIcon>
</StatusIcon>
</span>
</OverlayTrigger>
</OverlayTrigger>
</ProfilePicture>
</div>
<div
className="post__content"
onClick={[Function]}
>
<div
className="DraftPanelBody__right"
>
<div
className="post__header"
>
<strong>
display_name
</strong>
</div>
<div
className="post__body"
>
<Connect(Markdown)
message="message"
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
>
<Markdown
autolinkedUrlSchemes={
Array [
"http",
"https",
"ftp",
"mailto",
"tel",
"mattermost",
]
}
channelNamesMap={Object {}}
dispatch={[Function]}
emojiMap={
EmojiMap {
"customEmojis": Map {},
"customEmojisArray": Array [],
}
}
enableFormatting={true}
hasImageProxy={false}
managedResourcePaths={Array []}
mentionKeys={Array []}
message="message"
minimumHashtagLength={NaN}
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
siteURL="http://localhost:8065"
team={
Object {
"display_name": "Team ID",
"id": "team_id",
"name": "team-id",
}
}
>
<p
key="0"
>
message
</p>
</Markdown>
</Connect(Markdown)>
</div>
</div>
</div>
</div>
</PanelBody>
</Provider>
`;
exports[`components/drafts/panel/panel_body should match snapshot 1`] = `
<Provider
store={
Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<PanelBody
channelId="channel_id"
displayName="display_name"
fileInfos={Array []}
message="message"
status="status"
uploadsInProgress={Array []}
userId="user_id"
username="username"
>
<div
className="DraftPanelBody post"
>
<div
className="DraftPanelBody__left post__img"
>
<ProfilePicture
channelId="channel_id"
hasMention={false}
isEmoji={false}
popoverPlacement="right"
size="md"
src="/api/v4/users/user_id/image?_=0"
status="status"
userId="user_id"
username="username"
wrapperClass=""
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<Memo(Connect(injectIntl(ProfilePopover)))
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<OverlayWrapper
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
intl={
Object {
"$t": [Function],
"defaultFormats": Object {},
"defaultLocale": "en",
"defaultRichTextElements": undefined,
"fallbackOnEmptyString": true,
"formatDate": [Function],
"formatDateTimeRange": [Function],
"formatDateToParts": [Function],
"formatDisplayName": [Function],
"formatList": [Function],
"formatListToParts": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatNumberToParts": [Function],
"formatPlural": [Function],
"formatRelativeTime": [Function],
"formatTime": [Function],
"formatTimeToParts": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getDisplayNames": [Function],
"getListFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralRules": [Function],
"getRelativeTimeFormat": [Function],
},
"locale": "en",
"messages": Object {},
"onError": [Function],
"onWarn": [Function],
"textComponent": "span",
"timeZone": "Etc/UTC",
"wrapRichTextChunksInFragment": undefined,
}
}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<span
className="status-wrapper "
onClick={[Function]}
>
<RoundButton
className="style--none"
size="md"
>
<button
className="RoundButton-dvlhqG gfRzmz style--none"
size="md"
>
<span
className="profile-icon "
>
<Memo(Avatar)
size="md"
tabIndex={-1}
url="/api/v4/users/user_id/image?_=0"
username="username"
>
<img
alt="username profile image"
className="Avatar Avatar-md"
loading="lazy"
onError={[Function]}
src="/api/v4/users/user_id/image?_=0"
tabIndex={-1}
/>
</Memo(Avatar)>
</span>
</button>
</RoundButton>
<StatusIcon
button={false}
className=""
status="status"
>
<StatusOfflineIcon
className="status "
>
<span
className="status "
>
<svg
aria-label="Offline Icon"
className="offline--icon"
height="100%"
role="img"
style={
Object {
"clipRule": "evenodd",
"fillRule": "evenodd",
"strokeLinejoin": "round",
"strokeMiterlimit": 1.41421,
}
}
viewBox="0 0 20 20"
width="100%"
>
<path
d="M10,0c5.519,0 10,4.481 10,10c0,5.519 -4.481,10 -10,10c-5.519,0 -10,-4.481 -10,-10c0,-5.519 4.481,-10 10,-10Zm0,2c4.415,0 8,3.585 8,8c0,4.415 -3.585,8 -8,8c-4.415,0 -8,-3.585 -8,-8c0,-4.415 3.585,-8 8,-8Z"
/>
</svg>
</span>
</StatusOfflineIcon>
</StatusIcon>
</span>
</OverlayTrigger>
</OverlayTrigger>
</ProfilePicture>
</div>
<div
className="post__content"
onClick={[Function]}
>
<div
className="DraftPanelBody__right"
>
<div
className="post__header"
>
<strong>
display_name
</strong>
</div>
<div
className="post__body"
>
<Connect(Markdown)
message="message"
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
>
<Markdown
autolinkedUrlSchemes={
Array [
"http",
"https",
"ftp",
"mailto",
"tel",
"mattermost",
]
}
channelNamesMap={Object {}}
dispatch={[Function]}
emojiMap={
EmojiMap {
"customEmojis": Map {},
"customEmojisArray": Array [],
}
}
enableFormatting={true}
hasImageProxy={false}
managedResourcePaths={Array []}
mentionKeys={Array []}
message="message"
minimumHashtagLength={NaN}
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
siteURL="http://localhost:8065"
team={
Object {
"display_name": "Team ID",
"id": "team_id",
"name": "team-id",
}
}
>
<p
key="0"
>
message
</p>
</Markdown>
</Connect(Markdown)>
</div>
</div>
</div>
</div>
</PanelBody>
</Provider>
`;
exports[`components/drafts/panel/panel_body should match snapshot for priority 1`] = `
<Provider
store={
Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<PanelBody
channelId="channel_id"
displayName="display_name"
fileInfos={Array []}
message="message"
priority={
Object {
"priority": "important",
"requested_ack": false,
}
}
status="status"
uploadsInProgress={Array []}
userId="user_id"
username="username"
>
<div
className="DraftPanelBody post"
>
<div
className="DraftPanelBody__left post__img"
>
<ProfilePicture
channelId="channel_id"
hasMention={false}
isEmoji={false}
popoverPlacement="right"
size="md"
src="/api/v4/users/user_id/image?_=0"
status="status"
userId="user_id"
username="username"
wrapperClass=""
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<Memo(Connect(injectIntl(ProfilePopover)))
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<OverlayWrapper
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
intl={
Object {
"$t": [Function],
"defaultFormats": Object {},
"defaultLocale": "en",
"defaultRichTextElements": undefined,
"fallbackOnEmptyString": true,
"formatDate": [Function],
"formatDateTimeRange": [Function],
"formatDateToParts": [Function],
"formatDisplayName": [Function],
"formatList": [Function],
"formatListToParts": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatNumberToParts": [Function],
"formatPlural": [Function],
"formatRelativeTime": [Function],
"formatTime": [Function],
"formatTimeToParts": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getDisplayNames": [Function],
"getListFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralRules": [Function],
"getRelativeTimeFormat": [Function],
},
"locale": "en",
"messages": Object {},
"onError": [Function],
"onWarn": [Function],
"textComponent": "span",
"timeZone": "Etc/UTC",
"wrapRichTextChunksInFragment": undefined,
}
}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<span
className="status-wrapper "
onClick={[Function]}
>
<RoundButton
className="style--none"
size="md"
>
<button
className="RoundButton-dvlhqG gfRzmz style--none"
size="md"
>
<span
className="profile-icon "
>
<Memo(Avatar)
size="md"
tabIndex={-1}
url="/api/v4/users/user_id/image?_=0"
username="username"
>
<img
alt="username profile image"
className="Avatar Avatar-md"
loading="lazy"
onError={[Function]}
src="/api/v4/users/user_id/image?_=0"
tabIndex={-1}
/>
</Memo(Avatar)>
</span>
</button>
</RoundButton>
<StatusIcon
button={false}
className=""
status="status"
>
<StatusOfflineIcon
className="status "
>
<span
className="status "
>
<svg
aria-label="Offline Icon"
className="offline--icon"
height="100%"
role="img"
style={
Object {
"clipRule": "evenodd",
"fillRule": "evenodd",
"strokeLinejoin": "round",
"strokeMiterlimit": 1.41421,
}
}
viewBox="0 0 20 20"
width="100%"
>
<path
d="M10,0c5.519,0 10,4.481 10,10c0,5.519 -4.481,10 -10,10c-5.519,0 -10,-4.481 -10,-10c0,-5.519 4.481,-10 10,-10Zm0,2c4.415,0 8,3.585 8,8c0,4.415 -3.585,8 -8,8c-4.415,0 -8,-3.585 -8,-8c0,-4.415 3.585,-8 8,-8Z"
/>
</svg>
</span>
</StatusOfflineIcon>
</StatusIcon>
</span>
</OverlayTrigger>
</OverlayTrigger>
</ProfilePicture>
</div>
<div
className="post__content"
onClick={[Function]}
>
<div
className="DraftPanelBody__right"
>
<div
className="post__header"
>
<strong>
display_name
</strong>
<Memo(PriorityLabels)
canRemove={false}
hasError={false}
padding="0 0 0 8px"
priority="important"
requestedAck={false}
>
<Priority
padding="0 0 0 8px"
>
<div
className="Priority-unHRQ dkJcdD"
>
<PriorityLabel
priority="important"
size="xs"
>
<Memo(Tag)
icon="alert-circle-outline"
size="xs"
text="Important"
uppercase={true}
variant="info"
>
<TagWrapper
as="div"
className="Tag Tag--info Tag--xs"
uppercase={true}
>
<div
className="TagWrapper-keYggn hpsCJu Tag Tag--info Tag--xs"
>
<AlertCircleOutlineIcon
size={10}
>
<svg
fill="currentColor"
height={10}
version="1.1"
viewBox="0 0 24 24"
width={10}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12,2C6.5,2,2,6.5,2,12s4.5,10,10,10s10-4.5,10-10S17.5,2,12,2 M12,20c-4.4,0-8-3.6-8-8s3.6-8,8-8s8,3.6,8,8S16.4,20,12,20z M12.501,13h-1l-0.5-6h2L12.501,13z M13,16c0,0.552-0.448,1-1,1s-1-0.448-1-1s0.448-1,1-1S13,15.448,13,16z"
/>
</svg>
</AlertCircleOutlineIcon>
<TagText>
<span
className="TagText-bWgUzx kzWPbz"
>
Important
</span>
</TagText>
</div>
</TagWrapper>
</Memo(Tag)>
</PriorityLabel>
</div>
</Priority>
</Memo(PriorityLabels)>
</div>
<div
className="post__body"
>
<Connect(Markdown)
message="message"
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
>
<Markdown
autolinkedUrlSchemes={
Array [
"http",
"https",
"ftp",
"mailto",
"tel",
"mattermost",
]
}
channelNamesMap={Object {}}
dispatch={[Function]}
emojiMap={
EmojiMap {
"customEmojis": Map {},
"customEmojisArray": Array [],
}
}
enableFormatting={true}
hasImageProxy={false}
managedResourcePaths={Array []}
mentionKeys={Array []}
message="message"
minimumHashtagLength={NaN}
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
siteURL="http://localhost:8065"
team={
Object {
"display_name": "Team ID",
"id": "team_id",
"name": "team-id",
}
}
>
<p
key="0"
>
message
</p>
</Markdown>
</Connect(Markdown)>
</div>
</div>
</div>
</div>
</PanelBody>
</Provider>
`;
exports[`components/drafts/panel/panel_body should match snapshot for requested_ack 1`] = `
<Provider
store={
Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<PanelBody
channelId="channel_id"
displayName="display_name"
fileInfos={Array []}
message="message"
priority={
Object {
"priority": "",
"requested_ack": true,
}
}
status="status"
uploadsInProgress={Array []}
userId="user_id"
username="username"
>
<div
className="DraftPanelBody post"
>
<div
className="DraftPanelBody__left post__img"
>
<ProfilePicture
channelId="channel_id"
hasMention={false}
isEmoji={false}
popoverPlacement="right"
size="md"
src="/api/v4/users/user_id/image?_=0"
status="status"
userId="user_id"
username="username"
wrapperClass=""
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<Memo(Connect(injectIntl(ProfilePopover)))
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<OverlayTrigger
defaultOverlayShown={false}
overlay={
<OverlayWrapper
channelId="channel_id"
className="user-profile-popover"
hasMention={false}
hide={[Function]}
intl={
Object {
"$t": [Function],
"defaultFormats": Object {},
"defaultLocale": "en",
"defaultRichTextElements": undefined,
"fallbackOnEmptyString": true,
"formatDate": [Function],
"formatDateTimeRange": [Function],
"formatDateToParts": [Function],
"formatDisplayName": [Function],
"formatList": [Function],
"formatListToParts": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatNumberToParts": [Function],
"formatPlural": [Function],
"formatRelativeTime": [Function],
"formatTime": [Function],
"formatTimeToParts": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getDisplayNames": [Function],
"getListFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralRules": [Function],
"getRelativeTimeFormat": [Function],
},
"locale": "en",
"messages": Object {},
"onError": [Function],
"onWarn": [Function],
"textComponent": "span",
"timeZone": "Etc/UTC",
"wrapRichTextChunksInFragment": undefined,
}
}
src="/api/v4/users/user_id/image?_=0"
userId="user_id"
/>
}
placement="right"
rootClose={true}
trigger={
Array [
"click",
]
}
>
<span
className="status-wrapper "
onClick={[Function]}
>
<RoundButton
className="style--none"
size="md"
>
<button
className="RoundButton-dvlhqG gfRzmz style--none"
size="md"
>
<span
className="profile-icon "
>
<Memo(Avatar)
size="md"
tabIndex={-1}
url="/api/v4/users/user_id/image?_=0"
username="username"
>
<img
alt="username profile image"
className="Avatar Avatar-md"
loading="lazy"
onError={[Function]}
src="/api/v4/users/user_id/image?_=0"
tabIndex={-1}
/>
</Memo(Avatar)>
</span>
</button>
</RoundButton>
<StatusIcon
button={false}
className=""
status="status"
>
<StatusOfflineIcon
className="status "
>
<span
className="status "
>
<svg
aria-label="Offline Icon"
className="offline--icon"
height="100%"
role="img"
style={
Object {
"clipRule": "evenodd",
"fillRule": "evenodd",
"strokeLinejoin": "round",
"strokeMiterlimit": 1.41421,
}
}
viewBox="0 0 20 20"
width="100%"
>
<path
d="M10,0c5.519,0 10,4.481 10,10c0,5.519 -4.481,10 -10,10c-5.519,0 -10,-4.481 -10,-10c0,-5.519 4.481,-10 10,-10Zm0,2c4.415,0 8,3.585 8,8c0,4.415 -3.585,8 -8,8c-4.415,0 -8,-3.585 -8,-8c0,-4.415 3.585,-8 8,-8Z"
/>
</svg>
</span>
</StatusOfflineIcon>
</StatusIcon>
</span>
</OverlayTrigger>
</OverlayTrigger>
</ProfilePicture>
</div>
<div
className="post__content"
onClick={[Function]}
>
<div
className="DraftPanelBody__right"
>
<div
className="post__header"
>
<strong>
display_name
</strong>
<Memo(PriorityLabels)
canRemove={false}
hasError={false}
padding="0 0 0 8px"
priority=""
requestedAck={true}
>
<Priority
padding="0 0 0 8px"
>
<div
className="Priority-unHRQ dkJcdD"
>
<Acknowledgements
hasError={false}
>
<div
className="Acknowledgements-kPkVCv dNydui"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
overlay={
<Tooltip
id="post-priority-picker-ack-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Acknowledgement will be requested"
id="post_priority.request_acknowledgement.tooltip"
/>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
overlay={
<OverlayWrapper
id="post-priority-picker-ack-tooltip"
intl={
Object {
"$t": [Function],
"defaultFormats": Object {},
"defaultLocale": "en",
"defaultRichTextElements": undefined,
"fallbackOnEmptyString": true,
"formatDate": [Function],
"formatDateTimeRange": [Function],
"formatDateToParts": [Function],
"formatDisplayName": [Function],
"formatList": [Function],
"formatListToParts": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatNumberToParts": [Function],
"formatPlural": [Function],
"formatRelativeTime": [Function],
"formatTime": [Function],
"formatTimeToParts": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getDisplayNames": [Function],
"getListFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralRules": [Function],
"getRelativeTimeFormat": [Function],
},
"locale": "en",
"messages": Object {},
"onError": [Function],
"onWarn": [Function],
"textComponent": "span",
"timeZone": "Etc/UTC",
"wrapRichTextChunksInFragment": undefined,
}
}
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Acknowledgement will be requested"
id="post_priority.request_acknowledgement.tooltip"
/>
</OverlayWrapper>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<CheckCircleOutlineIcon
onBlur={[Function]}
onClick={null}
onFocus={[Function]}
onMouseOut={[Function]}
onMouseOver={[Function]}
size={14}
>
<svg
fill="currentColor"
height={14}
onBlur={[Function]}
onClick={null}
onFocus={[Function]}
onMouseOut={[Function]}
onMouseOver={[Function]}
version="1.1"
viewBox="0 0 24 24"
width={14}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"
/>
</svg>
</CheckCircleOutlineIcon>
</OverlayTrigger>
</OverlayTrigger>
<FormattedMessage
defaultMessage="Request acknowledgement"
id="post_priority.request_acknowledgement"
>
<span>
Request acknowledgement
</span>
</FormattedMessage>
</div>
</Acknowledgements>
</div>
</Priority>
</Memo(PriorityLabels)>
</div>
<div
className="post__body"
>
<Connect(Markdown)
message="message"
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
>
<Markdown
autolinkedUrlSchemes={
Array [
"http",
"https",
"ftp",
"mailto",
"tel",
"mattermost",
]
}
channelNamesMap={Object {}}
dispatch={[Function]}
emojiMap={
EmojiMap {
"customEmojis": Map {},
"customEmojisArray": Array [],
}
}
enableFormatting={true}
hasImageProxy={false}
managedResourcePaths={Array []}
mentionKeys={Array []}
message="message"
minimumHashtagLength={NaN}
options={
Object {
"disableGroupHighlight": true,
"mentionHighlight": false,
}
}
siteURL="http://localhost:8065"
team={
Object {
"display_name": "Team ID",
"id": "team_id",
"name": "team-id",
}
}
>
<p
key="0"
>
message
</p>
</Markdown>
</Connect(Markdown)>
</div>
</div>
</div>
</div>
</PanelBody>
</Provider>
`;
|
2,126 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/panel/__snapshots__/panel_header.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/panel/panel_header should match snapshot 1`] = `
<header
className="PanelHeader"
>
<div
className="PanelHeader__left"
>
<div>
title
</div>
</div>
<div
className="PanelHeader__right"
>
<div
className="PanelHeader__actions"
>
<div>
actions
</div>
</div>
<div
className="PanelHeader__info"
>
<div
className="PanelHeader__timestamp"
>
<Connect(injectIntl(Timestamp))
day="numeric"
units={
Array [
"now",
"minute",
"hour",
"day",
"week",
"month",
"year",
]
}
useSemanticOutput={false}
useTime={false}
value={1970-01-01T00:00:12.345Z}
/>
</div>
<Memo(Tag)
text="draft"
uppercase={true}
variant="danger"
/>
</div>
</div>
</header>
`;
exports[`components/drafts/panel/panel_header should show draft actions when hovered 1`] = `
<header
className="PanelHeader"
>
<div
className="PanelHeader__left"
>
<div>
title
</div>
</div>
<div
className="PanelHeader__right"
>
<div
className="PanelHeader__actions show"
>
<div>
actions
</div>
</div>
<div
className="PanelHeader__info hide"
>
<div
className="PanelHeader__timestamp"
>
<Connect(injectIntl(Timestamp))
day="numeric"
units={
Array [
"now",
"minute",
"hour",
"day",
"week",
"month",
"year",
]
}
useSemanticOutput={false}
useTime={false}
value={1970-01-01T00:00:12.345Z}
/>
</div>
<Memo(Tag)
text="draft"
uppercase={true}
variant="danger"
/>
</div>
</div>
</header>
`;
exports[`components/drafts/panel/panel_header should show sync icon when draft is from server 1`] = `
<header
className="PanelHeader"
>
<div
className="PanelHeader__left"
>
<div>
title
</div>
</div>
<div
className="PanelHeader__right"
>
<div
className="PanelHeader__actions"
>
<div>
actions
</div>
</div>
<div
className="PanelHeader__info"
>
<div
className="PanelHeader__sync-icon"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
overlay={
<Tooltip
id="drafts-sync-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Updated from another device"
id="drafts.info.sync"
/>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<SyncIcon
size={18}
/>
</OverlayTrigger>
</div>
<div
className="PanelHeader__timestamp"
>
<Connect(injectIntl(Timestamp))
day="numeric"
units={
Array [
"now",
"minute",
"hour",
"day",
"week",
"month",
"year",
]
}
useSemanticOutput={false}
useTime={false}
value={1970-01-01T00:00:12.345Z}
/>
</div>
<Memo(Tag)
text="draft"
uppercase={true}
variant="danger"
/>
</div>
</div>
</header>
`;
|
2,128 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/thread_draft/thread_draft.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import type {Channel} from '@mattermost/types/channels';
import type {UserThread, UserThreadSynthetic} from '@mattermost/types/threads';
import type {UserProfile, UserStatus} from '@mattermost/types/users';
import mockStore from 'tests/test_store';
import type {PostDraft} from 'types/store/draft';
import ThreadDraft from './thread_draft';
describe('components/drafts/drafts_row', () => {
const baseProps = {
channel: {
id: '',
} as Channel,
channelUrl: '',
displayName: '',
draftId: '',
rootId: '' as UserThread['id'] | UserThreadSynthetic['id'],
id: {} as Channel['id'],
status: {} as UserStatus['status'],
thread: {
id: '',
} as UserThread | UserThreadSynthetic,
type: 'thread' as 'channel' | 'thread',
user: {} as UserProfile,
value: {} as PostDraft,
isRemote: false,
};
it('should match snapshot for channel draft', () => {
const store = mockStore();
const wrapper = shallow(
<Provider store={store}>
<ThreadDraft
{...baseProps}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should match snapshot for undefined thread', () => {
const store = mockStore();
const props = {
...baseProps,
thread: null as unknown as UserThread | UserThreadSynthetic,
};
const wrapper = shallow(
<Provider store={store}>
<ThreadDraft
{...props}
/>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,130 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/thread_draft | petrpan-code/mattermost/mattermost/webapp/channels/src/components/drafts/thread_draft/__snapshots__/thread_draft.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/drafts/drafts_row should match snapshot for channel draft 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(ThreadDraft)
channel={
Object {
"id": "",
}
}
channelUrl=""
displayName=""
draftId=""
id={Object {}}
isRemote={false}
rootId=""
status={Object {}}
thread={
Object {
"id": "",
}
}
type="thread"
user={Object {}}
value={Object {}}
/>
</ContextProvider>
`;
exports[`components/drafts/drafts_row should match snapshot for undefined thread 1`] = `
<ContextProvider
value={
Object {
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"subscription": Subscription {
"handleChangeWrapper": [Function],
"listeners": Object {
"notify": [Function],
},
"onStateChange": [Function],
"parentSub": undefined,
"store": Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
},
"unsubscribe": null,
},
}
}
>
<Memo(ThreadDraft)
channel={
Object {
"id": "",
}
}
channelUrl=""
displayName=""
draftId=""
id={Object {}}
isRemote={false}
rootId=""
status={Object {}}
thread={null}
type="thread"
user={Object {}}
value={Object {}}
/>
</ContextProvider>
`;
|
2,131 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_category_modal/edit_category_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import EditCategoryModal from './edit_category_modal';
describe('components/EditCategoryModal', () => {
describe('isConfirmDisabled', () => {
const requiredProps = {
onExited: jest.fn(),
currentTeamId: '42',
actions: {
createCategory: jest.fn(),
renameCategory: jest.fn(),
},
};
test.each([
['', true],
['Where is Jessica Hyde?', false],
['Some string with length more than 22', true],
])('when categoryName: %s, isConfirmDisabled should return %s', (categoryName, expected) => {
const wrapper = shallow<EditCategoryModal>(<EditCategoryModal {...requiredProps}/>);
wrapper.setState({categoryName});
const instance = wrapper.instance();
expect(instance.isConfirmDisabled()).toBe(expected);
});
});
});
|
2,134 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_channel_header_modal/edit_channel_header_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import type {Channel, ChannelType} from '@mattermost/types/channels';
import EditChannelHeaderModal from 'components/edit_channel_header_modal/edit_channel_header_modal';
import Textbox from 'components/textbox';
import {testComponentForLineBreak} from 'tests/helpers/line_break_helpers';
import Constants from 'utils/constants';
import * as Utils from 'utils/utils';
const KeyCodes = Constants.KeyCodes;
describe('components/EditChannelHeaderModal', () => {
const timestamp = Utils.getTimestamp();
const channel = {
id: 'fake-id',
create_at: timestamp,
update_at: timestamp,
delete_at: timestamp,
team_id: 'fake-team-id',
type: Constants.OPEN_CHANNEL as ChannelType,
display_name: 'Fake Channel',
name: 'Fake Channel',
header: 'Fake Channel',
purpose: 'purpose',
last_post_at: timestamp,
creator_id: 'fake-creator-id',
scheme_id: 'fake-scheme-id',
group_constrained: false,
last_root_post_at: timestamp,
};
const serverError = {
server_error_id: 'fake-server-error',
message: 'some error',
};
const baseProps = {
markdownPreviewFeatureIsEnabled: false,
channel,
ctrlSend: false,
show: false,
shouldShowPreview: false,
onExited: jest.fn(),
actions: {
setShowPreview: jest.fn(),
patchChannel: jest.fn().mockResolvedValue({}),
},
};
test('should match snapshot, init', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('edit direct message channel', () => {
const dmChannel: Channel = {
...channel,
type: Constants.DM_CHANNEL as ChannelType,
};
const wrapper = shallow(
<EditChannelHeaderModal
{...baseProps}
channel={dmChannel}
/>,
);
expect(wrapper).toMatchSnapshot();
});
test('submitted', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.setState({saving: true});
expect(wrapper).toMatchSnapshot();
});
test('error with intl message', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.setState({serverError: {...serverError, server_error_id: 'model.channel.is_valid.header.app_error'}});
expect(wrapper).toMatchSnapshot();
});
test('error without intl message', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.setState({serverError});
expect(wrapper).toMatchSnapshot();
});
describe('handleSave', () => {
test('on no change, should hide the modal without trying to patch a channel', async () => {
const wrapper = shallow<EditChannelHeaderModal>(
<EditChannelHeaderModal {...baseProps}/>,
);
await wrapper.instance().handleSave();
expect(wrapper.state('show')).toBe(false);
expect(baseProps.actions.patchChannel).not.toHaveBeenCalled();
});
test('on error, should not close modal and set server error state', async () => {
baseProps.actions.patchChannel.mockResolvedValueOnce({error: serverError});
const wrapper = shallow<EditChannelHeaderModal>(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.setState({header: 'New header'});
await wrapper.instance().handleSave();
expect(wrapper.state('show')).toBe(true);
expect(wrapper.state('serverError')).toBe(serverError);
expect(baseProps.actions.patchChannel).toHaveBeenCalled();
});
test('on success, should close modal', async () => {
const wrapper = shallow<EditChannelHeaderModal>(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.setState({header: 'New header'});
await wrapper.instance().handleSave();
expect(wrapper.state('show')).toBe(false);
expect(baseProps.actions.patchChannel).toHaveBeenCalled();
});
});
test('change header', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.find(Textbox).simulate('change', {target: {value: 'header'}});
expect(
wrapper.state('header'),
).toBe('header');
});
test('patch on save button click', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
const newHeader = 'New channel header';
wrapper.setState({header: newHeader});
wrapper.find('.save-button').simulate('click');
expect(baseProps.actions.patchChannel).toBeCalledWith('fake-id', {header: newHeader});
});
test('patch on enter keypress event with ctrl', () => {
const wrapper = shallow(
<EditChannelHeaderModal
{...baseProps}
ctrlSend={true}
/>,
);
const newHeader = 'New channel header';
wrapper.setState({header: newHeader});
wrapper.find(Textbox).simulate('keypress', {
preventDefault: jest.fn(),
key: KeyCodes.ENTER[0],
which: KeyCodes.ENTER[1],
shiftKey: false,
altKey: false,
ctrlKey: true,
});
expect(baseProps.actions.patchChannel).toBeCalledWith('fake-id', {header: newHeader});
});
test('patch on enter keypress', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
const newHeader = 'New channel header';
wrapper.setState({header: newHeader});
wrapper.find(Textbox).simulate('keypress', {
preventDefault: jest.fn(),
key: KeyCodes.ENTER[0],
which: KeyCodes.ENTER[1],
shiftKey: false,
altKey: false,
ctrlKey: false,
});
expect(baseProps.actions.patchChannel).toBeCalledWith('fake-id', {header: newHeader});
});
test('patch on enter keydown', () => {
const wrapper = shallow(
<EditChannelHeaderModal
{...baseProps}
ctrlSend={true}
/>,
);
const newHeader = 'New channel header';
wrapper.setState({header: newHeader});
wrapper.find(Textbox).simulate('keydown', {
preventDefault: jest.fn(),
key: KeyCodes.ENTER[0],
keyCode: KeyCodes.ENTER[1],
which: KeyCodes.ENTER[1],
shiftKey: false,
altKey: false,
ctrlKey: true,
});
expect(baseProps.actions.patchChannel).toBeCalledWith('fake-id', {header: newHeader});
});
test('should show error only for invalid length', () => {
const wrapper = shallow(
<EditChannelHeaderModal {...baseProps}/>,
);
wrapper.find(Textbox).simulate('change', {target: {value: `The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
1914 translation by H. Rackham
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."`}});
expect(
wrapper.state('serverError'),
).toStrictEqual({message: 'Invalid header length', server_error_id: 'model.channel.is_valid.header.app_error'});
wrapper.find(Textbox).simulate('change', {target: {value: 'valid header'}});
expect(
wrapper.state('serverError'),
).toBeNull();
});
testComponentForLineBreak(
(value: string) => (
<EditChannelHeaderModal
{...baseProps}
channel={{
...baseProps.channel,
header: value,
}}
/>
),
(instance: React.Component<any, any>) => instance.state.header,
false,
);
});
|
2,137 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_channel_header_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_channel_header_modal/__snapshots__/edit_channel_header_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/EditChannelHeaderModal edit direct message channel 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelHeaderModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={false}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
onKeyDown={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelHeaderModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Edit Header"
id="edit_channel_header_modal.title_dm"
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body edit-modal-body"
componentClass="div"
>
<div>
<p>
<MemoizedFormattedMessage
defaultMessage="Edit the text appearing next to the channel name in the header."
id="edit_channel_header_modal.description"
/>
</p>
<div
className="textarea-wrapper"
>
<Connect(Textbox)
channelId="fake-id"
characterLimit={1024}
createMessage="Edit the Channel Header..."
handlePostError={[Function]}
id="edit_textbox"
onChange={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
preview={false}
suggestionListPosition="bottom"
supportsCommands={false}
useChannelMentions={false}
value="Fake Channel"
/>
</div>
<div
className="post-create-footer"
>
<TextboxLinks
hasExceededCharacterLimit={false}
hasText={true}
isMarkdownPreviewEnabled={false}
previewMessageLink="Edit Header"
showPreview={false}
updatePreview={[Function]}
/>
</div>
<br />
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_header_modal.cancel"
/>
</button>
<button
className="btn btn-primary save-button"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_header_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`components/EditChannelHeaderModal error with intl message 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelHeaderModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={false}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
onKeyDown={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelHeaderModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Edit Header for {channel}"
id="edit_channel_header_modal.title"
values={
Object {
"channel": "Fake Channel",
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body edit-modal-body"
componentClass="div"
>
<div>
<p>
<MemoizedFormattedMessage
defaultMessage="Edit the text appearing next to the channel name in the header."
id="edit_channel_header_modal.description"
/>
</p>
<div
className="textarea-wrapper"
>
<Connect(Textbox)
channelId="fake-id"
characterLimit={1024}
createMessage="Edit the Channel Header..."
handlePostError={[Function]}
id="edit_textbox"
onChange={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
preview={false}
suggestionListPosition="bottom"
supportsCommands={false}
useChannelMentions={false}
value="Fake Channel"
/>
</div>
<div
className="post-create-footer"
>
<TextboxLinks
hasExceededCharacterLimit={false}
hasText={true}
isMarkdownPreviewEnabled={false}
previewMessageLink="Edit Header"
showPreview={false}
updatePreview={[Function]}
/>
</div>
<br />
<div
className="form-group has-error"
>
<br />
<label
className="control-label"
>
<MemoizedFormattedMessage
defaultMessage="The text entered exceeds the character limit. The channel header is limited to {maxLength} characters."
id="edit_channel_header_modal.error"
values={
Object {
"maxLength": 1024,
}
}
/>
</label>
</div>
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_header_modal.cancel"
/>
</button>
<button
className="btn btn-primary save-button"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_header_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`components/EditChannelHeaderModal error without intl message 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelHeaderModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={false}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
onKeyDown={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelHeaderModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Edit Header for {channel}"
id="edit_channel_header_modal.title"
values={
Object {
"channel": "Fake Channel",
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body edit-modal-body"
componentClass="div"
>
<div>
<p>
<MemoizedFormattedMessage
defaultMessage="Edit the text appearing next to the channel name in the header."
id="edit_channel_header_modal.description"
/>
</p>
<div
className="textarea-wrapper"
>
<Connect(Textbox)
channelId="fake-id"
characterLimit={1024}
createMessage="Edit the Channel Header..."
handlePostError={[Function]}
id="edit_textbox"
onChange={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
preview={false}
suggestionListPosition="bottom"
supportsCommands={false}
useChannelMentions={false}
value="Fake Channel"
/>
</div>
<div
className="post-create-footer"
>
<TextboxLinks
hasExceededCharacterLimit={false}
hasText={true}
isMarkdownPreviewEnabled={false}
previewMessageLink="Edit Header"
showPreview={false}
updatePreview={[Function]}
/>
</div>
<br />
<div
className="form-group has-error"
>
<br />
<label
className="control-label"
>
some error
</label>
</div>
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_header_modal.cancel"
/>
</button>
<button
className="btn btn-primary save-button"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_header_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`components/EditChannelHeaderModal should match snapshot, init 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelHeaderModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={false}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
onKeyDown={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelHeaderModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Edit Header for {channel}"
id="edit_channel_header_modal.title"
values={
Object {
"channel": "Fake Channel",
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body edit-modal-body"
componentClass="div"
>
<div>
<p>
<MemoizedFormattedMessage
defaultMessage="Edit the text appearing next to the channel name in the header."
id="edit_channel_header_modal.description"
/>
</p>
<div
className="textarea-wrapper"
>
<Connect(Textbox)
channelId="fake-id"
characterLimit={1024}
createMessage="Edit the Channel Header..."
handlePostError={[Function]}
id="edit_textbox"
onChange={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
preview={false}
suggestionListPosition="bottom"
supportsCommands={false}
useChannelMentions={false}
value="Fake Channel"
/>
</div>
<div
className="post-create-footer"
>
<TextboxLinks
hasExceededCharacterLimit={false}
hasText={true}
isMarkdownPreviewEnabled={false}
previewMessageLink="Edit Header"
showPreview={false}
updatePreview={[Function]}
/>
</div>
<br />
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_header_modal.cancel"
/>
</button>
<button
className="btn btn-primary save-button"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_header_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`components/EditChannelHeaderModal submitted 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelHeaderModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={false}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
onKeyDown={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelHeaderModalLabel"
>
<MemoizedFormattedMessage
defaultMessage="Edit Header for {channel}"
id="edit_channel_header_modal.title"
values={
Object {
"channel": "Fake Channel",
}
}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body edit-modal-body"
componentClass="div"
>
<div>
<p>
<MemoizedFormattedMessage
defaultMessage="Edit the text appearing next to the channel name in the header."
id="edit_channel_header_modal.description"
/>
</p>
<div
className="textarea-wrapper"
>
<Connect(Textbox)
channelId="fake-id"
characterLimit={1024}
createMessage="Edit the Channel Header..."
handlePostError={[Function]}
id="edit_textbox"
onChange={[Function]}
onKeyDown={[Function]}
onKeyPress={[Function]}
preview={false}
suggestionListPosition="bottom"
supportsCommands={false}
useChannelMentions={false}
value="Fake Channel"
/>
</div>
<div
className="post-create-footer"
>
<TextboxLinks
hasExceededCharacterLimit={false}
hasText={true}
isMarkdownPreviewEnabled={false}
previewMessageLink="Edit Header"
showPreview={false}
updatePreview={[Function]}
/>
</div>
<br />
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_header_modal.cancel"
/>
</button>
<button
className="btn btn-primary save-button"
disabled={true}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_header_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
|
2,138 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_channel_purpose_modal/edit_channel_purpose_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {Channel} from '@mattermost/types/channels';
import EditChannelPurposeModal from 'components/edit_channel_purpose_modal/edit_channel_purpose_modal';
import type {EditChannelPurposeModal as EditChannelPurposeModalClass} from 'components/edit_channel_purpose_modal/edit_channel_purpose_modal';
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import {testComponentForLineBreak} from 'tests/helpers/line_break_helpers';
import Constants from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
describe('comoponents/EditChannelPurposeModal', () => {
const channel = TestHelper.getChannelMock({
purpose: 'testPurpose',
});
it('should match on init', () => {
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn()}}
/>,
{disableLifecycleMethods: true},
);
expect(wrapper).toMatchSnapshot();
});
it('should match with display name', () => {
const channelWithDisplayName = {
...channel,
display_name: 'channel name',
};
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channelWithDisplayName}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn()}}
/>,
{disableLifecycleMethods: true},
);
expect(wrapper).toMatchSnapshot();
});
it('should match for private channel', () => {
const privateChannel: Channel = {
...channel,
type: 'P',
};
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={privateChannel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn()}}
/>,
{disableLifecycleMethods: true},
);
expect(wrapper).toMatchSnapshot();
});
it('should match submitted', () => {
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn()}}
/>,
{disableLifecycleMethods: true},
).dive();
expect(wrapper).toMatchSnapshot();
});
it('match with modal error', async () => {
const serverError = {
id: 'api.context.invalid_param.app_error',
message: 'error',
};
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={false}
onExited={jest.fn()}
actions={{patchChannel: jest.fn().mockResolvedValue({error: serverError})}}
/>,
{disableLifecycleMethods: true},
);
const instance = wrapper.instance() as EditChannelPurposeModalClass;
await instance.handleSave();
expect(wrapper).toMatchSnapshot();
});
it('match with modal error with fake id', async () => {
const serverError = {
id: 'fake-error-id',
message: 'error',
};
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={false}
onExited={jest.fn()}
actions={{patchChannel: jest.fn().mockResolvedValue({error: serverError})}}
/>,
{disableLifecycleMethods: true},
);
const instance = wrapper.instance() as EditChannelPurposeModalClass;
await instance.handleSave();
expect(wrapper).toMatchSnapshot();
});
it('clear error on next', async () => {
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={false}
onExited={jest.fn()}
actions={{patchChannel: jest.fn().mockResolvedValue({data: true})}}
/>,
{disableLifecycleMethods: true},
);
const serverError = {
id: 'fake-error-id',
message: 'error',
};
const instance = wrapper.instance();
instance.setState({serverError});
expect(wrapper).toMatchSnapshot();
});
it('update purpose state', () => {
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn()}}
/>,
{disableLifecycleMethods: true},
);
wrapper.find('textarea').simulate(
'change',
{
preventDefault: jest.fn(),
target: {value: 'new info'},
},
);
expect(wrapper.state('purpose')).toBe('new info');
});
it('hide on success', async () => {
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn().mockResolvedValue({data: true})}}
/>,
{disableLifecycleMethods: true},
);
const instance = wrapper.instance() as EditChannelPurposeModalClass;
await instance.handleSave();
expect(wrapper.state('show')).toBeFalsy();
});
it('submit on save button click', () => {
const patchChannel = jest.fn().mockResolvedValue({data: true});
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel}}
/>,
{disableLifecycleMethods: true},
);
wrapper.find('.btn-primary').simulate('click');
expect(patchChannel).toBeCalledWith('channel_id', {purpose: 'testPurpose'});
});
it('submit on ctrl + enter', () => {
const patchChannel = jest.fn().mockResolvedValue({data: true});
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel}}
/>,
{disableLifecycleMethods: true},
);
wrapper.find('textarea').simulate('keydown', {
preventDefault: jest.fn(),
key: Constants.KeyCodes.ENTER[0],
keyCode: Constants.KeyCodes.ENTER[1],
ctrlKey: true,
});
expect(patchChannel).toBeCalledWith('channel_id', {purpose: 'testPurpose'});
});
it('submit on enter', () => {
const patchChannel = jest.fn().mockResolvedValue({data: true});
const wrapper = shallowWithIntl(
<EditChannelPurposeModal
channel={channel}
ctrlSend={false}
onExited={jest.fn()}
actions={{patchChannel}}
/>,
{disableLifecycleMethods: true},
);
wrapper.find('textarea').simulate('keydown', {
preventDefault: jest.fn(),
key: Constants.KeyCodes.ENTER[0],
keyCode: Constants.KeyCodes.ENTER[1],
ctrlKey: false,
});
expect(patchChannel).toBeCalledWith('channel_id', {purpose: 'testPurpose'});
});
testComponentForLineBreak((value: string) => (
<EditChannelPurposeModal
channel={{
...channel,
purpose: value,
}}
ctrlSend={true}
onExited={jest.fn()}
actions={{patchChannel: jest.fn()}}
/>
), (instance: React.Component<any, any>) => instance.state.purpose);
});
|
2,141 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_channel_purpose_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/edit_channel_purpose_modal/__snapshots__/edit_channel_purpose_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`comoponents/EditChannelPurposeModal clear error on next 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelPurposeModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="Describe how this channel should be used. This text appears in the channel list in the \\"More...\\" menu and helps others decide whether to join."
id="edit_channel_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
<div
className="form-group has-error"
>
<br />
<label
className="control-label"
>
error
</label>
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`comoponents/EditChannelPurposeModal match with modal error 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelPurposeModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="Describe how this channel should be used. This text appears in the channel list in the \\"More...\\" menu and helps others decide whether to join."
id="edit_channel_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
<div
className="form-group has-error"
>
<br />
<label
className="control-label"
>
error
</label>
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`comoponents/EditChannelPurposeModal match with modal error with fake id 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelPurposeModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="Describe how this channel should be used. This text appears in the channel list in the \\"More...\\" menu and helps others decide whether to join."
id="edit_channel_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
<div
className="form-group has-error"
>
<br />
<label
className="control-label"
>
error
</label>
</div>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`comoponents/EditChannelPurposeModal should match for private channel 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelPurposeModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="This text appears in the \\\\\\"View Info\\\\\\" modal of the private channel."
id="edit_channel_private_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`comoponents/EditChannelPurposeModal should match on init 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelPurposeModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="Describe how this channel should be used. This text appears in the channel list in the \\"More...\\" menu and helps others decide whether to join."
id="edit_channel_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
exports[`comoponents/EditChannelPurposeModal should match submitted 1`] = `
<Modal
autoFocus={true}
backdrop={true}
backdropClassName="modal-backdrop"
backdropTransition={[Function]}
containerClassName="modal-open"
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[Function]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
show={true}
transition={[Function]}
>
<ModalDialog
aria-labelledby="editChannelPurposeModalLabel"
bsClass="modal"
className=""
dialogClassName="a11y__modal"
handleDialogMouseDown={[Function]}
onClick={[Function]}
role="dialog"
style={Object {}}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="Describe how this channel should be used. This text appears in the channel list in the \\"More...\\" menu and helps others decide whether to join."
id="edit_channel_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</ModalDialog>
</Modal>
`;
exports[`comoponents/EditChannelPurposeModal should match with display name 1`] = `
<Modal
animation={true}
aria-labelledby="editChannelPurposeModalLabel"
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="a11y__modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onEntering={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
>
<ModalHeader
bsClass="modal-header"
closeButton={true}
closeLabel="Close"
>
<ModalTitle
bsClass="modal-title"
componentClass="h1"
id="editChannelPurposeModalLabel"
>
<span>
<MemoizedFormattedMessage
defaultMessage="Edit Purpose for "
id="edit_channel_purpose_modal.title2"
/>
<span
className="name"
>
channel name
</span>
</span>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<p>
<MemoizedFormattedMessage
defaultMessage="Describe how this channel should be used. This text appears in the channel list in the \\"More...\\" menu and helps others decide whether to join."
id="edit_channel_purpose_modal.body"
/>
</p>
<textarea
aria-label="edit purpose"
className="form-control no-resize"
maxLength={250}
onChange={[Function]}
onKeyDown={[Function]}
rows={6}
value="testPurpose"
/>
</ModalBody>
<ModalFooter
bsClass="modal-footer"
componentClass="div"
>
<button
className="btn btn-tertiary cancel-button"
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="edit_channel_purpose_modal.cancel"
/>
</button>
<button
className="btn btn-primary"
disabled={false}
onClick={[Function]}
type="button"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="edit_channel_purpose_modal.save"
/>
</button>
</ModalFooter>
</Modal>
`;
|
2,148 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji/add_emoji/add_emoji.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import type {CustomEmoji} from '@mattermost/types/emojis';
import type {Team} from '@mattermost/types/teams';
import type {UserProfile} from '@mattermost/types/users';
import EmojiMap from 'utils/emoji_map';
import {TestHelper} from 'utils/test_helper';
import AddEmoji from './add_emoji';
import type {AddEmojiProps} from './add_emoji';
const context = {router: {}};
const image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAB3R' +
'JTUUH4AcXEyomBnhW6AAAAm9JREFUeNrtnL9vEmEcxj9cCDUSIVhNgGjaTUppOmjrX1BNajs61n+hC5MMrQNOLE7d27GjPxLs0JmSDk2VYNLBCw0yCA0mOBATHXghVu4wYeHCPc' +
'94711y30/e732f54Y3sLBbxEUxYAtYA5aB+0yXasAZcAQcAFdON1kuD+eBBvAG2JhCOJiaNkyNDVPzfwGlgBPgJRDCPwqZmk8MA0dAKeAjsIJ/tWIYpJwA7U9pK43Tevv/Asr7f' +
'Oc47aR8H1AMyIrJkLJAzDKjPCQejh/uLcv4HMlZa5YxgZKzli1NrtETzRKD0RIgARIgARIgARIgAfKrgl54iUwiwrOlOHOzYQDsZof35w0+ffshQJlEhJ3NxWvX7t66waP5WV69' +
'/TxxSBNvsecP74215htA83fCrmv9lvM1oJsh9y4PzwQFqFJvj7XmG0AfzhtjrfkGUMlusXd8gd3sDK7ZzQ57xxeU7NbEAQUWdou/ZQflpAVIgPycxR7P3WbdZLHwTJBKvc3h6aU' +
'nspjlBTjZpw9IJ6MDY5hORtnZXCSTiAjQ+lJcWWyU0smostjYJi2gKTYyb3393hGgUXnr8PRSgEp2i0LxC5V6m5/dX4Nd5YW/iZ7xQSW75YlgKictQAKkLKYspiymLKYspiymLK' +
'YspiymLCYnraghQAIkCZAACZAACZDHAdWEwVU1i94RMZKzzix65+dIzjqy6B0u1BWLIXWBA4veyUsF8RhSAbjqT7EcUBaTgcqGybUx/0ITrTe5DIshH1QFnvh8J5UNg6qbUawCq' +
'8Brn324u6bm1b/hjHLSOSAObAPvprT1aqa2bVNrzummPw4OwJf+E7QCAAAAAElFTkSuQmCC';
describe('components/emoji/components/AddEmoji', () => {
const baseProps: AddEmojiProps = {
emojiMap: new EmojiMap(new Map([['mycustomemoji', TestHelper.getCustomEmojiMock({name: 'mycustomemoji'})]])),
team: {
id: 'team-id',
} as Team,
user: {
id: 'current-user-id',
} as UserProfile,
actions: {
createCustomEmoji: jest.fn().mockImplementation((emoji: CustomEmoji) => ({data: {name: emoji.name}})),
},
};
const assertErrorIsElementWithMatchingId = (error: React.ReactNode, expectedId: string) => {
const errorElement = error as JSX.Element;
expect(errorElement).not.toBeUndefined();
expect(errorElement.props.id).toEqual(expectedId);
};
test('should match snapshot', () => {
const wrapper = shallow(
<AddEmoji {...baseProps}/>,
{context},
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.state('image')).toBeNull();
expect(wrapper.state('imageUrl')).toEqual('');
expect(wrapper.state('name')).toEqual('');
});
test('should update emoji name and match snapshot', () => {
const wrapper = shallow(
<AddEmoji {...baseProps}/>,
{context},
);
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'emojiName'}});
expect(wrapper.state('name')).toEqual('emojiName');
expect(wrapper).toMatchSnapshot();
});
test('should select a file and match snapshot', () => {
const wrapper = shallow(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
const onload = jest.fn(() => {
wrapper.setState({image: file, imageUrl: image});
});
const readAsDataURL = jest.fn(() => onload());
Object.defineProperty(global, 'FileReader', {
writable: true,
value: jest.fn().mockImplementation(() => ({
readAsDataURL,
onload,
})),
});
const fileInput = wrapper.find('#select-emoji');
fileInput.simulate('change', {target: {files: []}});
expect(FileReader).not.toBeCalled();
expect(wrapper.state('image')).toEqual(null);
expect(wrapper.state('imageUrl')).toEqual('');
fileInput.simulate('change', {target: {files: [file]}});
expect(FileReader).toBeCalled();
expect(readAsDataURL).toHaveBeenCalledWith(file);
expect(onload).toHaveBeenCalledTimes(1);
expect(wrapper.state('image')).toEqual(file);
expect(wrapper.state('imageUrl')).toEqual(image);
expect(wrapper).toMatchSnapshot();
});
test('should submit the new added emoji', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
const onload = jest.fn(() => {
wrapper.setState({image: file as File, imageUrl: image});
});
const readAsDataURL = jest.fn(() => onload());
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
const fileInput = wrapper.find('#select-emoji');
Object.defineProperty(global, 'FileReader', {
writable: true,
value: jest.fn().mockImplementation(() => ({
readAsDataURL,
onload,
result: image,
})),
});
nameInput.simulate('change', {target: {name: 'name', value: 'emojiName'}});
fileInput.simulate('change', {target: {files: [file]}});
form.simulate('submit', {preventDefault: jest.fn()});
Promise.resolve();
expect(wrapper.state('saving')).toEqual(true);
expect(baseProps.actions.createCustomEmoji).toBeCalled();
expect(wrapper.state().error).toBeNull();
});
test('should not submit when already saving', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
wrapper.setState({saving: true});
const form = wrapper.find('form').first();
form.simulate('submit', {preventDefault: jest.fn()});
Promise.resolve();
expect(wrapper.state('saving')).toEqual(true);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).toBeNull();
});
test('should show error if emoji name unset', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const form = wrapper.find('form').first();
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state('saving')).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.nameRequired');
});
test('should show error if image unset', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'emojiName'}});
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state('saving')).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.imageRequired');
});
test.each([
'hyphens-are-allowed',
'underscores_are_allowed',
'numb3rsar3all0w3d',
])('%s should be a valid emoji name', (emojiName) => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const saveButton = wrapper.find({'data-testid': 'save-button'}).first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: emojiName}});
saveButton.simulate('click', {preventDefault: jest.fn()});
expect(wrapper.state().saving).toEqual(true);
expect(baseProps.actions.createCustomEmoji).toBeCalled();
expect(wrapper.state().error).toBeNull();
});
test.each([
'$ymbolsnotallowed',
'symbolsnot@llowed',
'symbolsnot&llowed',
'symbolsnota|lowed',
'symbolsnota()owed',
'symbolsnot^llowed',
'symbols notallowed',
'symbols"notallowed',
"symbols'notallowed",
'symbols.not.allowed',
])("'%s' should not be a valid emoji name", (emojiName) => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: emojiName}});
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state().saving).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.nameInvalid');
});
test.each([
['UPPERCASE', 'uppercase'],
[' trimmed ', 'trimmed'],
[':colonstrimmed:', 'colonstrimmed'],
])("emoji name '%s' should be corrected as '%s'", (emojiName, expectedName) => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: emojiName}});
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state().saving).toEqual(true);
expect(baseProps.actions.createCustomEmoji).toHaveBeenCalledWith({creator_id: baseProps.user.id, name: expectedName}, file);
expect(wrapper.state().error).toBeNull();
});
test('should show an error when emoji name is taken by a system emoji', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'smiley'}});
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state().saving).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.nameTaken');
});
test('should show error when emoji name is taken by an existing custom emoji', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'mycustomemoji'}});
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state().saving).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.customNameTaken');
});
test('should show error when image is too large', () => {
const wrapper = shallow<AddEmoji>(
<AddEmoji {...baseProps}/>,
{context},
);
const file = {
type: 'image/png',
size: (1024 * 1024) + 1,
} as Blob;
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'newcustomemoji'}});
form.simulate('submit', {preventDefault: jest.fn()});
expect(wrapper.state().saving).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.imageTooLarge');
});
test('should show generic error when action response cannot be parsed', async () => {
const props = {...baseProps};
props.actions = {
createCustomEmoji: jest.fn().mockImplementation(async (): Promise<unknown> => ({})),
};
const wrapper = shallow<AddEmoji>(
<AddEmoji {...props}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'newemoji'}});
form.simulate('submit', {preventDefault: jest.fn()});
await Promise.resolve();
expect(wrapper.state().error).not.toBeNull();
assertErrorIsElementWithMatchingId(wrapper.state().error, 'add_emoji.failedToAdd');
expect(wrapper.state().saving).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
});
test('should show response error message when action response is error', async () => {
const props = {...baseProps};
const serverError = 'The server does not like the emoji.';
props.actions = {
createCustomEmoji: jest.fn().mockImplementation(async (): Promise<unknown> => ({error: {message: serverError}})),
};
const wrapper = shallow<AddEmoji>(
<AddEmoji {...props}/>,
{context},
);
const file = new Blob([image], {type: 'image/png'});
wrapper.setState({image: file as File, imageUrl: image});
const form = wrapper.find('form').first();
const nameInput = wrapper.find('#name');
nameInput.simulate('change', {target: {name: 'name', value: 'newemoji'}});
form.simulate('submit', {preventDefault: jest.fn()});
await Promise.resolve();
expect(wrapper.state().error).not.toBeNull();
expect(wrapper.state().error).toEqual(serverError);
expect(wrapper.state().saving).toEqual(false);
expect(baseProps.actions.createCustomEmoji).not.toBeCalled();
});
});
|
2,151 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji/add_emoji | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji/add_emoji/__snapshots__/add_emoji.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/emoji/components/AddEmoji should match snapshot 1`] = `
<div
className="backstage-content row"
>
<BackstageHeader>
<Link
to="/undefined/emoji"
>
<MemoizedFormattedMessage
defaultMessage="Custom Emoji"
id="emoji_list.header"
/>
</Link>
<MemoizedFormattedMessage
defaultMessage="Add"
id="add_emoji.header"
/>
</BackstageHeader>
<div
className="backstage-form"
>
<form
className="form-horizontal"
onSubmit={[Function]}
>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="name"
>
<MemoizedFormattedMessage
defaultMessage="Name"
id="add_emoji.name"
/>
</label>
<div
className="col-md-5 col-sm-8"
>
<input
className="form-control"
id="name"
maxLength={64}
onChange={[Function]}
type="text"
value=""
/>
<div
className="form__help"
>
<MemoizedFormattedMessage
defaultMessage="Name your emoji. The name can be up to 64 characters, and can contain lowercase letters, numbers, and the symbols '-' and '_'."
id="add_emoji.name.help"
/>
</div>
</div>
</div>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="image"
>
<MemoizedFormattedMessage
defaultMessage="Image"
id="add_emoji.image"
/>
</label>
<div
className="col-md-5 col-sm-8"
>
<div>
<div
className="add-emoji__upload"
>
<button
className="btn btn-primary"
>
<MemoizedFormattedMessage
defaultMessage="Select"
id="add_emoji.image.button"
/>
</button>
<input
accept=".jpeg,.jpg,.png,.gif"
id="select-emoji"
multiple={false}
onChange={[Function]}
type="file"
/>
</div>
<div
className="form__help"
>
<MemoizedFormattedMessage
defaultMessage="Specify a .gif, .png, or .jpg file of up to 64 KB for your emoji. The dimensions can be up to 128 pixels by 128 pixels."
id="add_emoji.image.help"
/>
</div>
</div>
</div>
</div>
<div
className="backstage-form__footer"
>
<FormError
error={null}
errors={Array []}
type="backstage"
/>
<Link
className="btn btn-tertiary"
to="/undefined/emoji"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="add_emoji.cancel"
/>
</Link>
<Memo(SpinnerButton)
className="btn btn-primary"
data-testid="save-button"
onClick={[Function]}
spinning={false}
spinningText="Saving..."
type="submit"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="add_emoji.save"
/>
</Memo(SpinnerButton)>
</div>
</form>
</div>
</div>
`;
exports[`components/emoji/components/AddEmoji should select a file and match snapshot 1`] = `
<div
className="backstage-content row"
>
<BackstageHeader>
<Link
to="/undefined/emoji"
>
<MemoizedFormattedMessage
defaultMessage="Custom Emoji"
id="emoji_list.header"
/>
</Link>
<MemoizedFormattedMessage
defaultMessage="Add"
id="add_emoji.header"
/>
</BackstageHeader>
<div
className="backstage-form"
>
<form
className="form-horizontal"
onSubmit={[Function]}
>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="name"
>
<MemoizedFormattedMessage
defaultMessage="Name"
id="add_emoji.name"
/>
</label>
<div
className="col-md-5 col-sm-8"
>
<input
className="form-control"
id="name"
maxLength={64}
onChange={[Function]}
type="text"
value=""
/>
<div
className="form__help"
>
<MemoizedFormattedMessage
defaultMessage="Name your emoji. The name can be up to 64 characters, and can contain lowercase letters, numbers, and the symbols '-' and '_'."
id="add_emoji.name.help"
/>
</div>
</div>
</div>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="image"
>
<MemoizedFormattedMessage
defaultMessage="Image"
id="add_emoji.image"
/>
</label>
<div
className="col-md-5 col-sm-8"
>
<div>
<div
className="add-emoji__upload"
>
<button
className="btn btn-primary"
>
<MemoizedFormattedMessage
defaultMessage="Select"
id="add_emoji.image.button"
/>
</button>
<input
accept=".jpeg,.jpg,.png,.gif"
id="select-emoji"
multiple={false}
onChange={[Function]}
type="file"
/>
</div>
<span
className="add-emoji__filename"
/>
<div
className="form__help"
>
<MemoizedFormattedMessage
defaultMessage="Specify a .gif, .png, or .jpg file of up to 64 KB for your emoji. The dimensions can be up to 128 pixels by 128 pixels."
id="add_emoji.image.help"
/>
</div>
</div>
</div>
</div>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="preview"
>
<MemoizedFormattedMessage
defaultMessage="Preview"
id="add_emoji.preview"
/>
</label>
<div
className="col-md-5 col-sm-8 add-emoji__preview"
>
<MemoizedFormattedMessage
defaultMessage="This is a sentence with {image} in it."
id="add_emoji.preview.sentence"
values={
Object {
"image": <span
className="emoticon"
style={
Object {
"backgroundImage": "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAYAAABV7bNHAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAB3RJTUUH4AcXEyomBnhW6AAAAm9JREFUeNrtnL9vEmEcxj9cCDUSIVhNgGjaTUppOmjrX1BNajs61n+hC5MMrQNOLE7d27GjPxLs0JmSDk2VYNLBCw0yCA0mOBATHXghVu4wYeHCPc94711y30/e732f54Y3sLBbxEUxYAtYA5aB+0yXasAZcAQcAFdON1kuD+eBBvAG2JhCOJiaNkyNDVPzfwGlgBPgJRDCPwqZmk8MA0dAKeAjsIJ/tWIYpJwA7U9pK43Tevv/Asr7fOc47aR8H1AMyIrJkLJAzDKjPCQejh/uLcv4HMlZa5YxgZKzli1NrtETzRKD0RIgARIgARIgARIgAfKrgl54iUwiwrOlOHOzYQDsZof35w0+ffshQJlEhJ3NxWvX7t66waP5WV69/TxxSBNvsecP74215htA83fCrmv9lvM1oJsh9y4PzwQFqFJvj7XmG0AfzhtjrfkGUMlusXd8gd3sDK7ZzQ57xxeU7NbEAQUWdou/ZQflpAVIgPycxR7P3WbdZLHwTJBKvc3h6aUnspjlBTjZpw9IJ6MDY5hORtnZXCSTiAjQ+lJcWWyU0smostjYJi2gKTYyb3393hGgUXnr8PRSgEp2i0LxC5V6m5/dX4Nd5YW/iZ7xQSW75YlgKictQAKkLKYspiymLKYspiymLKYspiymLCYnraghQAIkCZAACZAACZDHAdWEwVU1i94RMZKzzix65+dIzjqy6B0u1BWLIXWBA4veyUsF8RhSAbjqT7EcUBaTgcqGybUx/0ITrTe5DIshH1QFnvh8J5UNg6qbUawCq8Brn324u6bm1b/hjHLSOSAObAPvprT1aqa2bVNrzummPw4OwJf+E7QCAAAAAElFTkSuQmCC)",
}
}
/>,
}
}
/>
</div>
</div>
<div
className="backstage-form__footer"
>
<FormError
error={null}
errors={Array []}
type="backstage"
/>
<Link
className="btn btn-tertiary"
to="/undefined/emoji"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="add_emoji.cancel"
/>
</Link>
<Memo(SpinnerButton)
className="btn btn-primary"
data-testid="save-button"
onClick={[Function]}
spinning={false}
spinningText="Saving..."
type="submit"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="add_emoji.save"
/>
</Memo(SpinnerButton)>
</div>
</form>
</div>
</div>
`;
exports[`components/emoji/components/AddEmoji should update emoji name and match snapshot 1`] = `
<div
className="backstage-content row"
>
<BackstageHeader>
<Link
to="/undefined/emoji"
>
<MemoizedFormattedMessage
defaultMessage="Custom Emoji"
id="emoji_list.header"
/>
</Link>
<MemoizedFormattedMessage
defaultMessage="Add"
id="add_emoji.header"
/>
</BackstageHeader>
<div
className="backstage-form"
>
<form
className="form-horizontal"
onSubmit={[Function]}
>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="name"
>
<MemoizedFormattedMessage
defaultMessage="Name"
id="add_emoji.name"
/>
</label>
<div
className="col-md-5 col-sm-8"
>
<input
className="form-control"
id="name"
maxLength={64}
onChange={[Function]}
type="text"
value="emojiName"
/>
<div
className="form__help"
>
<MemoizedFormattedMessage
defaultMessage="Name your emoji. The name can be up to 64 characters, and can contain lowercase letters, numbers, and the symbols '-' and '_'."
id="add_emoji.name.help"
/>
</div>
</div>
</div>
<div
className="form-group"
>
<label
className="control-label col-sm-4"
htmlFor="image"
>
<MemoizedFormattedMessage
defaultMessage="Image"
id="add_emoji.image"
/>
</label>
<div
className="col-md-5 col-sm-8"
>
<div>
<div
className="add-emoji__upload"
>
<button
className="btn btn-primary"
>
<MemoizedFormattedMessage
defaultMessage="Select"
id="add_emoji.image.button"
/>
</button>
<input
accept=".jpeg,.jpg,.png,.gif"
id="select-emoji"
multiple={false}
onChange={[Function]}
type="file"
/>
</div>
<div
className="form__help"
>
<MemoizedFormattedMessage
defaultMessage="Specify a .gif, .png, or .jpg file of up to 64 KB for your emoji. The dimensions can be up to 128 pixels by 128 pixels."
id="add_emoji.image.help"
/>
</div>
</div>
</div>
</div>
<div
className="backstage-form__footer"
>
<FormError
error={null}
errors={Array []}
type="backstage"
/>
<Link
className="btn btn-tertiary"
to="/undefined/emoji"
>
<MemoizedFormattedMessage
defaultMessage="Cancel"
id="add_emoji.cancel"
/>
</Link>
<Memo(SpinnerButton)
className="btn btn-primary"
data-testid="save-button"
onClick={[Function]}
spinning={false}
spinningText="Saving..."
type="submit"
>
<MemoizedFormattedMessage
defaultMessage="Save"
id="add_emoji.save"
/>
</Memo(SpinnerButton)>
</div>
</form>
</div>
</div>
`;
|
2,157 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker/emoji_picker.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {IntlProvider} from 'react-intl';
import {render, screen} from 'tests/react_testing_utils';
import EmojiMap from 'utils/emoji_map';
import EmojiPicker from './emoji_picker';
jest.mock('components/emoji_picker/components/emoji_picker_skin', () => () => (
<div/>
));
describe('components/emoji_picker/EmojiPicker', () => {
const intlProviderProps = {
defaultLocale: 'en',
locale: 'en',
};
const baseProps = {
filter: '',
visible: true,
onEmojiClick: jest.fn(),
handleFilterChange: jest.fn(),
handleEmojiPickerClose: jest.fn(),
customEmojisEnabled: false,
customEmojiPage: 1,
emojiMap: new EmojiMap(new Map()),
recentEmojis: [],
userSkinTone: 'default',
currentTeamName: 'testTeam',
actions: {
getCustomEmojis: jest.fn(),
incrementEmojiPickerPage: jest.fn(),
searchCustomEmojis: jest.fn(),
setUserSkinTone: jest.fn(),
},
};
test('should match snapshot', () => {
const {asFragment} = render(
<IntlProvider {...intlProviderProps}>
<EmojiPicker {...baseProps}/>
</IntlProvider>,
);
expect(asFragment()).toMatchSnapshot();
});
test('Recent category should not exist if there are no recent emojis', () => {
render(
<IntlProvider {...intlProviderProps}>
<EmojiPicker {...baseProps}/>
</IntlProvider>,
);
expect(screen.queryByLabelText('emoji_picker.recent')).toBeNull();
});
test('Recent category should exist if there are recent emojis', () => {
const props = {
...baseProps,
recentEmojis: ['smile'],
};
render(
<IntlProvider {...intlProviderProps}>
<EmojiPicker {...props}/>
</IntlProvider>,
);
expect(screen.queryByLabelText('emoji_picker.recent')).not.toBeNull();
});
});
|
2,161 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker/__snapshots__/emoji_picker.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/emoji_picker/EmojiPicker should match snapshot 1`] = `
<DocumentFragment>
<div
class="emoji-picker__inner"
role="application"
>
<div
aria-live="assertive"
class="sr-only"
>
emoji
</div>
<div
class="emoji-picker__search-container"
>
<div
class="emoji-picker__text-container"
>
<span
class="icon-magnify icon emoji-picker__search-icon"
/>
<input
aria-label="Search for an emoji"
autocomplete="off"
class="emoji-picker__search"
data-testid="emojiInputSearch"
id="emojiPickerSearch"
placeholder="Search Emoji"
type="text"
value=""
/>
</div>
<div />
</div>
<div
class="emoji-picker__categories"
id="emojiPickerCategories"
>
<a
aria-label="emoji_picker.smileys-emotion"
class="emoji-picker__category emoji-picker__category--selected"
href="#"
>
<i
class="icon-emoticon-happy-outline"
/>
</a>
<a
aria-label="emoji_picker.people-body"
class="emoji-picker__category"
href="#"
>
<i
class="icon-account-outline"
/>
</a>
<a
aria-label="emoji_picker.animals-nature"
class="emoji-picker__category"
href="#"
>
<i
class="icon-leaf-outline"
/>
</a>
<a
aria-label="emoji_picker.food-drink"
class="emoji-picker__category"
href="#"
>
<i
class="icon-food-apple"
/>
</a>
<a
aria-label="emoji_picker.travel-places"
class="emoji-picker__category"
href="#"
>
<i
class="icon-airplane-variant"
/>
</a>
<a
aria-label="emoji_picker.activities"
class="emoji-picker__category"
href="#"
>
<i
class="icon-basketball"
/>
</a>
<a
aria-label="emoji_picker.objects"
class="emoji-picker__category"
href="#"
>
<i
class="icon-lightbulb-outline"
/>
</a>
<a
aria-label="emoji_picker.symbols"
class="emoji-picker__category"
href="#"
>
<i
class="icon-heart-outline"
/>
</a>
<a
aria-label="emoji_picker.flags"
class="emoji-picker__category"
href="#"
>
<i
class="icon-flag-outline"
/>
</a>
<a
aria-label="emoji_picker.custom"
class="emoji-picker__category"
href="#"
>
<i
class="icon-emoticon-custom-outline"
/>
</a>
</div>
<div
class="emoji-picker__items"
style="height: 290px;"
>
<div
class="emoji-picker__container"
>
<div
style="overflow: visible; height: 0px; width: 0px;"
/>
<div
class="resize-triggers"
>
<div
class="expand-trigger"
>
<div
style="width: 1px; height: 1px;"
/>
</div>
<div
class="contract-trigger"
/>
</div>
</div>
</div>
<div
class="emoji-picker__footer"
>
<div
class="emoji-picker__preview emoji-picker__preview-placeholder"
>
Select an Emoji
</div>
</div>
</div>
</DocumentFragment>
`;
|
2,168 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker/components/emoji_picker_header.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import EmojiPickerHeader from 'components/emoji_picker/components/emoji_picker_header';
describe('components/emoji_picker/components/EmojiPickerHeader', () => {
test('should match snapshot, ', () => {
const props = {
handleEmojiPickerClose: jest.fn(),
};
const wrapper = shallow(
<EmojiPickerHeader {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('handleEmojiPickerClose, should have called props.handleEmojiPickerClose', () => {
const props = {
handleEmojiPickerClose: jest.fn(),
};
const wrapper = shallow(
<EmojiPickerHeader {...props}/>,
);
expect(wrapper).toMatchSnapshot();
wrapper.find('button').first().simulate('click');
expect(props.handleEmojiPickerClose).toHaveBeenCalledTimes(1);
});
});
|
2,174 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker/components/__snapshots__/emoji_picker_header.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/emoji_picker/components/EmojiPickerHeader handleEmojiPickerClose, should have called props.handleEmojiPickerClose 1`] = `
<div
className="emoji-picker__header modal-header"
>
<button
className="close emoji-picker__header-close-button"
onClick={[MockFunction]}
type="button"
>
<span
aria-hidden="true"
>
×
</span>
<span
className="sr-only"
>
<MemoizedFormattedMessage
defaultMessage="Close"
id="emoji_picker.close"
/>
</span>
</button>
<h4
className="modal-title emoji-picker__header-title"
>
<MemoizedFormattedMessage
defaultMessage="Emoji Picker"
id="emoji_picker.header"
/>
</h4>
</div>
`;
exports[`components/emoji_picker/components/EmojiPickerHeader should match snapshot, 1`] = `
<div
className="emoji-picker__header modal-header"
>
<button
className="close emoji-picker__header-close-button"
onClick={[MockFunction]}
type="button"
>
<span
aria-hidden="true"
>
×
</span>
<span
className="sr-only"
>
<MemoizedFormattedMessage
defaultMessage="Close"
id="emoji_picker.close"
/>
</span>
</button>
<h4
className="modal-title emoji-picker__header-title"
>
<MemoizedFormattedMessage
defaultMessage="Emoji Picker"
id="emoji_picker.header"
/>
</h4>
</div>
`;
|
2,179 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker | petrpan-code/mattermost/mattermost/webapp/channels/src/components/emoji_picker/utils/index.test.ts | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {
isCategoryHeaderRow,
getFilteredEmojis,
calculateCategoryRowIndex,
splitEmojisToRows,
createEmojisPositions,
createCategoryAndEmojiRows,
} from 'components/emoji_picker/utils';
enum SkinTones {
Light = '1F3FB',
MediumLight ='1F3FC',
Medium = '1F3FD',
MediumDark = '1F3FE',
Dark = '1F3FF'
}
const smileEmoji = {
unified: 'smile',
short_names: 'smile',
name: 'smile',
};
const thumbsupEmoji = {
name: 'THUMBS UP SIGN',
unified: '1F44D',
short_names: [
'+1',
'thumbsup',
],
};
const thumbsupEmojiLightSkin = {
unified: '1F44D-1F3FB',
short_name: '+1_light_skin_tone',
short_names: [
'+1_light_skin_tone',
'thumbsup_light_skin_tone',
],
name: 'THUMBS UP SIGN: LIGHT SKIN TONE',
category: 'people-body',
skins: [
'1F3FB',
],
};
const thumbsupEmojiMediumSkin = {
unified: '1F44D-1F3FD',
short_name: '+1_medium_skin_tone',
short_names: [
'+1_medium_skin_tone',
'thumbsup_medium_skin_tone',
],
name: 'THUMBS UP SIGN: MEDIUM SKIN TONE',
category: 'people-body',
skins: [
'1F3FD',
],
};
const thumbsupEmojiDarkSkin = {
unified: '1F44D-1F3FF',
short_name: '+1_dark_skin_tone',
short_names: [
'+1_dark_skin_tone',
'thumbsup_dark_skin_tone',
],
name: 'THUMBS UP SIGN: DARK SKIN TONE',
category: 'people-body',
skins: [
'1F3FF',
],
};
const thumbsdownEmoji = {
unified: 'thumbsdown',
short_names: ['thumbs_down', 'down'],
name: 'thumbsdown',
};
const okEmoji = {
unified: 'ok',
short_names: ['ok', 'ok_hand'],
name: 'ok',
};
const hundredEmoji = {
unified: 'hundred',
short_names: ['hundred', '100'],
name: 'hundred',
};
const recentCategory = {
id: 'recent',
message: 'recent_message',
name: 'recent',
className: 'recent-classname',
emojiIds: [hundredEmoji.unified, okEmoji.unified],
};
describe('isCategoryHeaderRow', () => {
test('should return true if its a category header row', () => {
const categoryHeaderRow: any = {
index: 1,
type: 'categoryHeaderRow',
};
expect(isCategoryHeaderRow(categoryHeaderRow)).toBe(true);
});
test('should return false if its emoji row', () => {
const emojiRow: any = {
index: 1,
type: 'emojiRow',
};
expect(isCategoryHeaderRow(emojiRow)).toBe(false);
});
});
describe('getFilteredEmojis', () => {
test('Should show no result when there are no emojis to start with', () => {
const allEmojis = {};
const filter = 'example';
const recentEmojisString: string[] = [];
const userSkinTone = '';
expect(getFilteredEmojis(allEmojis, filter, recentEmojisString, userSkinTone)).toEqual([]);
});
test('Should return same result when no filter is applied', () => {
const allEmojis = {
smile: smileEmoji,
thumbsup: thumbsupEmoji,
thumbsdown: thumbsdownEmoji,
};
const filter = '';
const recentEmojisString: string[] = [];
const userSkinTone = '';
const filteredEmojis = [
smileEmoji,
thumbsupEmoji,
thumbsdownEmoji,
];
expect(getFilteredEmojis(allEmojis as any, filter, recentEmojisString, userSkinTone)).toStrictEqual(filteredEmojis);
});
test('Should return correct result of single match when appropriate filter is applied', () => {
const allEmojis = {
smile: smileEmoji,
thumbsup: thumbsupEmoji,
thumbsdown: thumbsdownEmoji,
};
const filter = 'up';
const recentEmojisString: string[] = [];
const userSkinTone = '';
expect(getFilteredEmojis(allEmojis as any, filter, recentEmojisString, userSkinTone)).toStrictEqual([thumbsupEmoji]);
});
test('Should return correct result of multiple match when appropriate filter is applied', () => {
const allEmojis = {
smile: smileEmoji,
thumbsup: thumbsupEmoji,
thumbsdown: thumbsdownEmoji,
};
const filter = 'thumbs';
const recentEmojisString: string[] = [];
const userSkinTone = '';
const filteredResults = [
thumbsdownEmoji,
thumbsupEmoji,
];
expect(getFilteredEmojis(allEmojis as any, filter, recentEmojisString, userSkinTone)).toEqual(filteredResults);
});
test('Should return correct order of result when filter is applied and contains recently used emojis', () => {
const allEmojis = {
smile: smileEmoji,
thumbsup: thumbsupEmoji,
thumbsdown: thumbsdownEmoji,
};
const filter = 'thumbs';
const recentEmojisString = ['thumbsup'];
const userSkinTone = '';
const filteredResults = [
thumbsupEmoji,
thumbsdownEmoji,
];
expect(getFilteredEmojis(allEmojis as any, filter, recentEmojisString, userSkinTone)).toEqual(filteredResults);
});
test('Should filter emojis containing skin tone with user skin tone', () => {
const allEmojis = {
thumbsup: thumbsupEmoji,
thumbsupDark: thumbsupEmojiDarkSkin,
thumbsupLight: thumbsupEmojiLightSkin,
thumbsupMedium: thumbsupEmojiMediumSkin,
};
const filter = 'thumbs';
const recentEmojisString: string[] = [];
const userSkinTone = SkinTones.Dark;
// Note that filteredResults doesn't match what will be returned in a real use case because the variants of
// thumbsup will be deduped when using non-test data
const filteredResults = [
thumbsupEmoji,
thumbsupEmojiDarkSkin,
];
expect(getFilteredEmojis(allEmojis as any, filter, recentEmojisString, userSkinTone)).toEqual(filteredResults);
});
test('Should filter recent emojis', () => {
const allEmojis = {
thumbsup: thumbsupEmoji,
thumbsupDark: thumbsupEmojiDarkSkin,
thumbsupLight: thumbsupEmojiLightSkin,
thumbsupMedium: thumbsupEmojiMediumSkin,
};
const filter = 'thumbs';
const recentEmojisString = ['thumbsupDark'];
const userSkinTone = SkinTones.Dark;
// Note that filteredResults doesn't match what will be returned in a real use case because the variants of
// thumbsup will be deduped when using non-test data
const filteredResults = [
thumbsupEmojiDarkSkin,
thumbsupEmoji,
];
expect(getFilteredEmojis(allEmojis as any, filter, recentEmojisString, userSkinTone)).toEqual(filteredResults);
});
});
describe('calculateCategoryRowIndex', () => {
const categories = {
recent: recentCategory,
'people-body': {
emojiIds: ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9', 'p10', 'p11', 'p12', 'p13', 'p14', 'p15'],
id: 'people-body',
name: 'people-body',
},
'animals-nature': {
emojiIds: ['n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7', 'n8', 'n9'],
id: 'animals-nature',
name: 'animals-nature',
},
'food-drink': {
emojiIds: ['f1'],
id: 'food-drink',
name: 'food-drink',
},
};
test('Should return 0 row index for first category', () => {
expect(calculateCategoryRowIndex(categories as any, 'recent')).toBe(0);
});
test('Should return correct row index when emojis in a category are more than emoji_per_row', () => {
expect(calculateCategoryRowIndex(categories as any, 'animals-nature')).toBe(2 + 3);
});
test('Should return correct row index when emoji in previous category are less than emoji_per_row', () => {
expect(calculateCategoryRowIndex(categories as any, 'food-drink')).toBe(2 + 3 + 2);
});
});
describe('splitEmojisToRows', () => {
test('Should return empty when no emojis are passed', () => {
expect(splitEmojisToRows([], 0, 'recent', 0)).toEqual([[], -1]);
});
test('Should create only one row when passed emojis are less than emoji_per_row', () => {
const emojis = [
smileEmoji,
thumbsupEmoji,
];
const emojiRow = [{
index: 0,
type: 'emojisRow',
items: [
{
categoryIndex: 0,
categoryName: 'recent',
emojiIndex: 0,
emojiId: smileEmoji.unified,
item: smileEmoji,
},
{
categoryIndex: 0,
categoryName: 'recent',
emojiIndex: 1,
emojiId: thumbsupEmoji.unified,
item: thumbsupEmoji,
},
],
}];
expect(splitEmojisToRows(emojis as any, 0, 'recent', 0)).toEqual([emojiRow, 1]);
});
test('Should create only more than one row when passed emojis are more than emoji_per_row', () => {
const emojis = [
smileEmoji,
thumbsupEmoji,
thumbsdownEmoji,
smileEmoji,
thumbsupEmoji,
thumbsdownEmoji,
smileEmoji,
thumbsupEmoji,
thumbsdownEmoji,
smileEmoji,
];
expect(splitEmojisToRows(emojis as any, 0, 'recent', 0)[1]).toEqual(2);
});
});
describe('createEmojisPositions', () => {
test('Should not create emoji positions for category header row', () => {
const categoryOrEmojiRows = [{
index: 1,
type: 'categoryHeaderRow',
}];
expect(createEmojisPositions(categoryOrEmojiRows as any)).toEqual([]);
});
test('Should create emoji positions correctly', () => {
const categoryOrEmojiRows = [
{
index: 0,
type: 'categoryHeaderRow',
},
{
index: 1,
type: 'emojisRow',
items: [
{
categoryIndex: 0,
categoryName: 'recent',
emojiIndex: 0,
emojiId: smileEmoji.unified,
item: smileEmoji,
},
{
categoryIndex: 0,
categoryName: 'recent',
emojiIndex: 1,
emojiId: thumbsupEmoji.unified,
item: thumbsupEmoji,
},
],
},
];
expect(createEmojisPositions(categoryOrEmojiRows as any).length).toBe(2);
expect(createEmojisPositions(categoryOrEmojiRows as any)).toEqual([
{
rowIndex: 1,
emojiId: smileEmoji.unified,
categoryName: 'recent',
},
{
rowIndex: 1,
emojiId: thumbsupEmoji.unified,
categoryName: 'recent',
},
]);
});
});
describe('createCategoryAndEmojiRows', () => {
test('Should return empty for no categories or emojis', () => {
const categories = {
recent: recentCategory,
};
expect(createCategoryAndEmojiRows([] as any, categories as any, '', '')).toEqual([[], []]);
const allEmojis = {
smile: smileEmoji,
thumbsup: thumbsupEmoji,
};
expect(createCategoryAndEmojiRows(allEmojis as any, [] as any, '', '')).toEqual([[], []]);
});
test('Should return search results on filter is on', () => {
const allEmojis = {
smile: smileEmoji,
thumbsup: thumbsupEmoji,
thumbsdown: thumbsdownEmoji,
};
const categories = {
recent: {...recentCategory, emojiIds: ['thumbsup']},
'people-body': {
id: 'people-body',
name: 'people-body',
emojiIds: ['smile', 'thumbsup', 'thumbsdown'],
},
};
const categoryAndEmojiRows = [
{
index: 0,
type: 'categoryHeaderRow',
items: [{
categoryIndex: 0,
categoryName: 'searchResults',
emojiId: '',
emojiIndex: -1,
item: undefined,
}],
},
{
index: 1,
type: 'emojisRow',
items: [
{
categoryIndex: 0,
categoryName: 'searchResults',
emojiIndex: 0,
emojiId: thumbsupEmoji.unified,
item: thumbsupEmoji,
},
{
categoryIndex: 0,
categoryName: 'searchResults',
emojiIndex: 1,
emojiId: thumbsdownEmoji.unified,
item: thumbsdownEmoji,
},
],
},
];
const emojiPositions = [
{
rowIndex: 1,
emojiId: thumbsupEmoji.unified,
categoryName: 'searchResults',
},
{
rowIndex: 1,
emojiId: thumbsdownEmoji.unified,
categoryName: 'searchResults',
},
];
expect(createCategoryAndEmojiRows(allEmojis as any, categories as any, 'thumbs', '')).toEqual([categoryAndEmojiRows, emojiPositions]);
});
test('Should construct correct category and emoji rows along with emoji positions', () => {
const allEmojis = {
hundred: hundredEmoji,
ok: okEmoji,
};
const categories = {
'people-body': {
id: 'people-body',
name: 'people-body',
emojiIds: ['hundred', 'ok'],
},
};
expect(createCategoryAndEmojiRows(allEmojis as any, categories as any, '', '')[0]).toEqual([
{
index: 0,
type: 'categoryHeaderRow',
items: [{
categoryIndex: 0,
categoryName: 'people-body',
emojiId: '',
emojiIndex: -1,
item: undefined,
}],
},
{
index: 1,
type: 'emojisRow',
items: [
{
categoryIndex: 0,
categoryName: 'people-body',
emojiIndex: 0,
emojiId: hundredEmoji.unified,
item: hundredEmoji,
},
{
categoryIndex: 0,
categoryName: 'people-body',
emojiIndex: 1,
emojiId: okEmoji.unified,
item: okEmoji,
},
],
},
]);
expect(createCategoryAndEmojiRows(allEmojis as any, categories as any, '', '')[1]).toEqual([
{
rowIndex: 1,
emojiId: hundredEmoji.unified,
categoryName: 'people-body',
},
{
rowIndex: 1,
emojiId: okEmoji.unified,
categoryName: 'people-body',
},
]);
});
});
|
2,181 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/error_link.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import ErrorLink from 'components/error_page/error_link';
describe('components/error_page/ErrorLink', () => {
const baseProps = {
url: 'https://docs.mattermost.com/deployment/sso-gitlab.html',
messageId: 'error.oauth_missing_code.gitlab.link',
defaultMessage: 'GitLab',
};
test('should match snapshot', () => {
const wrapper = shallow(
<ErrorLink {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,183 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/error_message.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import ErrorMessage from 'components/error_page/error_message';
import {ErrorPageTypes} from 'utils/constants';
describe('components/error_page/ErrorMessage', () => {
const baseProps = {
type: ErrorPageTypes.LOCAL_STORAGE,
message: '',
service: '',
};
test('should match snapshot, local_storage type', () => {
const wrapper = shallow(
<ErrorMessage {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, permalink_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.PERMALINK_NOT_FOUND};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_missing_code type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_MISSING_CODE, service: 'Gitlab'};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_access_denied type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_ACCESS_DENIED, service: 'Gitlab'};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_invalid_param type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_INVALID_PARAM, message: 'error message'};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_invalid_redirect_url type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_INVALID_REDIRECT_URL, message: 'error message'};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, page_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.PAGE_NOT_FOUND};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, team_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.TEAM_NOT_FOUND};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, channel_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.CHANNEL_NOT_FOUND};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
const wrapper2 = shallow(
<ErrorMessage
{...props}
isGuest={true}
/>,
);
expect(wrapper2).toMatchSnapshot();
});
test('should match snapshot, no type but with message', () => {
const props = {...baseProps, type: '', message: 'error message'};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, no type nor message', () => {
const props = {...baseProps, type: '', message: ''};
const wrapper = shallow(
<ErrorMessage {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,185 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/error_page.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {GlobalState} from '@mattermost/types/store';
import {renderWithContext, screen} from 'tests/react_testing_utils';
import {ErrorPageTypes} from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import ErrorPage from './error_page';
describe('ErrorPage', () => {
it('displays cloud archived page correctly', () => {
renderWithContext(
(
<ErrorPage
location={{
search: `?type=${ErrorPageTypes.CLOUD_ARCHIVED}`,
}}
/>
),
{
entities: {
cloud: {
subscription: TestHelper.getSubscriptionMock({
product_id: 'prod_a',
}),
products: {
prod_a: TestHelper.getProductMock({
id: 'prod_a',
name: 'cloud plan',
}),
},
},
},
} as unknown as GlobalState,
);
screen.getByText('Message Archived');
screen.getByText('archived because of cloud plan limits', {exact: false});
});
});
|
2,187 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/error_title.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import ErrorTitle from 'components/error_page/error_title';
import {ErrorPageTypes} from 'utils/constants';
describe('components/error_page/ErrorTitle', () => {
const baseProps = {
type: ErrorPageTypes.LOCAL_STORAGE,
title: '',
};
test('should match snapshot, local_storage type', () => {
const wrapper = shallow(
<ErrorTitle {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, permalink_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.PERMALINK_NOT_FOUND};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_missing_code type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_MISSING_CODE};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_access_denied type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_ACCESS_DENIED};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_invalid_param type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_INVALID_PARAM};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, oauth_invalid_redirect_url type', () => {
const props = {...baseProps, type: ErrorPageTypes.OAUTH_INVALID_REDIRECT_URL};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, page_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.PAGE_NOT_FOUND};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, team_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.TEAM_NOT_FOUND};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, channel_not_found type', () => {
const props = {...baseProps, type: ErrorPageTypes.CHANNEL_NOT_FOUND};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, no type but with title', () => {
const props = {...baseProps, type: '', title: 'error title'};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, no type nor title', () => {
const props = {...baseProps, type: '', title: ''};
const wrapper = shallow(
<ErrorTitle {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,190 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/__snapshots__/error_link.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/error_page/ErrorLink should match snapshot 1`] = `
<ExternalLink
href="https://docs.mattermost.com/deployment/sso-gitlab.html"
location="error_link"
>
<MemoizedFormattedMessage
defaultMessage="GitLab"
id="error.oauth_missing_code.gitlab.link"
/>
</ExternalLink>
`;
|
2,191 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/__snapshots__/error_message.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/error_page/ErrorMessage should match snapshot, channel_not_found type 1`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="The channel you're requesting is private or does not exist. Please contact an Administrator to be added to the channel."
id="error.channel_not_found.message"
/>
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, channel_not_found type 2`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="Your guest account has no channels assigned. Please contact an administrator."
id="error.channel_not_found.message_guest"
/>
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, local_storage type 1`] = `
<div>
<MemoizedFormattedMessage
defaultMessage="Mattermost was unable to load because a setting in your browser prevents the use of its local storage features. To allow Mattermost to load, try the following actions:"
id="error.local_storage.message"
/>
<ul>
<li>
<MemoizedFormattedMessage
defaultMessage="Enable cookies"
id="error.local_storage.help1"
/>
</li>
<li>
<MemoizedFormattedMessage
defaultMessage="Turn off private browsing"
id="error.local_storage.help2"
/>
</li>
<li>
<MemoizedFormattedMessage
defaultMessage="Use a supported browser (IE 11, Chrome 61+, Firefox 60+, Safari 12+, Edge 42+)"
id="error.local_storage.help3"
/>
</li>
</ul>
</div>
`;
exports[`components/error_page/ErrorMessage should match snapshot, no type but with message 1`] = `
<p>
error message
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, no type nor message 1`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="An error has occurred."
id="error.generic.message"
/>
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, oauth_access_denied type 1`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="You must authorize Mattermost to log in with {service}."
id="error.oauth_access_denied"
values={
Object {
"service": "Gitlab",
}
}
/>
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, oauth_invalid_param type 1`] = `
<p>
error message
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, oauth_invalid_redirect_url type 1`] = `
<p>
error message
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, oauth_missing_code type 1`] = `
<div>
<p>
<MemoizedFormattedMessage
defaultMessage="The service provider {service} did not provide an authorization code in the redirect URL."
id="error.oauth_missing_code"
values={
Object {
"service": "Gitlab",
}
}
/>
</p>
<p>
<MemoizedFormattedMessage
defaultMessage="For {link} make sure your administrator enabled the Google+ API."
id="error.oauth_missing_code.google"
values={
Object {
"link": <ErrorLink
defaultMessage="Google Apps"
messageId="error.oauth_missing_code.google.link"
url="https://docs.mattermost.com/deployment/sso-google.html"
/>,
}
}
/>
</p>
<p>
<MemoizedFormattedMessage
defaultMessage="For {link} make sure the administrator of your Microsoft organization has enabled the Mattermost app."
id="error.oauth_missing_code.office365"
values={
Object {
"link": <ErrorLink
defaultMessage="Office 365"
messageId="error.oauth_missing_code.office365.link"
url="https://docs.mattermost.com/deployment/sso-office.html"
/>,
}
}
/>
</p>
<p>
<MemoizedFormattedMessage
defaultMessage="For {link} please make sure you followed the setup instructions."
id="error.oauth_missing_code.gitlab"
values={
Object {
"link": <ErrorLink
defaultMessage="GitLab"
messageId="error.oauth_missing_code.gitlab.link"
url="https://docs.mattermost.com/deployment/sso-gitlab.html"
/>,
}
}
/>
</p>
<p>
<MemoizedFormattedMessage
defaultMessage="If you reviewed the above and are still having trouble with configuration, you may post in our {link} where we'll be happy to help with issues during setup."
id="error.oauth_missing_code.forum"
values={
Object {
"link": <ErrorLink
defaultMessage="Troubleshooting forum"
messageId="error.oauth_missing_code.forum.link"
url="https://forum.mattermost.com/c/trouble-shoot"
/>,
}
}
/>
</p>
</div>
`;
exports[`components/error_page/ErrorMessage should match snapshot, page_not_found type 1`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="The page you were trying to reach does not exist"
id="error.not_found.message"
/>
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, permalink_not_found type 1`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="Permalink belongs to a deleted message or to a channel to which you do not have access."
id="permalink.error.access"
/>
</p>
`;
exports[`components/error_page/ErrorMessage should match snapshot, team_not_found type 1`] = `
<p>
<MemoizedFormattedMessage
defaultMessage="The team you're requesting is private or does not exist. Please contact your Administrator for an invitation."
id="error.team_not_found.message"
/>
</p>
`;
|
2,192 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page | petrpan-code/mattermost/mattermost/webapp/channels/src/components/error_page/__snapshots__/error_title.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/error_page/ErrorTitle should match snapshot, channel_not_found type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Channel Not Found"
id="error.channel_not_found.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, local_storage type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Cannot Load Mattermost"
id="error.local_storage.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, no type but with title 1`] = `
<Fragment>
error title
</Fragment>
`;
exports[`components/error_page/ErrorTitle should match snapshot, no type nor title 1`] = `
<Fragment>
Error
</Fragment>
`;
exports[`components/error_page/ErrorTitle should match snapshot, oauth_access_denied type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Authorization Error"
id="error.oauth_access_denied.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, oauth_invalid_param type 1`] = `
<MemoizedFormattedMessage
defaultMessage="OAuth Parameter Error"
id="error.oauth_invalid_param.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, oauth_invalid_redirect_url type 1`] = `
<MemoizedFormattedMessage
defaultMessage="OAuth Parameter Error"
id="error.oauth_invalid_param.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, oauth_missing_code type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Mattermost Needs Your Help"
id="error.oauth_missing_code.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, page_not_found type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Page Not Found"
id="error.not_found.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, permalink_not_found type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Message Not Found"
id="permalink.error.title"
/>
`;
exports[`components/error_page/ErrorTitle should match snapshot, team_not_found type 1`] = `
<MemoizedFormattedMessage
defaultMessage="Team Not Found"
id="error.team_not_found.title"
/>
`;
|
2,194 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/external_image/external_image.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Client4} from 'mattermost-redux/client';
import ExternalImage from './external_image';
describe('ExternalImage', () => {
const baseProps = {
children: jest.fn((src) => <img src={src}/>),
enableSVGs: true,
imageMetadata: {
format: 'png',
frameCount: 20,
height: 300,
width: 200,
},
hasImageProxy: false,
src: 'https://example.com/image.png',
};
test('should render an image', () => {
const wrapper = shallow(<ExternalImage {...baseProps}/>);
expect(baseProps.children).toHaveBeenCalledWith(baseProps.src);
expect(wrapper.find('img').exists()).toBe(true);
});
test('should render an image without image metadata', () => {
const props = {
...baseProps,
imageMetadata: undefined,
};
const wrapper = shallow(<ExternalImage {...props}/>);
expect(baseProps.children).toHaveBeenCalledWith(baseProps.src);
expect(wrapper.find('img').exists()).toBe(true);
});
test('should render an SVG when enabled', () => {
const props = {
...baseProps,
imageMetadata: {
format: 'svg',
frameCount: 20,
height: 0,
width: 0,
},
src: 'https://example.com/logo.svg',
};
const wrapper = shallow(<ExternalImage {...props}/>);
expect(props.children).toHaveBeenCalledWith(props.src);
expect(wrapper.find('img').exists()).toBe(true);
});
test('should not render an SVG when disabled', () => {
const props = {
...baseProps,
enableSVGs: false,
imageMetadata: {
format: 'svg',
frameCount: 20,
height: 0,
width: 0,
},
src: 'https://example.com/logo.svg',
};
const wrapper = shallow(<ExternalImage {...props}/>);
expect(props.children).toHaveBeenCalledWith('');
expect(wrapper.find('img').exists()).toBe(true);
});
test('should pass src through the image proxy when enabled', () => {
const props = {
...baseProps,
hasImageProxy: true,
};
const wrapper = shallow(<ExternalImage {...props}/>);
expect(props.children).toHaveBeenCalledWith(Client4.getBaseRoute() + '/image?url=' + encodeURIComponent(props.src));
expect(wrapper.find('img').exists()).toBe(true);
});
});
|
2,197 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/external_image/is_svg_image.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {isSVGImage} from './is_svg_image';
describe('ExternalIImage isSVGImage', () => {
for (const testCase of [
{
name: 'no metadata, no extension',
src: 'https://example.com/image.png',
imageMetadata: undefined,
expected: false,
},
{
name: 'no metadata, svg extension',
src: 'https://example.com/image.svg',
imageMetadata: undefined,
expected: true,
},
{
name: 'no metadata, svg extension with query parameter',
src: 'https://example.com/image.svg?a=1',
imageMetadata: undefined,
expected: true,
},
{
name: 'no metadata, svg extension with hash',
src: 'https://example.com/image.svg#abc',
imageMetadata: undefined,
expected: true,
},
{
name: 'no metadata, proxied image',
src: 'https://mattermost.example.com/api/v4/image?url=' + encodeURIComponent('https://example.com/image.png'),
imageMetadata: undefined,
expected: false,
},
{
name: 'no metadata, proxied svg image',
src: 'https://mattermost.example.com/api/v4/image?url=' + encodeURIComponent('https://example.com/image.svg'),
imageMetadata: undefined,
expected: true,
},
{
name: 'with metadata, not an SVG',
src: 'https://example.com/image.png',
imageMetadata: {
format: 'png',
frameCount: 40,
width: 100,
height: 200,
},
expected: false,
},
{
name: 'with metadata, SVG',
src: 'https://example.com/image.svg',
imageMetadata: {
format: 'svg',
frameCount: 30,
width: 10,
height: 20,
},
expected: true,
},
]) {
test(testCase.name, () => {
const {imageMetadata, src} = testCase;
expect(isSVGImage(imageMetadata, src)).toBe(testCase.expected);
});
}
});
|
2,199 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/external_link/external_link.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {mount} from 'enzyme';
import React from 'react';
import {Provider} from 'react-redux';
import type {DeepPartial} from 'redux';
import {renderWithContext, screen} from 'tests/react_testing_utils';
import mockStore from 'tests/test_store';
import type {GlobalState} from 'types/store';
import ExternalLink from '.';
describe('components/external_link', () => {
const initialState: DeepPartial<GlobalState> = {
entities: {
general: {
config: {},
license: {
Cloud: 'true',
},
},
users: {
currentUserId: 'currentUserId',
},
},
};
it('should match snapshot', () => {
const store = mockStore(initialState);
const wrapper = mount(
<Provider store={store}>
<ExternalLink
href='https://mattermost.com'
>{'Click Me'}</ExternalLink>
</Provider>,
);
expect(wrapper).toMatchSnapshot();
});
it('should attach parameters', () => {
const state = {
...initialState,
entities: {
...initialState.entities,
general: {
...initialState?.entities?.general,
config: {
DiagnosticsEnabled: 'true',
},
},
},
};
renderWithContext(
<ExternalLink href='https://mattermost.com'>
{'Click Me'}
</ExternalLink>,
state,
);
expect(screen.queryByText('Click Me')).toHaveAttribute(
'href',
expect.stringMatching('utm_source=mattermost&utm_medium=in-product-cloud&utm_content=&uid=currentUserId&sid='),
);
});
it('should preserve query params that already exist in the href', () => {
const state = {
...initialState,
entities: {
...initialState.entities,
general: {
...initialState?.entities?.general,
config: {
DiagnosticsEnabled: 'true',
},
},
},
};
renderWithContext(
<ExternalLink href='https://mattermost.com?test=true'>
{'Click Me'}
</ExternalLink>,
state,
);
expect(screen.queryByText('Click Me')).toHaveAttribute(
'href',
'https://mattermost.com?utm_source=mattermost&utm_medium=in-product-cloud&utm_content=&uid=currentUserId&sid=&test=true',
);
});
it("should not attach parameters if href isn't *.mattermost.com enabled", () => {
const state = {
...initialState,
entities: {
...initialState.entities,
general: {
...initialState?.entities?.general,
config: {
DiagnosticsEnabled: 'true',
},
},
},
};
renderWithContext(
<ExternalLink href='https://google.com'>
{'Click Me'}
</ExternalLink>,
state,
);
expect(screen.queryByText('Click Me')).not.toHaveAttribute(
'href',
'utm_source=mattermost&utm_medium=in-product-cloud&utm_content=&uid=currentUserId&sid=',
);
});
it('should be able to override target, rel', () => {
const state = {
...initialState,
entities: {
...initialState.entities,
general: {
...initialState?.entities?.general,
config: {
DiagnosticsEnabled: 'true',
},
},
},
};
renderWithContext(
<ExternalLink
target='test'
rel='test'
href='https://google.com'
>{'Click Me'}</ExternalLink>,
state,
);
expect(screen.queryByText('Click Me')).toHaveAttribute(
'target',
expect.stringMatching(
'test',
),
);
expect(screen.queryByText('Click Me')).toHaveAttribute(
'rel',
expect.stringMatching('test'),
);
});
it('renders href correctly when url contains anchor by setting anchor at the end', () => {
const state = {
...initialState,
entities: {
...initialState.entities,
general: {
...initialState?.entities?.general,
config: {
DiagnosticsEnabled: 'true',
},
},
},
};
renderWithContext(
<ExternalLink
href='https://mattermost.com#desktop'
>
{'Click Me'}
</ExternalLink>,
state,
);
expect(screen.queryByText('Click Me')).toHaveAttribute(
'href',
'https://mattermost.com?utm_source=mattermost&utm_medium=in-product-cloud&utm_content=&uid=currentUserId&sid=#desktop',
);
});
});
|
2,201 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/external_link | petrpan-code/mattermost/mattermost/webapp/channels/src/components/external_link/__snapshots__/external_link.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/external_link should match snapshot 1`] = `
<Provider
store={
Object {
"clearActions": [Function],
"dispatch": [Function],
"getActions": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
}
}
>
<ExternalLink
href="https://mattermost.com"
>
<a
href="https://mattermost.com?utm_source=mattermost&utm_medium=in-product-cloud&utm_content=&uid=currentUserId&sid="
onClick={[Function]}
rel="noopener noreferrer"
target="_blank"
>
Click Me
</a>
</ExternalLink>
</Provider>
`;
|
2,204 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/favicon_title_handler/favicon_title_handler.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import type {ShallowWrapper} from 'enzyme';
import React from 'react';
import type {ComponentProps} from 'react';
import type {ChannelType} from '@mattermost/types/channels';
import type {TeamType} from '@mattermost/types/teams';
import FaviconTitleHandler from 'components/favicon_title_handler/favicon_title_handler';
import type {FaviconTitleHandlerClass} from 'components/favicon_title_handler/favicon_title_handler';
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import {Constants} from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import {isChrome, isFirefox} from 'utils/user_agent';
type Props = ComponentProps<typeof FaviconTitleHandlerClass>;
jest.mock('utils/user_agent', () => {
const original = jest.requireActual('utils/user_agent');
return {
...original,
isFirefox: jest.fn().mockReturnValue(true),
isChrome: jest.fn(),
};
});
describe('components/FaviconTitleHandler', () => {
const defaultProps = {
unreadStatus: false,
siteName: 'Test site',
currentChannel: TestHelper.getChannelMock({
id: 'c1',
display_name: 'Public test 1',
name: 'public-test-1',
type: Constants.OPEN_CHANNEL as ChannelType,
}),
currentTeam: TestHelper.getTeamMock({
id: 'team_id',
name: 'test-team',
display_name: 'Test team display name',
description: 'Test team description',
type: 'team-type' as TeamType,
}),
currentTeammate: null,
inGlobalThreads: false,
inDrafts: false,
};
test('set correctly the title when needed', () => {
const wrapper = shallowWithIntl(
<FaviconTitleHandler {...defaultProps}/>,
) as unknown as ShallowWrapper<Props, any, FaviconTitleHandlerClass>;
const instance = wrapper.instance();
instance.updateTitle();
instance.componentDidUpdate = jest.fn();
instance.render = jest.fn();
expect(document.title).toBe('Public test 1 - Test team display name Test site');
wrapper.setProps({
siteName: undefined,
});
instance.updateTitle();
expect(document.title).toBe('Public test 1 - Test team display name');
wrapper.setProps({
currentChannel: {id: '1', type: Constants.DM_CHANNEL} as Props['currentChannel'],
currentTeammate: {display_name: 'teammate'} as Props['currentTeammate'],
});
instance.updateTitle();
expect(document.title).toBe('teammate - Test team display name');
wrapper.setProps({
unreadStatus: 3,
});
instance.updateTitle();
expect(document.title).toBe('(3) teammate - Test team display name');
wrapper.setProps({
currentChannel: {} as Props['currentChannel'],
currentTeammate: {} as Props['currentTeammate']});
instance.updateTitle();
expect(document.title).toBe('Mattermost - Join a team');
});
test('should set correct title on mentions on safari', () => {
// in safari browser, modification of favicon is not
// supported, hence we need to show * in title on mentions
(isFirefox as jest.Mock).mockImplementation(() => false);
(isChrome as jest.Mock).mockImplementation(() => false);
const wrapper = shallowWithIntl(
<FaviconTitleHandler {...defaultProps}/>,
) as unknown as ShallowWrapper<Props, any, FaviconTitleHandlerClass>;
const instance = wrapper.instance();
wrapper.setProps({
siteName: undefined,
});
wrapper.setProps({
currentChannel: {id: '1', type: Constants.DM_CHANNEL} as Props['currentChannel'],
currentTeammate: {display_name: 'teammate'} as Props['currentTeammate'],
});
wrapper.setProps({
unreadStatus: 3,
});
instance.updateTitle();
expect(document.title).toBe('(3) * teammate - Test team display name');
});
test('should display correct favicon', () => {
const link = document.createElement('link');
link.rel = 'icon';
document.head.appendChild(link);
const wrapper = shallowWithIntl(
<FaviconTitleHandler {...defaultProps}/>,
) as unknown as ShallowWrapper<Props, any, FaviconTitleHandlerClass>;
const instance = wrapper.instance();
instance.updateFavicon = jest.fn();
wrapper.setProps({
unreadStatus: 3,
});
expect(instance.updateFavicon).lastCalledWith('Mention');
wrapper.setProps({
unreadStatus: true,
});
expect(instance.updateFavicon).lastCalledWith('Unread');
wrapper.setProps({
unreadStatus: false,
});
expect(instance.updateFavicon).lastCalledWith('None');
});
test('should display correct title when in drafts', () => {
const wrapper = shallowWithIntl(
<FaviconTitleHandler
{...defaultProps}
inDrafts={true}
currentChannel={undefined}
siteName={undefined}
/>,
) as unknown as ShallowWrapper<Props, any, FaviconTitleHandlerClass>;
wrapper.instance().updateTitle();
expect(document.title).toBe('Drafts - Test team display name');
});
});
|
2,211 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/feature_restricted_modal/feature_restricted_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {ModalIdentifiers} from 'utils/constants';
import FeatureRestrictedModal from './feature_restricted_modal';
const mockDispatch = jest.fn();
let mockState: any;
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux') as typeof import('react-redux'),
useSelector: (selector: (state: typeof mockState) => unknown) => selector(mockState),
useDispatch: () => mockDispatch,
}));
describe('components/global/product_switcher_menu', () => {
const defaultProps = {
titleAdminPreTrial: 'Title admin pre trial',
messageAdminPreTrial: 'Message admin pre trial',
titleAdminPostTrial: 'Title admin post trial',
messageAdminPostTrial: 'Message admin post trial',
titleEndUser: 'Title end user',
messageEndUser: 'Message end user',
};
beforeEach(() => {
mockState = {
entities: {
users: {
currentUserId: 'user1',
profiles: {
current_user_id: {roles: ''},
user1: {
id: 'user1',
roles: '',
},
},
},
admin: {
prevTrialLicense: {
IsLicensed: 'false',
},
},
general: {
license: {
IsLicensed: 'false',
},
},
cloud: {
subscription: {
id: 'subId',
customer_id: '',
product_id: '',
add_ons: [],
start_at: 0,
end_at: 0,
create_at: 0,
seats: 0,
trial_end_at: 0,
is_free_trial: '',
},
},
},
views: {
modals: {
modalState: {
[ModalIdentifiers.FEATURE_RESTRICTED_MODAL]: {
open: 'true',
},
},
},
},
};
});
test('should show with end user pre trial', () => {
const wrapper = shallow(<FeatureRestrictedModal {...defaultProps}/>);
expect(wrapper.find('.FeatureRestrictedModal__description').text()).toEqual(defaultProps.messageEndUser);
expect(wrapper.find('.FeatureRestrictedModal__terms').length).toEqual(0);
expect(wrapper.find('.FeatureRestrictedModal__buttons').hasClass('single')).toEqual(true);
expect(wrapper.find('.button-plans').length).toEqual(1);
expect(wrapper.find('CloudStartTrialButton').length).toEqual(0);
expect(wrapper.find('StartTrialBtn').length).toEqual(0);
});
test('should show with end user post trial', () => {
const wrapper = shallow(<FeatureRestrictedModal {...defaultProps}/>);
expect(wrapper.find('.FeatureRestrictedModal__description').text()).toEqual(defaultProps.messageEndUser);
expect(wrapper.find('.FeatureRestrictedModal__terms').length).toEqual(0);
expect(wrapper.find('.FeatureRestrictedModal__buttons').hasClass('single')).toEqual(true);
expect(wrapper.find('.button-plans').length).toEqual(1);
expect(wrapper.find('CloudStartTrialButton').length).toEqual(0);
expect(wrapper.find('StartTrialBtn').length).toEqual(0);
});
test('should show with system admin pre trial for self hosted', () => {
mockState.entities.users.profiles.user1.roles = 'system_admin';
const wrapper = shallow(<FeatureRestrictedModal {...defaultProps}/>);
expect(wrapper.find('.FeatureRestrictedModal__description').text()).toEqual(defaultProps.messageAdminPreTrial);
expect(wrapper.find('.FeatureRestrictedModal__terms').length).toEqual(1);
expect(wrapper.find('.FeatureRestrictedModal__buttons').hasClass('single')).toEqual(false);
expect(wrapper.find('.button-plans').length).toEqual(1);
expect(wrapper.find('StartTrialBtn').length).toEqual(1);
});
test('should show with system admin pre trial for cloud', () => {
mockState.entities.users.profiles.user1.roles = 'system_admin';
mockState.entities.general.license = {
Cloud: 'true',
};
const wrapper = shallow(<FeatureRestrictedModal {...defaultProps}/>);
expect(wrapper.find('.FeatureRestrictedModal__description').text()).toEqual(defaultProps.messageAdminPreTrial);
expect(wrapper.find('.FeatureRestrictedModal__terms').length).toEqual(1);
expect(wrapper.find('.FeatureRestrictedModal__buttons').hasClass('single')).toEqual(false);
expect(wrapper.find('.button-plans').length).toEqual(1);
expect(wrapper.find('CloudStartTrialButton').length).toEqual(1);
});
test('should match snapshot with system admin post trial', () => {
mockState.entities.users.profiles.user1.roles = 'system_admin';
mockState.entities.cloud.subscription.is_free_trial = 'false';
mockState.entities.cloud.subscription.trial_end_at = 1;
const wrapper = shallow(<FeatureRestrictedModal {...defaultProps}/>);
expect(wrapper.find('.FeatureRestrictedModal__description').text()).toEqual(defaultProps.messageAdminPostTrial);
expect(wrapper.find('.FeatureRestrictedModal__terms').length).toEqual(0);
expect(wrapper.find('.button-plans').length).toEqual(1);
expect(wrapper.find('CloudStartTrialButton').length).toEqual(0);
});
});
|
2,214 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/file_attachment.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import type {GlobalState} from '@mattermost/types/store';
import type {DeepPartial} from '@mattermost/types/utilities';
import {mountWithIntl} from 'tests/helpers/intl-test-helper';
import {renderWithContext, screen} from 'tests/react_testing_utils';
import FileAttachment from './file_attachment';
jest.mock('utils/utils', () => {
const original = jest.requireActual('utils/utils');
return {
...original,
loadImage: jest.fn((id: string, callback: () => void) => {
if (id !== 'noLoad') {
callback();
}
}),
};
});
jest.mock('mattermost-redux/utils/file_utils', () => {
const original = jest.requireActual('mattermost-redux/utils/file_utils');
return {
...original,
getFileThumbnailUrl: (fileId: string) => fileId,
};
});
describe('FileAttachment', () => {
const baseFileInfo = {
id: 'thumbnail_id',
extension: 'pdf',
name: 'test.pdf',
size: 100,
width: 100,
height: 80,
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
mime_type: '',
clientId: '',
archived: false,
};
const baseProps = {
fileInfo: baseFileInfo,
handleImageClick: jest.fn(),
index: 3,
canDownloadFiles: true,
enableSVGs: false,
enablePublicLink: false,
pluginMenuItems: [],
handleFileDropdownOpened: jest.fn(() => null),
actions: {
openModal: jest.fn(),
},
};
test('should match snapshot, regular file', () => {
const wrapper = shallow(<FileAttachment {...baseProps}/>);
expect(wrapper).toMatchSnapshot();
});
test('non archived file does not show archived elements', () => {
const reduxState: DeepPartial<GlobalState> = {
entities: {
general: {
config: {},
},
users: {
currentUserId: 'currentUserId',
},
},
};
renderWithContext(<FileAttachment {...baseProps}/>, reduxState);
expect(screen.queryByTestId('archived-file-icon')).not.toBeInTheDocument();
expect(screen.queryByText(/This file is archived/)).not.toBeInTheDocument();
});
test('non archived file does not show archived elements in compact display mode', () => {
renderWithContext(<FileAttachment {...{...baseProps, compactDisplay: true}}/>);
expect(screen.queryByTestId('archived-file-icon')).not.toBeInTheDocument();
expect(screen.queryByText(/archived/)).not.toBeInTheDocument();
});
test('should match snapshot, regular image', () => {
const fileInfo = {
...baseFileInfo,
extension: 'png',
name: 'test.png',
width: 600,
height: 400,
size: 100,
};
const props = {...baseProps, fileInfo};
const wrapper = shallow(<FileAttachment {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, small image', () => {
const fileInfo = {
...baseFileInfo,
extension: 'png',
name: 'test.png',
width: 16,
height: 16,
size: 100,
};
const props = {...baseProps, fileInfo};
const wrapper = shallow(<FileAttachment {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, svg image', () => {
const fileInfo = {
...baseFileInfo,
extension: 'svg',
name: 'test.svg',
width: 600,
height: 400,
size: 100,
};
const props = {...baseProps, fileInfo};
const wrapper = shallow(<FileAttachment {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, after change from file to image', () => {
const fileInfo = {
...baseFileInfo,
extension: 'png',
name: 'test.png',
width: 600,
height: 400,
size: 100,
};
const wrapper = shallow(<FileAttachment {...baseProps}/>);
wrapper.setProps({...baseProps, fileInfo});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, with compact display', () => {
const props = {...baseProps, compactDisplay: true};
const wrapper = shallow(<FileAttachment {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, without compact display and without can download', () => {
const props = {...baseProps, canDownloadFiles: false};
const wrapper = shallow(<FileAttachment {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, when file is not loaded', () => {
const wrapper = shallow(<FileAttachment {...{...baseProps, fileInfo: {...baseProps.fileInfo, id: 'noLoad', extension: 'jpg'}, enableSVGs: true}}/>);
expect(wrapper).toMatchSnapshot();
});
test('should blur file attachment link after click', () => {
const props = {...baseProps, compactDisplay: true};
const wrapper = mountWithIntl(<FileAttachment {...props}/>);
const e = {
preventDefault: jest.fn(),
target: {blur: jest.fn()},
};
const a = wrapper.find('#file-attachment-link');
a.simulate('click', e);
expect(e.target.blur).toHaveBeenCalled();
});
describe('archived file', () => {
test('shows archived image instead of real image and explanatory test in compact mode', () => {
const props = {
...baseProps,
fileInfo: {
...baseProps.fileInfo,
archived: true,
},
compactDisplay: true,
};
renderWithContext(<FileAttachment {...props}/>);
screen.getByTestId('archived-file-icon');
screen.getByText(baseProps.fileInfo.name);
screen.getByText(/archived/);
});
test('shows archived image instead of real image and explanatory test in full mode', () => {
const props = {
...baseProps,
fileInfo: {
...baseProps.fileInfo,
archived: true,
},
compactDisplay: false,
};
renderWithContext(<FileAttachment {...props}/>);
screen.getByTestId('archived-file-icon');
screen.getByText(baseProps.fileInfo.name);
screen.getByText(/This file is archived/);
});
});
});
|
2,216 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/filename_overlay.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FilenameOverlay from 'components/file_attachment/filename_overlay';
import AttachmentIcon from 'components/widgets/icons/attachment_icon';
describe('components/file_attachment/FilenameOverlay', () => {
function emptyFunction() {} //eslint-disable-line no-empty-function
const fileInfo = {
id: 'thumbnail_id',
name: 'test_filename',
extension: 'jpg',
width: 100,
height: 80,
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
size: 100,
mime_type: '',
clientId: '',
archived: false,
};
const baseProps = {
fileInfo,
handleImageClick: emptyFunction,
compactDisplay: false,
canDownload: true,
};
test('should match snapshot, standard display', () => {
const wrapper = shallow(
<FilenameOverlay {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, compact display', () => {
const handleImageClick = jest.fn();
const props = {...baseProps, compactDisplay: true, handleImageClick};
const wrapper = shallow(
<FilenameOverlay {...props}/>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(AttachmentIcon).exists()).toBe(true);
wrapper.find('a').first().simulate('click');
expect(handleImageClick).toHaveBeenCalledTimes(1);
});
test('should match snapshot, with Download icon as children', () => {
const props = {...baseProps, canDownload: true};
const wrapper = shallow(
<FilenameOverlay {...props}>
<AttachmentIcon/>
</FilenameOverlay>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find(AttachmentIcon).exists()).toBe(true);
});
test('should match snapshot, standard but not downloadable', () => {
const props = {...baseProps, canDownload: false};
const wrapper = shallow(
<FilenameOverlay {...props}>
<AttachmentIcon/>
</FilenameOverlay>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,219 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/__snapshots__/file_attachment.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`FileAttachment should match snapshot, after change from file to image 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.png"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 400,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.png",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 600,
}
}
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.png
</span>
<span
className="post-image__type"
>
PNG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<FilenameOverlay
canDownload={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 400,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.png",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 600,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, regular file 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.pdf"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "pdf",
"has_preview_image": true,
"height": 80,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.pdf",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.pdf
</span>
<span
className="post-image__type"
>
PDF
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<FilenameOverlay
canDownload={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "pdf",
"has_preview_image": true,
"height": 80,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.pdf",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, regular image 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.png"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<div
className="post-image__load"
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.png
</span>
<span
className="post-image__type"
>
PNG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<FilenameOverlay
canDownload={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 400,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.png",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 600,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, small image 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.png"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<div
className="post-image__load"
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.png
</span>
<span
className="post-image__type"
>
PNG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<FilenameOverlay
canDownload={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 16,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.png",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 16,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, svg image 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.svg"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "svg",
"has_preview_image": true,
"height": 400,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.svg",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 600,
}
}
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.svg
</span>
<span
className="post-image__type"
>
SVG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<FilenameOverlay
canDownload={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "svg",
"has_preview_image": true,
"height": 400,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.svg",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 600,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, when file is not loaded 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.pdf"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<div
className="post-image__load"
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.pdf
</span>
<span
className="post-image__type"
>
JPG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<FilenameOverlay
canDownload={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "jpg",
"has_preview_image": true,
"height": 80,
"id": "noLoad",
"mime_type": "",
"name": "test.pdf",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, with compact display 1`] = `
<div
className="post-image__column"
>
<div
className="post-image__details"
>
<FilenameOverlay
canDownload={true}
compactDisplay={true}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "pdf",
"has_preview_image": true,
"height": 80,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.pdf",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
handleImageClick={[Function]}
iconClass="post-image__download"
>
<i
className="icon icon-download-outline"
/>
</FilenameOverlay>
</div>
</div>
`;
exports[`FileAttachment should match snapshot, without compact display and without can download 1`] = `
<div
className="post-image__column"
>
<a
aria-label="file thumbnail test.pdf"
className="post-image__thumbnail"
href="#"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "pdf",
"has_preview_image": true,
"height": 80,
"id": "thumbnail_id",
"mime_type": "",
"name": "test.pdf",
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
</a>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
onClick={[Function]}
>
<div
className="post-image__detail"
>
<span
className="post-image__name"
>
test.pdf
</span>
<span
className="post-image__type"
>
PDF
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
</div>
</div>
`;
|
2,220 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/__snapshots__/filename_overlay.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_attachment/FilenameOverlay should match snapshot, compact display 1`] = `
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
test_filename
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<a
className="post-image__name"
href="#"
id="file-attachment-link"
onClick={[MockFunction]}
rel="noopener noreferrer"
>
<AttachmentIcon
className="icon"
/>
test_filename
</a>
</OverlayTrigger>
`;
exports[`components/file_attachment/FilenameOverlay should match snapshot, standard but not downloadable 1`] = `
<span
className="post-image__name"
>
test_filename
</span>
`;
exports[`components/file_attachment/FilenameOverlay should match snapshot, standard display 1`] = `
<div
className="post-image__name"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
Download
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<ExternalLink
aria-label="download"
download="test_filename"
href="/api/v4/files/thumbnail_id?download=1"
location="filename_overlay"
>
test_filename
</ExternalLink>
</OverlayTrigger>
</div>
`;
exports[`components/file_attachment/FilenameOverlay should match snapshot, with Download icon as children 1`] = `
<div
className="post-image__name"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
Download
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<ExternalLink
aria-label="download"
download="test_filename"
href="/api/v4/files/thumbnail_id?download=1"
location="filename_overlay"
>
<AttachmentIcon />
</ExternalLink>
</OverlayTrigger>
</div>
`;
|
2,221 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/file_thumbnail/file_thumbnail.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FileThumbnail from './file_thumbnail';
describe('FileThumbnail', () => {
const fileInfo = {
id: 'thumbnail_id',
extension: 'jpg',
width: 100,
height: 80,
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
name: '',
size: 100,
mime_type: '',
clientId: '',
archived: false,
};
const baseProps = {
fileInfo,
enableSVGs: false,
};
test('should render a small image', () => {
const wrapper = shallow(
<FileThumbnail {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should render a normal-sized image', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo,
height: 150,
width: 150,
},
};
const wrapper = shallow(
<FileThumbnail {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should render an svg when svg previews are enabled', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo,
extension: 'svg',
},
enableSVGs: true,
};
const wrapper = shallow(
<FileThumbnail {...props}/>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('img').exists()).toBe(true);
});
test('should render an icon for an SVG when SVG previews are disabled', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo,
extension: 'svg',
},
enableSVGs: false,
};
const wrapper = shallow(
<FileThumbnail {...props}/>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('div.file-icon').exists()).toBe(true);
});
test('should render an icon for a PDF', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo,
extension: 'pdf',
},
};
const wrapper = shallow(
<FileThumbnail {...props}/>,
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('div.file-icon').exists()).toBe(true);
});
});
|
2,224 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/file_thumbnail | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment/file_thumbnail/__snapshots__/file_thumbnail.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`FileThumbnail should render a normal-sized image 1`] = `
<div
className="post-image normal"
style={
Object {
"backgroundImage": "url(/api/v4/files/thumbnail_id/thumbnail)",
"backgroundSize": "cover",
}
}
/>
`;
exports[`FileThumbnail should render a small image 1`] = `
<div
className="post-image small"
style={
Object {
"backgroundImage": "url(/api/v4/files/thumbnail_id/thumbnail)",
"backgroundSize": "cover",
}
}
/>
`;
exports[`FileThumbnail should render an icon for a PDF 1`] = `
<div
className="file-icon pdf"
/>
`;
exports[`FileThumbnail should render an icon for an SVG when SVG previews are disabled 1`] = `
<div
className="file-icon generic"
/>
`;
exports[`FileThumbnail should render an svg when svg previews are enabled 1`] = `
<img
alt="file thumbnail image"
className="post-image normal"
src="/api/v4/files/thumbnail_id"
/>
`;
|
2,225 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_attachment_list/file_attachment_list.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FileAttachment from 'components/file_attachment';
import SingleImageView from 'components/single_image_view';
import {TestHelper} from 'utils/test_helper';
import FileAttachmentList from './file_attachment_list';
describe('FileAttachmentList', () => {
const post = TestHelper.getPostMock({
id: 'post_id',
file_ids: ['file_id_1', 'file_id_2', 'file_id_3'],
});
const fileInfos = [
TestHelper.getFileInfoMock({id: 'file_id_3', name: 'image_3.png', extension: 'png', create_at: 3}),
TestHelper.getFileInfoMock({id: 'file_id_2', name: 'image_2.png', extension: 'png', create_at: 2}),
TestHelper.getFileInfoMock({id: 'file_id_1', name: 'image_1.png', extension: 'png', create_at: 1}),
];
const baseProps = {
post,
fileCount: 3,
fileInfos,
compactDisplay: false,
enableSVGs: false,
isEmbedVisible: false,
locale: 'en',
handleFileDropdownOpened: jest.fn(),
actions: {
openModal: jest.fn(),
},
};
test('should render a FileAttachment for a single file', () => {
const props = {
...baseProps,
fileCount: 1,
fileInfos: [
TestHelper.getFileInfoMock({
id: 'file_id_1',
name: 'file.txt',
extension: 'txt',
}),
],
};
const wrapper = shallow(
<FileAttachmentList {...props}/>,
);
expect(wrapper.find(FileAttachment).exists()).toBe(true);
});
test('should render multiple, sorted FileAttachments for multiple files', () => {
const wrapper = shallow(
<FileAttachmentList {...baseProps}/>,
);
expect(wrapper.find(FileAttachment)).toHaveLength(3);
expect(wrapper.find(FileAttachment).first().prop('fileInfo').id).toBe('file_id_1');
expect(wrapper.find(FileAttachment).last().prop('fileInfo').id).toBe('file_id_3');
});
test('should render a SingleImageView for a single image', () => {
const props = {
...baseProps,
fileCount: 1,
fileInfos: [
TestHelper.getFileInfoMock({id: 'file_id_1', name: 'image.png', extension: 'png'}),
],
};
const wrapper = shallow(
<FileAttachmentList {...props}/>,
);
expect(wrapper.find(SingleImageView).exists()).toBe(true);
});
test('should render a SingleImageView for an SVG with SVG previews enabled', () => {
const props = {
...baseProps,
enableSVGs: true,
fileCount: 1,
fileInfos: [
TestHelper.getFileInfoMock({id: 'file_id_1', name: 'image.svg', extension: 'svg'}),
],
};
const wrapper = shallow(
<FileAttachmentList {...props}/>,
);
expect(wrapper.find(SingleImageView).exists()).toBe(true);
});
test('should render a FileAttachment for an SVG with SVG previews disabled', () => {
const props = {
...baseProps,
fileCount: 1,
fileInfos: [
TestHelper.getFileInfoMock({id: 'file_id_1', name: 'image.svg', extension: 'svg'}),
],
};
const wrapper = shallow(
<FileAttachmentList {...props}/>,
);
expect(wrapper.find(SingleImageView).exists()).toBe(false);
expect(wrapper.find(FileAttachment).exists()).toBe(true);
});
});
|
2,228 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_info_preview/file_info_preview.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import type {FileInfo} from '@mattermost/types/files';
import FileInfoPreview from 'components/file_info_preview/file_info_preview';
describe('components/FileInfoPreview', () => {
test('should match snapshot, can download files', () => {
const wrapper = shallow(
<FileInfoPreview
fileUrl='https://pre-release.mattermost.com/api/v4/files/rqir81f7a7ft8m6j6ej7g1txuo'
fileInfo={{name: 'Test Image', size: 100, extension: 'jpg'} as FileInfo}
canDownloadFiles={true}
/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, cannot download files', () => {
const wrapper = shallow(
<FileInfoPreview
fileUrl='https://pre-release.mattermost.com/api/v4/files/aasf9afshaskj1asf91jasf0a0'
fileInfo={{name: 'Test Image 2', size: 200, extension: 'png'} as FileInfo}
canDownloadFiles={false}
/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,231 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_info_preview | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_info_preview/__snapshots__/file_info_preview.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/FileInfoPreview should match snapshot, can download files 1`] = `
<div
className="file-details__container"
>
<a
className="file-details__preview"
href="https://pre-release.mattermost.com/api/v4/files/rqir81f7a7ft8m6j6ej7g1txuo"
>
<span
className="file-details__preview-helper"
/>
<img
alt="file preview"
src={null}
/>
</a>
<div
className="file-details"
>
<div
className="file-details__name"
>
Test Image
</div>
<div
className="file-details__info"
>
File type JPG, Size 100B
</div>
</div>
</div>
`;
exports[`components/FileInfoPreview should match snapshot, cannot download files 1`] = `
<div
className="file-details__container"
>
<span
className="file-details__preview"
>
<span
className="file-details__preview-helper"
/>
<img
alt="file preview"
src={null}
/>
</span>
<div
className="file-details"
>
<div
className="file-details__name"
>
Test Image 2
</div>
<div
className="file-details__info"
>
File type PNG, Size 200B
</div>
</div>
</div>
`;
|
2,233 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview/file_preview.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {getFileUrl} from 'mattermost-redux/utils/file_utils';
import FilePreview from './file_preview';
describe('FilePreview', () => {
const onRemove = jest.fn();
const fileInfos = [
{
width: 100,
height: 100,
name: 'test_filename',
id: 'file_id_1',
type: 'image/png',
extension: 'png',
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
size: 100,
mime_type: '',
clientId: '',
archived: false,
},
];
const uploadsInProgress = ['clientID_1'];
const uploadsProgressPercent = {
// eslint-disable-next-line @typescript-eslint/naming-convention
clientID_1: {
width: 100,
height: 100,
name: 'file',
percent: 50,
extension: 'image/png',
id: 'file_id_1',
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
size: 100,
mime_type: '',
clientId: '',
archived: false,
},
};
const baseProps = {
enableSVGs: false,
fileInfos,
uploadsInProgress,
onRemove,
uploadsProgressPercent,
};
test('should match snapshot', () => {
const wrapper = shallow(
<FilePreview {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot when props are changed', () => {
const wrapper = shallow(
<FilePreview {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
const fileInfo2 = {
id: 'file_id_2',
create_at: '2',
width: 100,
height: 100,
extension: 'jpg',
};
const newFileInfos = [...fileInfos, fileInfo2];
wrapper.setProps({
fileInfos: newFileInfos,
uploadsInProgress: [],
});
expect(wrapper).toMatchSnapshot();
});
test('should call handleRemove when file removed', () => {
const newOnRemove = jest.fn();
const props = {...baseProps, onRemove: newOnRemove};
const wrapper = shallow<FilePreview>(
<FilePreview {...props}/>,
);
wrapper.instance().handleRemove('');
expect(newOnRemove).toHaveBeenCalled();
});
test('should not render an SVG when SVGs are disabled', () => {
const fileId = 'file_id_1';
const props = {
...baseProps,
fileInfos: [
{
...baseProps.fileInfos[0],
type: 'image/svg',
extension: 'svg',
},
],
};
const wrapper = shallow(
<FilePreview {...props}/>,
);
expect(wrapper.find('img').find({src: getFileUrl(fileId)}).exists()).toBe(false);
expect(wrapper.find('div').find('.file-icon.generic').exists()).toBe(true);
});
test('should render an SVG when SVGs are enabled', () => {
const fileId = 'file_id_1';
const props = {
...baseProps,
enableSVGs: true,
fileInfos: [
{
...baseProps.fileInfos[0],
type: 'image/svg',
extension: 'svg',
},
],
};
const wrapper = shallow(
<FilePreview {...props}/>,
);
expect(wrapper.find('img').find({src: getFileUrl(fileId)}).exists()).toBe(true);
expect(wrapper.find('div').find('.file-icon.generic').exists()).toBe(false);
});
});
|
2,235 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview/file_progress_preview.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FileProgressPreview from './file_progress_preview';
describe('component/file_preview/file_progress_preview', () => {
const handleRemove = jest.fn();
const fiftyPercent = 50;
const fileInfo = {
name: 'test_filename',
id: 'file',
percent: fiftyPercent,
type: 'image/png',
extension: 'png',
width: 100,
height: 80,
has_preview_image: true,
user_id: '',
create_at: 0,
update_at: 0,
delete_at: 0,
size: 100,
mime_type: '',
clientId: '',
archived: false,
};
const baseProps = {
clientId: 'clientId',
fileInfo,
handleRemove,
};
test('should match snapshot', () => {
const wrapper = shallow(
<FileProgressPreview {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('snapshot for percent value undefined', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo,
percent: undefined,
},
};
const wrapper = shallow(
<FileProgressPreview {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,238 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview/__snapshots__/file_preview.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`FilePreview should match snapshot 1`] = `
<div
className="file-preview__container"
>
<div
className="file-preview post-image__column"
key="file_id_1"
>
<div
className="post-image__thumbnail"
>
<div
className="post-image normal"
style={
Object {
"backgroundImage": "url(/api/v4/files/file_id_1/thumbnail)",
"backgroundSize": "cover",
}
}
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 100,
"id": "file_id_1",
"mime_type": "",
"name": "test_filename",
"size": 100,
"type": "image/png",
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
<span
className="post-image__type"
>
PNG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="icon icon-close"
/>
</a>
</div>
</div>
</div>
<FileProgressPreview
clientId="clientID_1"
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "image/png",
"has_preview_image": true,
"height": 100,
"id": "file_id_1",
"mime_type": "",
"name": "file",
"percent": 50,
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
handleRemove={[Function]}
key="clientID_1"
/>
</div>
`;
exports[`FilePreview should match snapshot when props are changed 1`] = `
<div
className="file-preview__container"
>
<div
className="file-preview post-image__column"
key="file_id_1"
>
<div
className="post-image__thumbnail"
>
<div
className="post-image normal"
style={
Object {
"backgroundImage": "url(/api/v4/files/file_id_1/thumbnail)",
"backgroundSize": "cover",
}
}
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 100,
"id": "file_id_1",
"mime_type": "",
"name": "test_filename",
"size": 100,
"type": "image/png",
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
<span
className="post-image__type"
>
PNG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="icon icon-close"
/>
</a>
</div>
</div>
</div>
<FileProgressPreview
clientId="clientID_1"
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "image/png",
"has_preview_image": true,
"height": 100,
"id": "file_id_1",
"mime_type": "",
"name": "file",
"percent": 50,
"size": 100,
"update_at": 0,
"user_id": "",
"width": 100,
}
}
handleRemove={[Function]}
key="clientID_1"
/>
</div>
`;
exports[`FilePreview should match snapshot when props are changed 2`] = `
<div
className="file-preview__container"
>
<div
className="file-preview post-image__column"
key="file_id_1"
>
<div
className="post-image__thumbnail"
>
<div
className="post-image normal"
style={
Object {
"backgroundImage": "url(/api/v4/files/file_id_1/thumbnail)",
"backgroundSize": "cover",
}
}
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 100,
"id": "file_id_1",
"mime_type": "",
"name": "test_filename",
"size": 100,
"type": "image/png",
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
<span
className="post-image__type"
>
PNG
</span>
<span
className="post-image__size"
>
100B
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="icon icon-close"
/>
</a>
</div>
</div>
</div>
<div
className="file-preview post-image__column"
key="file_id_2"
>
<div
className="post-image__thumbnail"
>
<div
className="post-image normal"
style={
Object {
"backgroundImage": "url(/api/v4/files/file_id_2/thumbnail)",
"backgroundSize": "cover",
}
}
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"create_at": "2",
"extension": "jpg",
"height": 100,
"id": "file_id_2",
"width": 100,
}
}
/>
<span
className="post-image__type"
>
JPG
</span>
<span
className="post-image__size"
>
undefinedB
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="icon icon-close"
/>
</a>
</div>
</div>
</div>
</div>
`;
|
2,239 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview/__snapshots__/file_progress_preview.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`component/file_preview/file_progress_preview should match snapshot 1`] = `
<div
className="file-preview post-image__column"
data-client-id="clientId"
key="clientId"
>
<div
className="post-image__thumbnail"
>
<div
className="file-icon image"
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 80,
"id": "file",
"mime_type": "",
"name": "test_filename",
"percent": 50,
"size": 100,
"type": "image/png",
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
<span
className="post-image__uploadingTxt"
>
<MemoizedFormattedMessage
defaultMessage="Uploading..."
id="admin.plugin.uploading"
/>
<span>
(50%)
</span>
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="icon icon-close"
/>
</a>
</div>
<ProgressBar
active={false}
bsClass="progress-bar"
className="post-image__progressBar"
isChild={false}
max={100}
min={0}
now={50}
srOnly={false}
striped={false}
/>
</div>
</div>
`;
exports[`component/file_preview/file_progress_preview snapshot for percent value undefined 1`] = `
<div
className="file-preview post-image__column"
data-client-id="clientId"
key="clientId"
>
<div
className="post-image__thumbnail"
>
<div
className="file-icon image"
/>
</div>
<div
className="post-image__details"
>
<div
className="post-image__detail_wrapper"
>
<div
className="post-image__detail"
>
<FilenameOverlay
canDownload={false}
compactDisplay={false}
fileInfo={
Object {
"archived": false,
"clientId": "",
"create_at": 0,
"delete_at": 0,
"extension": "png",
"has_preview_image": true,
"height": 80,
"id": "file",
"mime_type": "",
"name": "test_filename",
"percent": undefined,
"size": 100,
"type": "image/png",
"update_at": 0,
"user_id": "",
"width": 100,
}
}
/>
<span
className="post-image__uploadingTxt"
>
<MemoizedFormattedMessage
defaultMessage="Uploading..."
id="admin.plugin.uploading"
/>
<span>
(0%)
</span>
</span>
</div>
</div>
<div>
<a
className="file-preview__remove"
onClick={[Function]}
>
<i
className="icon icon-close"
/>
</a>
</div>
</div>
</div>
`;
|
2,241 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FilePreviewModal from 'components/file_preview_modal/file_preview_modal';
import Constants from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import {generateId} from 'utils/utils';
describe('components/FilePreviewModal', () => {
const baseProps = {
fileInfos: [TestHelper.getFileInfoMock({id: 'file_id', extension: 'jpg'})],
startIndex: 0,
canDownloadFiles: true,
enablePublicLink: true,
isMobileView: false,
post: TestHelper.getPostMock(),
onExited: jest.fn(),
};
test('should match snapshot', () => {
const wrapper = shallow(<FilePreviewModal {...baseProps}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded with image', () => {
const wrapper = shallow(<FilePreviewModal {...baseProps}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded with .mov file', () => {
const fileInfos = [TestHelper.getFileInfoMock({id: 'file_id', extension: 'mov'})];
const props = {...baseProps, fileInfos};
const wrapper = shallow(<FilePreviewModal {...props}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded with .m4a file', () => {
const fileInfos = [TestHelper.getFileInfoMock({id: 'file_id', extension: 'm4a'})];
const props = {...baseProps, fileInfos};
const wrapper = shallow(<FilePreviewModal {...props}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded with .js file', () => {
const fileInfos = [TestHelper.getFileInfoMock({id: 'file_id', extension: 'js'})];
const props = {...baseProps, fileInfos};
const wrapper = shallow(<FilePreviewModal {...props}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded with other file', () => {
const fileInfos = [TestHelper.getFileInfoMock({id: 'file_id', extension: 'other'})];
const props = {...baseProps, fileInfos};
const wrapper = shallow(<FilePreviewModal {...props}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded with footer', () => {
const fileInfos = [
TestHelper.getFileInfoMock({id: 'file_id_1', extension: 'gif'}),
TestHelper.getFileInfoMock({id: 'file_id_2', extension: 'wma'}),
TestHelper.getFileInfoMock({id: 'file_id_3', extension: 'mp4'}),
];
const props = {...baseProps, fileInfos};
const wrapper = shallow(<FilePreviewModal {...props}/>);
wrapper.setState({loaded: [true, true, true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded', () => {
const wrapper = shallow(<FilePreviewModal {...baseProps}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, loaded and showing footer', () => {
const wrapper = shallow(<FilePreviewModal {...baseProps}/>);
wrapper.setState({loaded: [true]});
expect(wrapper).toMatchSnapshot();
});
test('should go to next or previous upon key press of right or left, respectively', () => {
const fileInfos = [
TestHelper.getFileInfoMock({id: 'file_id_1', extension: 'gif'}),
TestHelper.getFileInfoMock({id: 'file_id_2', extension: 'wma'}),
TestHelper.getFileInfoMock({id: 'file_id_3', extension: 'mp4'}),
];
const props = {...baseProps, fileInfos};
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...props}/>);
wrapper.setState({loaded: [true, true, true]});
let evt = {key: Constants.KeyCodes.RIGHT[0]} as KeyboardEvent;
wrapper.instance().handleKeyPress(evt);
expect(wrapper.state('imageIndex')).toBe(1);
wrapper.instance().handleKeyPress(evt);
expect(wrapper.state('imageIndex')).toBe(2);
evt = {key: Constants.KeyCodes.LEFT[0]} as KeyboardEvent;
wrapper.instance().handleKeyPress(evt);
expect(wrapper.state('imageIndex')).toBe(1);
wrapper.instance().handleKeyPress(evt);
expect(wrapper.state('imageIndex')).toBe(0);
});
test('should handle onMouseEnter and onMouseLeave', () => {
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...baseProps}/>);
wrapper.setState({loaded: [true]});
wrapper.instance().onMouseEnterImage();
expect(wrapper.state('showCloseBtn')).toBe(true);
wrapper.instance().onMouseLeaveImage();
expect(wrapper.state('showCloseBtn')).toBe(false);
});
test('should handle on modal close', () => {
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...baseProps}/>);
wrapper.setState({
loaded: [true],
});
wrapper.instance().handleModalClose();
expect(wrapper.state('show')).toBe(false);
});
test('should match snapshot for external file', () => {
const fileInfos = [
TestHelper.getFileInfoMock({extension: 'png'}),
];
const props = {...baseProps, fileInfos};
const wrapper = shallow(<FilePreviewModal {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should have called loadImage', () => {
const fileInfos = [
TestHelper.getFileInfoMock({id: 'file_id_1', extension: 'gif'}),
TestHelper.getFileInfoMock({id: 'file_id_2', extension: 'wma'}),
TestHelper.getFileInfoMock({id: 'file_id_3', extension: 'mp4'}),
];
const props = {...baseProps, fileInfos};
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...props}/>);
let index = 1;
wrapper.setState({loaded: [true, false, false]});
wrapper.instance().loadImage(index);
expect(wrapper.state('loaded')[index]).toBe(true);
index = 2;
wrapper.instance().loadImage(index);
expect(wrapper.state('loaded')[index]).toBe(true);
});
test('should handle handleImageLoaded', () => {
const fileInfos = [
TestHelper.getFileInfoMock({id: 'file_id_1', extension: 'gif'}),
TestHelper.getFileInfoMock({id: 'file_id_2', extension: 'wma'}),
TestHelper.getFileInfoMock({id: 'file_id_3', extension: 'mp4'}),
];
const props = {...baseProps, fileInfos};
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...props}/>);
let index = 1;
wrapper.setState({loaded: [true, false, false]});
wrapper.instance().handleImageLoaded(index);
expect(wrapper.state('loaded')[index]).toBe(true);
index = 2;
wrapper.instance().handleImageLoaded(index);
expect(wrapper.state('loaded')[index]).toBe(true);
});
test('should handle handleImageProgress', () => {
const fileInfos = [
TestHelper.getFileInfoMock({id: 'file_id_1', extension: 'gif'}),
TestHelper.getFileInfoMock({id: 'file_id_2', extension: 'wma'}),
TestHelper.getFileInfoMock({id: 'file_id_3', extension: 'mp4'}),
];
const props = {...baseProps, fileInfos};
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...props}/>);
const index = 1;
let completedPercentage = 30;
wrapper.setState({loaded: [true, false, false]});
wrapper.instance().handleImageProgress(index, completedPercentage);
expect(wrapper.state('progress')[index]).toBe(completedPercentage);
completedPercentage = 70;
wrapper.instance().handleImageProgress(index, completedPercentage);
expect(wrapper.state('progress')[index]).toBe(completedPercentage);
});
test('should pass componentWillReceiveProps', () => {
const wrapper = shallow<FilePreviewModal>(<FilePreviewModal {...baseProps}/>);
expect(Object.keys(wrapper.state('loaded')).length).toBe(1);
expect(Object.keys(wrapper.state('progress')).length).toBe(1);
wrapper.setProps({
fileInfos: [
TestHelper.getFileInfoMock({id: 'file_id_1', extension: 'gif'}),
TestHelper.getFileInfoMock({id: 'file_id_2', extension: 'wma'}),
TestHelper.getFileInfoMock({id: 'file_id_3', extension: 'mp4'}),
],
});
expect(Object.keys(wrapper.state('loaded')).length).toBe(3);
expect(Object.keys(wrapper.state('progress')).length).toBe(3);
});
test('should match snapshot when plugin overrides the preview component', () => {
const pluginFilePreviewComponents = [{
id: generateId(),
pluginId: 'file-preview',
override: () => true,
component: () => <div>{'Preview'}</div>,
}];
const props = {...baseProps, pluginFilePreviewComponents};
const wrapper = shallow(<FilePreviewModal {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should fall back to default preview if plugin does not need to override preview component', () => {
const pluginFilePreviewComponents = [{
id: generateId(),
pluginId: 'file-preview',
override: () => false,
component: () => <div>{'Preview'}</div>,
}];
const props = {...baseProps, pluginFilePreviewComponents};
const wrapper = shallow(<FilePreviewModal {...props}/>);
expect(wrapper).toMatchSnapshot();
});
});
|
2,244 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/image_preview.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import ImagePreview from 'components/file_preview_modal/image_preview';
import {TestHelper} from 'utils/test_helper';
describe('components/view_image/ImagePreview', () => {
const fileInfo1 = TestHelper.getFileInfoMock({id: 'file_id', extension: 'm4a', has_preview_image: false});
const baseProps = {
canDownloadFiles: true,
fileInfo: fileInfo1,
};
test('should match snapshot, without preview', () => {
const wrapper = shallow(
<ImagePreview {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, with preview', () => {
const props = {
...baseProps,
fileInfo: {
...fileInfo1,
id: 'file_id_1',
has_preview_image: true,
},
};
const wrapper = shallow(
<ImagePreview {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, without preview, cannot download', () => {
const props = {
...baseProps,
canDownloadFiles: false,
};
const wrapper = shallow(
<ImagePreview {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot, with preview, cannot download', () => {
const props = {
...baseProps,
canDownloadFiles: false,
fileInfo: {
...fileInfo1,
id: 'file_id_1',
has_preview_image: true,
},
};
const wrapper = shallow(
<ImagePreview {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should not download link for external file', () => {
fileInfo1.link = 'https://example.com/image.png';
const props = {
...baseProps,
fileInfo: {
...fileInfo1,
link: 'https://example.com/image.png',
id: '',
},
};
const wrapper = shallow(
<ImagePreview {...props}/>,
);
expect(wrapper.find('a').prop('href')).toBe('#');
expect(wrapper.find('img').prop('src')).toBe(props.fileInfo.link);
});
});
|
2,248 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/__snapshots__/file_preview_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/FilePreviewModal should fall back to default preview if plugin does not need to override preview component 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<LoadingImagePreview
containerClass="view-image__loading"
loading="Loading"
progress={0}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<LoadingImagePreview
containerClass="view-image__loading"
loading="Loading"
progress={0}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot for external file 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "png",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_info_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<LoadingImagePreview
containerClass="view-image__loading"
loading="Loading"
progress={0}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot when plugin overrides the preview component 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<component
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
onModalDismissed={[Function]}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<ImagePreview
canDownloadFiles={true}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded and showing footer 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<ImagePreview
canDownloadFiles={true}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded with .js file 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal modal-code"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={true}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "js",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<CodePreview
className="file-preview-modal__code-preview"
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "js",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileUrl="/api/v4/files/file_id"
getContent={[Function]}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded with .m4a file 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "m4a",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<Connect(AudioVideoPreview)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "m4a",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileUrl="/api/v4/files/file_id"
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded with .mov file 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "mov",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<Connect(AudioVideoPreview)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "mov",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileUrl="/api/v4/files/file_id"
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded with footer 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "gif",
"has_preview_image": true,
"height": 200,
"id": "file_id_1",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id_1?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={3}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<ImagePreview
canDownloadFiles={true}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "gif",
"has_preview_image": true,
"height": 200,
"id": "file_id_1",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded with image 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<ImagePreview
canDownloadFiles={true}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
exports[`components/FilePreviewModal should match snapshot, loaded with other file 1`] = `
<Modal
animation={true}
aria-labelledby="viewImageModalLabel"
autoFocus={true}
backdrop={false}
bsClass="modal"
className="modal-image file-preview-modal"
dialogClassName="a11y__modal modal-image file-preview-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"add": [Function],
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"isTopModal": [Function],
"modals": Array [],
"remove": [Function],
}
}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
role="dialog"
show={true}
style={
Object {
"paddingLeft": 0,
}
}
>
<ModalBody
bsClass="modal-body"
className="file-preview-modal__body"
componentClass="div"
>
<div
className="modal-image__wrapper"
onClick={[Function]}
>
<div
className="file-preview-modal__main-ctr"
onClick={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<ModalTitle
bsClass="modal-title"
className="file-preview-modal__title"
componentClass="div"
id="viewImageModalLabel"
>
<Memo(FilePreviewModalHeader)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={true}
fileIndex={0}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "other",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="/api/v4/files/file_id?download=1"
filename="name"
handleModalClose={[Function]}
handleNext={[Function]}
handlePrev={[Function]}
isExternalFile={false}
isMobileView={false}
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showPublicLink={true}
totalFiles={1}
/>
</ModalTitle>
<div
className="file-preview-modal__content"
onClick={[Function]}
>
<Connect(FileInfoPreview)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "other",
"has_preview_image": true,
"height": 200,
"id": "file_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileUrl="/api/v4/files/file_id"
/>
</div>
</div>
</div>
</ModalBody>
</Modal>
`;
|
2,249 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/__snapshots__/image_preview.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/view_image/ImagePreview should match snapshot, with preview 1`] = `
<a
className="image_preview"
href="#"
>
<img
alt="preview url image"
className="image_preview__image"
data-testid="imagePreview"
loading="lazy"
src="/api/v4/files/file_id_1/preview"
/>
</a>
`;
exports[`components/view_image/ImagePreview should match snapshot, with preview, cannot download 1`] = `
<img
src="/api/v4/files/file_id_1/preview"
/>
`;
exports[`components/view_image/ImagePreview should match snapshot, without preview 1`] = `
<a
className="image_preview"
href="#"
>
<img
alt="preview url image"
className="image_preview__image"
data-testid="imagePreview"
loading="lazy"
src="/api/v4/files/file_id?download=1"
/>
</a>
`;
exports[`components/view_image/ImagePreview should match snapshot, without preview, cannot download 1`] = `
<img
src="/api/v4/files/file_id?download=1"
/>
`;
|
2,251 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_footer/file_preview_modal_footer.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {TestHelper} from 'utils/test_helper';
import FilePreviewModalFooter from './file_preview_modal_footer';
describe('components/file_preview_modal/file_preview_modal_footer/FilePreviewModalFooter', () => {
const defaultProps = {
enablePublicLink: false,
fileInfo: TestHelper.getFileInfoMock(),
canDownloadFiles: true,
fileURL: 'https://example.com/img.png',
filename: 'img.png',
isMobile: false,
fileIndex: 1,
totalFiles: 3,
post: TestHelper.getPostMock(),
showPublicLink: false,
isExternalFile: false,
onGetPublicLink: jest.fn(),
handleModalClose: jest.fn(),
content: '',
canCopyContent: false,
};
test('should match snapshot the desktop view', () => {
const props = {
...defaultProps,
};
const wrapper = shallow(<FilePreviewModalFooter {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot the mobile view', () => {
const props = {
...defaultProps,
isMobile: true,
};
const wrapper = shallow(<FilePreviewModalFooter {...props}/>);
expect(wrapper).toMatchSnapshot();
});
});
|
2,253 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_footer | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_footer/__snapshots__/file_preview_modal_footer.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_preview_modal/file_preview_modal_footer/FilePreviewModalFooter should match snapshot the desktop view 1`] = `
<div
className="file-preview-modal-footer"
>
<Memo(FilePreviewModalInfo)
filename="img.png"
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showFileName={false}
/>
<Memo(FilePreviewModalMainActions)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={false}
fileIndex={1}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="https://example.com/img.png"
filename="img.png"
handleModalClose={[MockFunction]}
isExternalFile={false}
isMobile={false}
onGetPublicLink={[MockFunction]}
showClose={false}
showOnlyClose={false}
showPublicLink={false}
totalFiles={3}
usedInside="Footer"
/>
</div>
`;
exports[`components/file_preview_modal/file_preview_modal_footer/FilePreviewModalFooter should match snapshot the mobile view 1`] = `
<div
className="file-preview-modal-footer"
>
<Memo(FilePreviewModalInfo)
filename="img.png"
post={
Object {
"channel_id": "",
"create_at": 0,
"delete_at": 0,
"edit_at": 0,
"hashtags": "",
"id": "id",
"is_pinned": false,
"message": "post message",
"metadata": Object {
"embeds": Array [],
"emojis": Array [],
"files": Array [],
"images": Object {},
"reactions": Array [],
},
"original_id": "",
"pending_post_id": "",
"props": Object {},
"reply_count": 0,
"root_id": "",
"type": "system_add_remove",
"update_at": 0,
"user_id": "user_id",
}
}
showFileName={false}
/>
<Memo(FilePreviewModalMainActions)
canCopyContent={false}
canDownloadFiles={true}
content=""
enablePublicLink={false}
fileIndex={1}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="https://example.com/img.png"
filename="img.png"
handleModalClose={[MockFunction]}
isExternalFile={false}
isMobile={true}
onGetPublicLink={[MockFunction]}
showClose={false}
showOnlyClose={false}
showPublicLink={false}
totalFiles={3}
usedInside="Footer"
/>
</div>
`;
|
2,255 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_header/file_preview_modal_header.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import type {Post} from '@mattermost/types/posts';
import {TestHelper} from 'utils/test_helper';
import FilePreviewModalHeader from './file_preview_modal_header';
describe('components/file_preview_modal/file_preview_modal_header/FilePreviewModalHeader', () => {
const defaultProps = {
enablePublicLink: false,
canDownloadFiles: true,
fileURL: 'http://example.com/img.png',
filename: 'img.png',
fileInfo: TestHelper.getFileInfoMock({}),
isMobileView: false,
fileIndex: 1,
totalFiles: 3,
post: {} as Post,
showPublicLink: false,
isExternalFile: false,
onGetPublicLink: jest.fn(),
handlePrev: jest.fn(),
handleNext: jest.fn(),
handleModalClose: jest.fn(),
content: '',
canCopyContent: true,
};
test('should match snapshot the desktop view', () => {
const props = {
...defaultProps,
};
const wrapper = shallow(<FilePreviewModalHeader {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot the mobile view', () => {
const props = {
...defaultProps,
isMobileView: true,
};
const wrapper = shallow(<FilePreviewModalHeader {...props}/>);
expect(wrapper).toMatchSnapshot();
});
});
|
2,257 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_header | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_header/__snapshots__/file_preview_modal_header.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_preview_modal/file_preview_modal_header/FilePreviewModalHeader should match snapshot the desktop view 1`] = `
<div
className="file-preview-modal-header"
>
<Memo(FilePreviewModalInfo)
filename="img.png"
post={Object {}}
showFileName={true}
/>
<Memo(FilePreviewModalMainNav)
fileIndex={1}
handleNext={[MockFunction]}
handlePrev={[MockFunction]}
totalFiles={3}
/>
<Memo(FilePreviewModalMainActions)
canCopyContent={true}
canDownloadFiles={true}
content=""
enablePublicLink={false}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="http://example.com/img.png"
filename="img.png"
handleModalClose={[MockFunction]}
handleNext={[MockFunction]}
handlePrev={[MockFunction]}
isExternalFile={false}
isMobileView={false}
onGetPublicLink={[MockFunction]}
showOnlyClose={false}
showPublicLink={false}
usedInside="Header"
/>
</div>
`;
exports[`components/file_preview_modal/file_preview_modal_header/FilePreviewModalHeader should match snapshot the mobile view 1`] = `
<div
className="file-preview-modal-header"
>
<Memo(FilePreviewModalMainActions)
canCopyContent={true}
canDownloadFiles={true}
content=""
enablePublicLink={false}
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
fileURL="http://example.com/img.png"
filename="img.png"
handleModalClose={[MockFunction]}
handleNext={[MockFunction]}
handlePrev={[MockFunction]}
isExternalFile={false}
isMobileView={true}
onGetPublicLink={[MockFunction]}
showOnlyClose={true}
showPublicLink={false}
usedInside="Header"
/>
<Memo(FilePreviewModalMainNav)
fileIndex={1}
handleNext={[MockFunction]}
handlePrev={[MockFunction]}
totalFiles={3}
/>
</div>
`;
|
2,259 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_info/file_preview_modal_info.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import type {ComponentProps} from 'react';
import {TestHelper} from 'utils/test_helper';
import type {GlobalState} from 'types/store';
import FilePreviewModalInfo from './file_preview_modal_info';
const mockDispatch = jest.fn();
let mockState: GlobalState;
const mockedUser = TestHelper.getUserMock();
const mockedChannel = TestHelper.getChannelMock();
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux') as typeof import('react-redux'),
useSelector: (selector: (state: typeof mockState) => unknown) => selector(mockState),
useDispatch: () => mockDispatch,
}));
describe('components/FilePreviewModalInfo', () => {
let baseProps: ComponentProps<typeof FilePreviewModalInfo>;
beforeEach(() => {
baseProps = {
post: TestHelper.getPostMock({channel_id: 'channel_id'}),
showFileName: false,
filename: 'Testing',
};
mockState = {
entities: {
general: {config: {}},
users: {profiles: {}},
channels: {channels: {}},
preferences: {
myPreferences: {
},
},
},
} as GlobalState;
});
test('should match snapshot', () => {
mockState.entities.users.profiles = {user_id: mockedUser};
mockState.entities.channels.channels = {channel_id: mockedChannel};
const wrapper = shallow<typeof FilePreviewModalInfo>(
<FilePreviewModalInfo
{...baseProps}
/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot where post is missing and avoid crash', () => {
mockState.entities.users.profiles = {user_id: mockedUser};
mockState.entities.channels.channels = {channel_id: mockedChannel};
baseProps.post = undefined;
const wrapper = shallow<typeof FilePreviewModalInfo>(
<FilePreviewModalInfo
{...baseProps}
/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,261 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_info | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_info/__snapshots__/file_preview_modal_info.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/FilePreviewModalInfo should match snapshot 1`] = `
<div
className="file-preview-modal__info"
>
<Memo(Avatar)
className="file-preview-modal__avatar"
size="lg"
url="/api/v4/users/user_id/image?_=0"
/>
<div
className="file-preview-modal__info-details"
>
<h5
className="file-preview-modal__user-name"
>
some-user
</h5>
<span
className="file-preview-modal__channel"
>
<MemoizedFormattedMessage
defaultMessage="Shared in ~{name}"
id="file_preview_modal_info.shared_in"
values={
Object {
"name": "name",
}
}
/>
</span>
</div>
</div>
`;
exports[`components/FilePreviewModalInfo should match snapshot where post is missing and avoid crash 1`] = `
<div
className="file-preview-modal__info"
>
<div
className="file-preview-modal__info-details"
>
<h5
className="file-preview-modal__user-name"
>
Someone
</h5>
<span
className="file-preview-modal__channel"
/>
</div>
</div>
`;
|
2,263 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_main_actions/file_preview_modal_main_actions.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {mount, shallow} from 'enzyme';
import React from 'react';
import type {ComponentProps} from 'react';
import * as fileActions from 'mattermost-redux/actions/files';
import OverlayTrigger from 'components/overlay_trigger';
import Tooltip from 'components/tooltip';
import {TestHelper} from 'utils/test_helper';
import * as Utils from 'utils/utils';
import type {GlobalState} from 'types/store';
import FilePreviewModalMainActions from './file_preview_modal_main_actions';
const mockDispatch = jest.fn();
let mockState: GlobalState;
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux') as typeof import('react-redux'),
useSelector: (selector: (state: typeof mockState) => unknown) => selector(mockState),
useDispatch: () => mockDispatch,
}));
describe('components/file_preview_modal/file_preview_modal_main_actions/FilePreviewModalMainActions', () => {
let defaultProps: ComponentProps<typeof FilePreviewModalMainActions>;
beforeEach(() => {
defaultProps = {
fileInfo: TestHelper.getFileInfoMock({}),
enablePublicLink: false,
canDownloadFiles: true,
showPublicLink: true,
fileURL: 'http://example.com/img.png',
filename: 'img.png',
handleModalClose: jest.fn(),
content: 'test content',
canCopyContent: false,
};
mockState = {
entities: {
general: {config: {}},
users: {profiles: {}},
channels: {channels: {}},
preferences: {
myPreferences: {
},
},
files: {
filePublicLink: {link: 'http://example.com/img.png'},
},
},
} as GlobalState;
});
test('should match snapshot with public links disabled', () => {
const props = {
...defaultProps,
enablePublicLink: false,
};
const wrapper = shallow(<FilePreviewModalMainActions {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with public links enabled', () => {
const props = {
...defaultProps,
enablePublicLink: true,
};
const wrapper = shallow(<FilePreviewModalMainActions {...props}/>);
expect(wrapper).toMatchSnapshot();
const overlayWrapper = wrapper.find(OverlayTrigger).first();
expect(overlayWrapper.prop('overlay').type).toEqual(Tooltip);
expect(overlayWrapper.prop('children')).toMatchSnapshot();
});
test('should match snapshot for external image with public links enabled', () => {
const props = {
...defaultProps,
enablePublicLink: true,
showPublicLink: false,
};
const wrapper = shallow(<FilePreviewModalMainActions {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot when copy content is enabled', () => {
const props = {
...defaultProps,
canCopyContent: true,
};
const wrapper = shallow(<FilePreviewModalMainActions {...props}/>);
expect(wrapper).toMatchSnapshot();
});
test('should call public link callback', () => {
const spy = jest.spyOn(Utils, 'copyToClipboard');
const props = {
...defaultProps,
enablePublicLink: true,
};
const wrapper = shallow(<FilePreviewModalMainActions {...props}/>);
expect(wrapper.find(OverlayTrigger)).toHaveLength(3);
const overlayWrapper = wrapper.find(OverlayTrigger).first().children('a');
expect(spy).toHaveBeenCalledTimes(0);
overlayWrapper.simulate('click');
expect(spy).toHaveBeenCalledTimes(1);
});
test('should not get public api when public links is disabled', async () => {
const spy = jest.spyOn(fileActions, 'getFilePublicLink');
mount(<FilePreviewModalMainActions {...defaultProps}/>);
expect(spy).toHaveBeenCalledTimes(0);
});
test('should get public api when public links is enabled', async () => {
const spy = jest.spyOn(fileActions, 'getFilePublicLink');
const props = {
...defaultProps,
enablePublicLink: true,
};
mount(<FilePreviewModalMainActions {...props}/>);
expect(spy).toHaveBeenCalledTimes(1);
});
test('should copy the content to clipboard', async () => {
const spy = jest.spyOn(Utils, 'copyToClipboard');
const props = {
...defaultProps,
canCopyContent: true,
};
const wrapper = mount(<FilePreviewModalMainActions {...props}/>);
expect(spy).toHaveBeenCalledTimes(0);
wrapper.find('.icon-content-copy').simulate('click');
expect(spy).toHaveBeenCalledTimes(1);
});
});
|
2,265 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_main_actions | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_main_actions/__snapshots__/file_preview_modal_main_actions.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_preview_modal/file_preview_modal_main_actions/FilePreviewModalMainActions should match snapshot for external image with public links enabled 1`] = `
<div
className="file-preview-modal-main-actions__actions"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="download"
overlay={
<Tooltip
id="download-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Download"
id="view_image_popover.download"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<ExternalLink
className="file-preview-modal-main-actions__action-item"
download="img.png"
href="http://example.com/img.png"
location="file_preview_modal_main_actions"
>
<i
className="icon icon-download-outline"
/>
</ExternalLink>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="publicLink"
overlay={
<Tooltip
id="close-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Close"
id="full_screen_modal.close"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="file-preview-modal-main-actions__action-item"
onClick={[MockFunction]}
>
<i
className="icon icon-close"
/>
</button>
</OverlayTrigger>
</div>
`;
exports[`components/file_preview_modal/file_preview_modal_main_actions/FilePreviewModalMainActions should match snapshot when copy content is enabled 1`] = `
<div
className="file-preview-modal-main-actions__actions"
>
<CopyButton
afterCopyText="Copied"
className="file-preview-modal-main-actions__action-item"
content="test content"
placement="bottom"
/>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="download"
overlay={
<Tooltip
id="download-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Download"
id="view_image_popover.download"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<ExternalLink
className="file-preview-modal-main-actions__action-item"
download="img.png"
href="http://example.com/img.png"
location="file_preview_modal_main_actions"
>
<i
className="icon icon-download-outline"
/>
</ExternalLink>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="publicLink"
overlay={
<Tooltip
id="close-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Close"
id="full_screen_modal.close"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="file-preview-modal-main-actions__action-item"
onClick={[MockFunction]}
>
<i
className="icon icon-close"
/>
</button>
</OverlayTrigger>
</div>
`;
exports[`components/file_preview_modal/file_preview_modal_main_actions/FilePreviewModalMainActions should match snapshot with public links disabled 1`] = `
<div
className="file-preview-modal-main-actions__actions"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="download"
overlay={
<Tooltip
id="download-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Download"
id="view_image_popover.download"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<ExternalLink
className="file-preview-modal-main-actions__action-item"
download="img.png"
href="http://example.com/img.png"
location="file_preview_modal_main_actions"
>
<i
className="icon icon-download-outline"
/>
</ExternalLink>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="publicLink"
overlay={
<Tooltip
id="close-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Close"
id="full_screen_modal.close"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="file-preview-modal-main-actions__action-item"
onClick={[MockFunction]}
>
<i
className="icon icon-close"
/>
</button>
</OverlayTrigger>
</div>
`;
exports[`components/file_preview_modal/file_preview_modal_main_actions/FilePreviewModalMainActions should match snapshot with public links enabled 1`] = `
<div
className="file-preview-modal-main-actions__actions"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="filePreviewPublicLink"
onExit={[Function]}
overlay={
<Tooltip
id="link-variant-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Get a public link"
id="view_image_popover.publicLink"
/>
</Tooltip>
}
placement="bottom"
shouldUpdatePosition={true}
trigger={
Array [
"hover",
"focus",
]
}
>
<a
className="file-preview-modal-main-actions__action-item"
href="#"
onClick={[Function]}
>
<i
className="icon icon-link-variant"
/>
</a>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="download"
overlay={
<Tooltip
id="download-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Download"
id="view_image_popover.download"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<ExternalLink
className="file-preview-modal-main-actions__action-item"
download="img.png"
href="http://example.com/img.png"
location="file_preview_modal_main_actions"
>
<i
className="icon icon-download-outline"
/>
</ExternalLink>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="publicLink"
overlay={
<Tooltip
id="close-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Close"
id="full_screen_modal.close"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="file-preview-modal-main-actions__action-item"
onClick={[MockFunction]}
>
<i
className="icon icon-close"
/>
</button>
</OverlayTrigger>
</div>
`;
exports[`components/file_preview_modal/file_preview_modal_main_actions/FilePreviewModalMainActions should match snapshot with public links enabled 2`] = `
<a
className="file-preview-modal-main-actions__action-item"
href="#"
onClick={[Function]}
>
<i
className="icon icon-link-variant"
/>
</a>
`;
|
2,267 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_main_nav/file_preview_modal_main_nav.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import FilePreviewModalMainNav from './file_preview_modal_main_nav';
describe('components/file_preview_modal/file_preview_modal_main_nav/FilePreviewModalMainNav', () => {
const defaultProps = {
fileIndex: 1,
totalFiles: 2,
handlePrev: jest.fn(),
handleNext: jest.fn(),
};
test('should match snapshot with multiple files', () => {
const props = {
...defaultProps,
enablePublicLink: false,
};
const wrapper = shallow(<FilePreviewModalMainNav {...props}/>);
expect(wrapper).toMatchSnapshot();
});
});
|
2,269 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_main_nav | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/file_preview_modal_main_nav/__snapshots__/file_preview_modal_main_nav.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_preview_modal/file_preview_modal_main_nav/FilePreviewModalMainNav should match snapshot with multiple files 1`] = `
<div
className="file_preview_modal_main_nav"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="previewArrowLeft"
overlay={
<Tooltip
id="close-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Close"
id="generic.close"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="file_preview_modal_main_nav__prev"
id="previewArrowLeft"
onClick={[MockFunction]}
>
<i
className="icon icon-chevron-left"
/>
</button>
</OverlayTrigger>
<span
className="modal-bar-file-count"
>
<MemoizedFormattedMessage
defaultMessage="{count, number} of {total, number}"
id="file_preview_modal_main_nav.file"
values={
Object {
"count": 2,
"total": 2,
}
}
/>
</span>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="publicLink"
overlay={
<Tooltip
id="close-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Next"
id="generic.next"
/>
</Tooltip>
}
placement="bottom"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
className="file_preview_modal_main_nav__next"
id="previewArrowRight"
onClick={[MockFunction]}
>
<i
className="icon icon-chevron-right"
/>
</button>
</OverlayTrigger>
</div>
`;
|
2,271 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/popover_bar/popover_bar.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import PopoverBar from 'components/file_preview_modal/popover_bar/popover_bar';
describe('components/file_preview_modal/popover_bar/PopoverBar', () => {
const defaultProps = {
showZoomControls: false,
};
test('should match snapshot with zoom controls enabled', () => {
const props = {
...defaultProps,
showZoomControls: true,
};
const wrapper = shallow(<PopoverBar {...props}/>);
expect(wrapper).toMatchSnapshot();
});
});
|
2,273 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/popover_bar | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_preview_modal/popover_bar/__snapshots__/popover_bar.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_preview_modal/popover_bar/PopoverBar should match snapshot with zoom controls enabled 1`] = `
<div
className="modal-button-bar file-preview-modal__zoom-bar"
data-testid="fileCountFooter"
>
<div
className="modal-column"
>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="zoomOut"
overlay={
<Tooltip
id="zoom-out-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Zoom Out"
id="view_image.zoom_out"
/>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<span
className="btn-inactive"
>
<i
className="icon icon-minus"
/>
</span>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="zoomReset"
overlay={
<Tooltip
id="zoom-reset-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Reset Zoom"
id="view_image.zoom_reset"
/>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<span
className="btn-inactive"
>
<i
className="icon icon-magnify-minus"
/>
</span>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
key="zoomIn"
overlay={
<Tooltip
id="zoom-in-icon-tooltip"
>
<Memo(MemoizedFormattedMessage)
defaultMessage="Zoom In"
id="view_image.zoom_in"
/>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<span
className="btn-inactive"
>
<i
className="icon icon-plus"
/>
</span>
</OverlayTrigger>
</div>
</div>
`;
|
2,275 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_search_results/file_search_result_item.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import type {ShallowWrapper} from 'enzyme';
import React from 'react';
import type {ChannelType} from '@mattermost/types/channels';
import Constants from 'utils/constants';
import {TestHelper} from 'utils/test_helper';
import FileSearchResultItem from './file_search_result_item';
describe('components/file_search_result/FileSearchResultItem', () => {
const baseProps = {
channelId: 'channel_id',
fileInfo: TestHelper.getFileInfoMock({}),
channelDisplayName: '',
channelType: Constants.OPEN_CHANNEL as ChannelType,
teamName: 'test-team-name',
onClick: jest.fn(),
actions: {
openModal: jest.fn(),
},
};
test('should match snapshot', () => {
const wrapper: ShallowWrapper<any, any, FileSearchResultItem> = shallow(
<FileSearchResultItem {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with channel name', () => {
const props = {
...baseProps,
channelDisplayName: 'test',
};
const wrapper: ShallowWrapper<any, any, FileSearchResultItem> = shallow(
<FileSearchResultItem {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with DM', () => {
const props = {
...baseProps,
channelDisplayName: 'test',
channelType: Constants.DM_CHANNEL as ChannelType,
};
const wrapper: ShallowWrapper<any, any, FileSearchResultItem> = shallow(
<FileSearchResultItem {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with GM', () => {
const props = {
...baseProps,
channelDisplayName: 'test',
channelType: Constants.GM_CHANNEL as ChannelType,
};
const wrapper: ShallowWrapper<any, any, FileSearchResultItem> = shallow(
<FileSearchResultItem {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
});
|
2,278 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_search_results | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_search_results/__snapshots__/file_search_result_item.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/file_search_result/FileSearchResultItem should match snapshot 1`] = `
<div
className="search-item__container"
data-testid="search-item-container"
>
<button
className="FileSearchResultItem"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
<div
className="fileData"
>
<div
className="fileDataName"
>
name
</div>
<div
className="fileMetadata"
>
<span>
1B
</span>
<span>
•
</span>
<Connect(injectIntl(Timestamp))
ranges={
Array [
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Today"
id="date_separator.today"
/>,
"equals": Array [
"day",
0,
],
},
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Yesterday"
id="date_separator.yesterday"
/>,
"equals": Array [
"day",
-1,
],
},
]
}
value={1}
/>
</div>
</div>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
More Actions
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<MenuWrapper
animationComponent={[Function]}
className=""
onToggle={[Function]}
stopPropagationOnToggle={true}
>
<a
className="action-icon dots-icon"
href="#"
>
<i
className="icon icon-dots-vertical"
/>
</a>
<Menu
ariaLabel="file menu"
openLeft={true}
>
<MenuItemAction
ariaLabel="Open in channel"
onClick={[Function]}
show={true}
text="Open in channel"
/>
<MenuItemAction
ariaLabel="Copy link"
onClick={[Function]}
show={true}
text="Copy link"
/>
</Menu>
</MenuWrapper>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
Download
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<a
className="action-icon download-icon"
href="/api/v4/files/file_info_id?download=1"
onClick={[Function]}
>
<i
className="icon icon-download-outline"
/>
</a>
</OverlayTrigger>
</button>
</div>
`;
exports[`components/file_search_result/FileSearchResultItem should match snapshot with DM 1`] = `
<div
className="search-item__container"
data-testid="search-item-container"
>
<button
className="FileSearchResultItem"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
<div
className="fileData"
>
<div
className="fileDataName"
>
name
</div>
<div
className="fileMetadata"
>
<Memo(Tag)
className="file-search-channel-name"
text={
<Memo(MemoizedFormattedMessage)
defaultMessage="Direct Message"
id="search_item.file_tag.direct_message"
/>
}
/>
<span>
1B
</span>
<span>
•
</span>
<Connect(injectIntl(Timestamp))
ranges={
Array [
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Today"
id="date_separator.today"
/>,
"equals": Array [
"day",
0,
],
},
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Yesterday"
id="date_separator.yesterday"
/>,
"equals": Array [
"day",
-1,
],
},
]
}
value={1}
/>
</div>
</div>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
More Actions
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<MenuWrapper
animationComponent={[Function]}
className=""
onToggle={[Function]}
stopPropagationOnToggle={true}
>
<a
className="action-icon dots-icon"
href="#"
>
<i
className="icon icon-dots-vertical"
/>
</a>
<Menu
ariaLabel="file menu"
openLeft={true}
>
<MenuItemAction
ariaLabel="Open in channel"
onClick={[Function]}
show={true}
text="Open in channel"
/>
<MenuItemAction
ariaLabel="Copy link"
onClick={[Function]}
show={true}
text="Copy link"
/>
</Menu>
</MenuWrapper>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
Download
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<a
className="action-icon download-icon"
href="/api/v4/files/file_info_id?download=1"
onClick={[Function]}
>
<i
className="icon icon-download-outline"
/>
</a>
</OverlayTrigger>
</button>
</div>
`;
exports[`components/file_search_result/FileSearchResultItem should match snapshot with GM 1`] = `
<div
className="search-item__container"
data-testid="search-item-container"
>
<button
className="FileSearchResultItem"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
<div
className="fileData"
>
<div
className="fileDataName"
>
name
</div>
<div
className="fileMetadata"
>
<Memo(Tag)
className="file-search-channel-name"
text={
<Memo(MemoizedFormattedMessage)
defaultMessage="Group Message"
id="search_item.file_tag.group_message"
/>
}
/>
<span>
1B
</span>
<span>
•
</span>
<Connect(injectIntl(Timestamp))
ranges={
Array [
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Today"
id="date_separator.today"
/>,
"equals": Array [
"day",
0,
],
},
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Yesterday"
id="date_separator.yesterday"
/>,
"equals": Array [
"day",
-1,
],
},
]
}
value={1}
/>
</div>
</div>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
More Actions
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<MenuWrapper
animationComponent={[Function]}
className=""
onToggle={[Function]}
stopPropagationOnToggle={true}
>
<a
className="action-icon dots-icon"
href="#"
>
<i
className="icon icon-dots-vertical"
/>
</a>
<Menu
ariaLabel="file menu"
openLeft={true}
>
<MenuItemAction
ariaLabel="Open in channel"
onClick={[Function]}
show={true}
text="Open in channel"
/>
<MenuItemAction
ariaLabel="Copy link"
onClick={[Function]}
show={true}
text="Copy link"
/>
</Menu>
</MenuWrapper>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
Download
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<a
className="action-icon download-icon"
href="/api/v4/files/file_info_id?download=1"
onClick={[Function]}
>
<i
className="icon icon-download-outline"
/>
</a>
</OverlayTrigger>
</button>
</div>
`;
exports[`components/file_search_result/FileSearchResultItem should match snapshot with channel name 1`] = `
<div
className="search-item__container"
data-testid="search-item-container"
>
<button
className="FileSearchResultItem"
onClick={[Function]}
>
<Connect(FileThumbnail)
fileInfo={
Object {
"archived": false,
"clientId": "client_id",
"create_at": 1,
"delete_at": 1,
"extension": "jpg",
"has_preview_image": true,
"height": 200,
"id": "file_info_id",
"mime_type": "mime_type",
"name": "name",
"size": 1,
"update_at": 1,
"user_id": "user_id",
"width": 350,
}
}
/>
<div
className="fileData"
>
<div
className="fileDataName"
>
name
</div>
<div
className="fileMetadata"
>
<Memo(Tag)
className="file-search-channel-name"
text="test"
/>
<span>
1B
</span>
<span>
•
</span>
<Connect(injectIntl(Timestamp))
ranges={
Array [
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Today"
id="date_separator.today"
/>,
"equals": Array [
"day",
0,
],
},
Object {
"display": <Memo(MemoizedFormattedMessage)
defaultMessage="Yesterday"
id="date_separator.yesterday"
/>,
"equals": Array [
"day",
-1,
],
},
]
}
value={1}
/>
</div>
</div>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
More Actions
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<MenuWrapper
animationComponent={[Function]}
className=""
onToggle={[Function]}
stopPropagationOnToggle={true}
>
<a
className="action-icon dots-icon"
href="#"
>
<i
className="icon icon-dots-vertical"
/>
</a>
<Menu
ariaLabel="file menu"
openLeft={true}
>
<MenuItemAction
ariaLabel="Open in channel"
onClick={[Function]}
show={true}
text="Open in channel"
/>
<MenuItemAction
ariaLabel="Copy link"
onClick={[Function]}
show={true}
text="Copy link"
/>
</Menu>
</MenuWrapper>
</OverlayTrigger>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={1000}
overlay={
<Tooltip
id="file-name__tooltip"
>
Download
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<a
className="action-icon download-icon"
href="/api/v4/files/file_info_id?download=1"
onClick={[Function]}
>
<i
className="icon icon-download-outline"
/>
</a>
</OverlayTrigger>
</button>
</div>
`;
|
2,279 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_upload/file_upload.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import type {MouseEvent, DragEvent, ChangeEvent} from 'react';
import type {FileInfo} from '@mattermost/types/files';
import {General} from 'mattermost-redux/constants';
import FileUpload, {type FileUpload as FileUploadClass} from 'components/file_upload/file_upload';
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import {clearFileInput} from 'utils/utils';
import type {FilesWillUploadHook} from 'types/store/plugins';
const generatedIdRegex = /[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/;
jest.mock('utils/file_utils', () => {
const original = jest.requireActual('utils/file_utils');
return {
...original,
canDownloadFiles: jest.fn(() => true),
};
});
jest.mock('utils/utils', () => {
const original = jest.requireActual('utils/utils');
return {
...original,
clearFileInput: jest.fn(),
sortFilesByName: jest.fn((files) => {
return files.sort((a: File, b: File) => a.name.localeCompare(b.name, 'en', {numeric: true}));
}),
};
});
const RealDate = Date;
const RealFile = File;
beforeEach(() => {
global.Date.prototype.getDate = () => 1;
global.Date.prototype.getFullYear = () => 2000;
global.Date.prototype.getHours = () => 1;
global.Date.prototype.getMinutes = () => 1;
global.Date.prototype.getMonth = () => 1;
});
afterEach(() => {
global.Date = RealDate;
global.File = RealFile;
});
describe('components/FileUpload', () => {
const MaxFileSize = 10;
const uploadFile: () => XMLHttpRequest = jest.fn();
const baseProps = {
channelId: 'channel_id',
fileCount: 1,
getTarget: jest.fn(),
locale: General.DEFAULT_LOCALE,
onClick: jest.fn(),
onFileUpload: jest.fn(),
onFileUploadChange: jest.fn(),
onUploadError: jest.fn(),
onUploadStart: jest.fn(),
onUploadProgress: jest.fn(),
postType: 'post',
maxFileSize: MaxFileSize,
canUploadFiles: true,
rootId: 'root_id',
pluginFileUploadMethods: [],
pluginFilesWillUploadHooks: [],
actions: {
uploadFile,
},
};
test('should match snapshot', () => {
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should call onClick when fileInput is clicked', () => {
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
wrapper.find('input').simulate('click');
expect(baseProps.onClick).toHaveBeenCalledTimes(1);
});
test('should prevent event default and progogation on call of onTouchEnd on fileInput', () => {
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.handleLocalFileUploaded = jest.fn();
instance.fileInput = {
current: {
click: () => instance.handleLocalFileUploaded({} as unknown as MouseEvent<HTMLInputElement>),
} as unknown as HTMLInputElement,
};
const event = {stopPropagation: jest.fn(), preventDefault: jest.fn()};
wrapper.find('button').simulate('touchend', event);
expect(event.stopPropagation).toHaveBeenCalled();
expect(event.preventDefault).toHaveBeenCalled();
expect(instance.handleLocalFileUploaded).toHaveBeenCalled();
});
test('should prevent event default and progogation on call of onClick on fileInput', () => {
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.handleLocalFileUploaded = jest.fn();
instance.fileInput = {
current: {
click: () => instance.handleLocalFileUploaded({} as unknown as MouseEvent<HTMLInputElement>),
} as unknown as HTMLInputElement,
};
const event = {stopPropagation: jest.fn(), preventDefault: jest.fn()};
wrapper.find('button').simulate('click', event);
expect(event.stopPropagation).toHaveBeenCalled();
expect(event.preventDefault).toHaveBeenCalled();
expect(instance.handleLocalFileUploaded).toHaveBeenCalled();
});
test('should match state and call handleMaxUploadReached or props.onClick on handleLocalFileUploaded', () => {
const wrapper = shallowWithIntl(
<FileUpload
{...baseProps}
fileCount={9}
/>,
);
const instance = wrapper.instance() as FileUploadClass;
const evt = {preventDefault: jest.fn()} as unknown as MouseEvent<HTMLInputElement>;
instance.handleMaxUploadReached = jest.fn();
// allow file upload
wrapper.setState({menuOpen: true});
instance.handleLocalFileUploaded(evt);
expect(baseProps.onClick).toHaveBeenCalledTimes(1);
expect(instance.handleMaxUploadReached).not.toBeCalled();
expect(wrapper.state('menuOpen')).toEqual(false);
// not allow file upload, max limit has been reached
wrapper.setState({menuOpen: true});
wrapper.setProps({fileCount: 10});
instance.handleLocalFileUploaded(evt);
expect(baseProps.onClick).toHaveBeenCalledTimes(1);
expect(instance.handleMaxUploadReached).toHaveBeenCalledTimes(1);
expect(instance.handleMaxUploadReached).toBeCalledWith(evt);
expect(wrapper.state('menuOpen')).toEqual(false);
});
test('should props.onFileUpload when fileUploadSuccess is called', () => {
const data = {
file_infos: [{id: 'file_info1'} as FileInfo],
client_ids: ['id1'],
};
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.fileUploadSuccess(data, 'channel_id', 'root_id');
expect(baseProps.onFileUpload).toHaveBeenCalledTimes(1);
expect(baseProps.onFileUpload).toHaveBeenCalledWith(data.file_infos, data.client_ids, 'channel_id', 'root_id');
});
test('should props.onUploadError when fileUploadFail is called', () => {
const params = {
err: 'error_message',
clientId: 'client_id',
channelId: 'channel_id',
rootId: 'root_id',
};
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.fileUploadFail(params.err, params.clientId, params.channelId, params.rootId);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadError).toHaveBeenCalledWith(params.err, params.clientId, params.channelId, params.rootId);
});
test('should upload file on paste', () => {
const expectedFileName = 'test.png';
const event = new Event('paste');
event.preventDefault = jest.fn();
const getAsFile = jest.fn().mockReturnValue(new File(['test'], 'test.png'));
const file = {getAsFile, kind: 'file', name: 'test.png'};
(event as any).clipboardData = {items: [file], types: ['image/png'], getData: () => {}};
const wrapper = shallowWithIntl(
<FileUpload
{...baseProps}
/>,
);
const instance = wrapper.instance() as FileUploadClass;
jest.spyOn(instance, 'containsEventTarget').mockReturnValue(true);
const spy = jest.spyOn(instance, 'checkPluginHooksAndUploadFiles');
document.dispatchEvent(event);
expect(event.preventDefault).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith([expect.objectContaining({name: expectedFileName})]);
expect(spy.mock.calls[0][0][0]).toBeInstanceOf(Blob); // first call, first arg, first item in array
expect(baseProps.onFileUploadChange).toHaveBeenCalled();
});
test('should not prevent paste event default if no file in clipboard', () => {
const event = new Event('paste');
event.preventDefault = jest.fn();
const getAsString = jest.fn();
(event as any).clipboardData = {items: [{getAsString, kind: 'string', type: 'text/plain'}],
types: ['text/plain'],
getData: () => {
return '';
}};
const wrapper = shallowWithIntl(
<FileUpload
{...baseProps}
/>,
);
const instance = wrapper.instance() as FileUploadClass;
const spy = jest.spyOn(instance, 'containsEventTarget').mockReturnValue(true);
document.dispatchEvent(event);
expect(spy).toHaveBeenCalled();
expect(event.preventDefault).not.toHaveBeenCalled();
});
test('should have props.functions when uploadFiles is called', () => {
const files = [{name: 'file1.pdf'} as File, {name: 'file2.jpg'} as File];
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.checkPluginHooksAndUploadFiles(files);
expect(uploadFile).toHaveBeenCalledTimes(2);
expect(baseProps.onUploadStart).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadStart).toHaveBeenCalledWith(
Array(2).fill(expect.stringMatching(generatedIdRegex)),
baseProps.channelId,
);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadError).toHaveBeenCalledWith(null);
});
test('should error max upload files', () => {
const fileCount = 10;
const props = {...baseProps, fileCount};
const files = [{name: 'file1.pdf'} as File, {name: 'file2.jpg'} as File];
const wrapper = shallowWithIntl(
<FileUpload {...props}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.checkPluginHooksAndUploadFiles(files);
expect(uploadFile).not.toBeCalled();
expect(baseProps.onUploadStart).toBeCalledWith([], props.channelId);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(2);
expect(baseProps.onUploadError.mock.calls[0][0]).toEqual(null);
});
test('should error max upload files', () => {
const fileCount = 10;
const props = {...baseProps, fileCount};
const files = [{name: 'file1.pdf'} as File, {name: 'file2.jpg'} as File];
const wrapper = shallowWithIntl(
<FileUpload {...props}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.checkPluginHooksAndUploadFiles(files);
expect(uploadFile).not.toBeCalled();
expect(baseProps.onUploadStart).toBeCalledWith([], props.channelId);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(2);
expect(baseProps.onUploadError.mock.calls[0][0]).toEqual(null);
});
test('should error max too large files', () => {
const files = [{name: 'file1.pdf', size: MaxFileSize + 1} as File];
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.checkPluginHooksAndUploadFiles(files);
expect(uploadFile).not.toBeCalled();
expect(baseProps.onUploadStart).toBeCalledWith([], baseProps.channelId);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(2);
expect(baseProps.onUploadError.mock.calls[0][0]).toEqual(null);
});
test('should functions when handleChange is called', () => {
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const e = {target: {files: [{name: 'file1.pdf'}]}} as unknown as ChangeEvent<HTMLInputElement>;
const instance = wrapper.instance() as FileUploadClass;
instance.uploadFiles = jest.fn();
instance.handleChange(e);
expect(instance.uploadFiles).toBeCalled();
expect(instance.uploadFiles).toHaveBeenCalledWith(e.target.files);
expect(clearFileInput).toBeCalled();
expect(clearFileInput).toHaveBeenCalledWith(e.target);
expect(baseProps.onFileUploadChange).toBeCalled();
expect(baseProps.onFileUploadChange).toHaveBeenCalledWith();
});
test('should functions when handleDrop is called', () => {
const wrapper = shallowWithIntl(
<FileUpload {...baseProps}/>,
);
const e = {dataTransfer: {files: [{name: 'file1.pdf'}]}} as unknown as DragEvent<HTMLInputElement>;
const instance = wrapper.instance() as FileUploadClass;
instance.uploadFiles = jest.fn();
instance.handleDrop(e);
expect(baseProps.onUploadError).toBeCalled();
expect(baseProps.onUploadError).toHaveBeenCalledWith(null);
expect(instance.uploadFiles).toBeCalled();
expect(instance.uploadFiles).toHaveBeenCalledWith(e.dataTransfer.files);
expect(baseProps.onFileUploadChange).toBeCalled();
expect(baseProps.onFileUploadChange).toHaveBeenCalledWith();
});
test('FilesWillUploadHook - should reject all files', () => {
const pluginHook = () => {
return {files: null};
};
const props = {...baseProps, pluginFilesWillUploadHooks: [{hook: pluginHook} as unknown as FilesWillUploadHook]};
const files = [{name: 'file1.pdf'} as File, {name: 'file2.jpg'} as File];
const wrapper = shallowWithIntl(
<FileUpload {...props}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.checkPluginHooksAndUploadFiles(files);
expect(uploadFile).toHaveBeenCalledTimes(0);
expect(baseProps.onUploadStart).toHaveBeenCalledTimes(0);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadError).toHaveBeenCalledWith(null);
});
test('FilesWillUploadHook - should reject one file and allow one file', () => {
const pluginHook = (files: File[]) => {
return {files: files.filter((f) => f.name === 'file1.pdf')};
};
const props = {...baseProps, pluginFilesWillUploadHooks: [{hook: pluginHook} as unknown as FilesWillUploadHook]};
const files = [{name: 'file1.pdf'} as File, {name: 'file2.jpg'} as File];
const wrapper = shallowWithIntl(
<FileUpload {...props}/>,
);
const instance = wrapper.instance() as FileUploadClass;
instance.checkPluginHooksAndUploadFiles(files);
expect(uploadFile).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadStart).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadStart).toHaveBeenCalledWith([expect.stringMatching(generatedIdRegex)], props.channelId);
expect(baseProps.onUploadError).toHaveBeenCalledTimes(1);
expect(baseProps.onUploadError).toHaveBeenCalledWith(null);
});
});
|
2,282 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_upload | petrpan-code/mattermost/mattermost/webapp/channels/src/components/file_upload/__snapshots__/file_upload.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/FileUpload should match snapshot 1`] = `
<div
className="style--none"
>
<div>
<OverlayTrigger
defaultOverlayShown={false}
delayShow={400}
overlay={
<Tooltip
id="upload-tooltip"
>
<Memo(KeyboardShortcutSequence)
hoistDescription={true}
isInsideTooltip={true}
shortcut={
Object {
"default": Object {
"defaultMessage": "Upload files: Ctrl|U",
"id": "shortcuts.files.upload",
},
"mac": Object {
"defaultMessage": "Upload files: ⌘|U",
"id": "shortcuts.files.upload.mac",
},
}
}
/>
</Tooltip>
}
placement="top"
trigger={
Array [
"hover",
"focus",
]
}
>
<button
aria-label="attachment"
className="style--none AdvancedTextEditor__action-button"
id="fileUploadButton"
onClick={[Function]}
onTouchEnd={[Function]}
type="button"
>
<PaperclipIcon
aria-label="Attachment Icon"
color="currentColor"
size={18}
/>
</button>
</OverlayTrigger>
<input
accept=""
aria-label="Upload files"
id="fileUploadInput"
multiple={true}
onChange={[Function]}
onClick={[Function]}
tabIndex={-1}
type="file"
/>
</div>
</div>
`;
|
2,289 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/get_public_link_modal/get_public_link_modal.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import GetLinkModal from 'components/get_link_modal';
import GetPublicLinkModal from 'components/get_public_link_modal/get_public_link_modal';
describe('components/GetPublicLinkModal', () => {
const baseProps = {
link: 'http://mattermost.com/files/n5bnoaz3e7g93nyipzo1bixdwr/public?h=atw9qQHI1nUPnxo1e48tPspo1Qvwd3kHtJZjysmI5zs',
fileId: 'n5bnoaz3e7g93nyipzo1bixdwr',
onExited: jest.fn(),
actions: {
getFilePublicLink: jest.fn(),
},
};
test('should match snapshot when link is empty', () => {
const props = {
...baseProps,
link: '',
};
const wrapper = shallow<GetPublicLinkModal>(
<GetPublicLinkModal {...props}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot when link is not empty', () => {
const wrapper = shallow<GetPublicLinkModal>(
<GetPublicLinkModal {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot();
});
test('should call getFilePublicLink on GetPublicLinkModal\'s show', () => {
const wrapper = shallow<GetPublicLinkModal>(
<GetPublicLinkModal {...baseProps}/>,
);
wrapper.setState({show: true});
expect(baseProps.actions.getFilePublicLink).toHaveBeenCalledTimes(1);
expect(baseProps.actions.getFilePublicLink).toHaveBeenCalledWith(baseProps.fileId);
});
test('should not call getFilePublicLink on GetLinkModal\'s onHide', () => {
const wrapper = shallow<GetPublicLinkModal>(
<GetPublicLinkModal {...baseProps}/>,
);
wrapper.setState({show: true});
baseProps.actions.getFilePublicLink.mockClear();
wrapper.find(GetLinkModal).first().props().onHide();
expect(baseProps.actions.getFilePublicLink).not.toHaveBeenCalled();
});
test('should call handleToggle on GetLinkModal\'s onHide', () => {
const wrapper = shallow<GetPublicLinkModal>(
<GetPublicLinkModal {...baseProps}/>);
wrapper.find(GetLinkModal).first().props().onHide();
expect(wrapper.state('show')).toBe(false);
});
});
|
2,292 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components/get_public_link_modal | petrpan-code/mattermost/mattermost/webapp/channels/src/components/get_public_link_modal/__snapshots__/get_public_link_modal.test.tsx.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/GetPublicLinkModal should match snapshot when link is empty 1`] = `
<GetLinkModal
helpText="The link below allows anyone to see this file without being registered on this server."
link=""
onExited={[MockFunction]}
onHide={[Function]}
show={true}
title="Copy Public Link"
/>
`;
exports[`components/GetPublicLinkModal should match snapshot when link is not empty 1`] = `
<GetLinkModal
helpText="The link below allows anyone to see this file without being registered on this server."
link="http://mattermost.com/files/n5bnoaz3e7g93nyipzo1bixdwr/public?h=atw9qQHI1nUPnxo1e48tPspo1Qvwd3kHtJZjysmI5zs"
onExited={[MockFunction]}
onHide={[Function]}
show={true}
title="Copy Public Link"
/>
`;
|
2,297 | 0 | petrpan-code/mattermost/mattermost/webapp/channels/src/components | petrpan-code/mattermost/mattermost/webapp/channels/src/components/global_header/global_header.test.tsx | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import * as redux from 'react-redux';
import GlobalHeader from 'components/global_header/global_header';
import * as productUtils from 'utils/products';
describe('components/global/global_header', () => {
test('should be disabled when global header is disabled', () => {
const spy = jest.spyOn(redux, 'useSelector');
spy.mockReturnValue(false);
const spyProduct = jest.spyOn(productUtils, 'useCurrentProductId');
spyProduct.mockReturnValue(null);
const wrapper = shallow(
<GlobalHeader/>,
);
// Global header should render null
expect(wrapper.type()).toEqual(null);
});
test('should be enabled when global header is enabled', () => {
const spy = jest.spyOn(redux, 'useSelector');
spy.mockReturnValue(true);
const spyProduct = jest.spyOn(productUtils, 'useCurrentProductId');
spyProduct.mockReturnValue(null);
const wrapper = shallow(
<GlobalHeader/>,
);
// Global header should not be null
expect(wrapper.type()).not.toEqual(null);
});
});
|
Subsets and Splits