Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-9547 Added CustomUrlSchemes setting #1270

Merged
merged 8 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added additional unit tests
  • Loading branch information
hmhealey committed Jun 4, 2018
commit e68a1ab7b9a63334a9060d44e1a5c8ea099e4a86
4 changes: 2 additions & 2 deletions components/admin_console/custom_url_schemes_setting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import * as Utils from 'utils/utils';

import Setting from './setting';

export default class TextSetting extends React.Component {
export default class CustomUrlSchemesSetting extends React.Component {
static get propTypes() {
return {
id: PropTypes.string.isRequired,
value: PropTypes.array.isRequired,
onChange: PropTypes.func,
onChange: PropTypes.func.isRequired,
disabled: PropTypes.bool,
setByEnv: PropTypes.bool.isRequired,
};
Expand Down
17 changes: 17 additions & 0 deletions tests/components/__snapshots__/markdown.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components/Markdown should not render markdown when formatting is disabled 1`] = `
<span>
This _is_ some **Markdown**
</span>
`;

exports[`components/Markdown should render properly 1`] = `
Array [
<p
key="0"
/>,
"
",
]
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with multiple items 1`] = `
<Settings
helpText="Allow message text to link if it begins with any of the URL schemes listed here. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
setByEnv={false}
>
<input
className="form-control"
disabled={false}
id="MySetting"
onChange={[Function]}
placeholder="E.g.: \\"git,smtp\\""
type="text"
value="git,smtp,steam"
/>
</Settings>
`;

exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with no items 1`] = `
<Settings
helpText="Allow message text to link if it begins with any of the URL schemes listed here. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
setByEnv={false}
>
<input
className="form-control"
disabled={false}
id="MySetting"
onChange={[Function]}
placeholder="E.g.: \\"git,smtp\\""
type="text"
value=""
/>
</Settings>
`;

exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with one item 1`] = `
<Settings
helpText="Allow message text to link if it begins with any of the URL schemes listed here. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
setByEnv={false}
>
<input
className="form-control"
disabled={false}
id="MySetting"
onChange={[Function]}
placeholder="E.g.: \\"git,smtp\\""
type="text"
value="git"
/>
</Settings>
`;

exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when disabled 1`] = `
<Settings
helpText="Allow message text to link if it begins with any of the URL schemes listed here. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
setByEnv={false}
>
<input
className="form-control"
disabled={true}
id="MySetting"
onChange={[Function]}
placeholder="E.g.: \\"git,smtp\\""
type="text"
value="git,smtp"
/>
</Settings>
`;

exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when set by environment variable 1`] = `
<Settings
helpText="Allow message text to link if it begins with any of the URL schemes listed here. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
setByEnv={true}
>
<input
className="form-control"
disabled={true}
id="MySetting"
onChange={[Function]}
placeholder="E.g.: \\"git,smtp\\""
type="text"
value="git,smtp"
/>
</Settings>
`;
162 changes: 162 additions & 0 deletions tests/components/admin_console/custom_url_scheme_setting.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';
import {shallow} from 'enzyme';

import CustomUrlSchemesSetting from 'components/admin_console/custom_url_schemes_setting';

describe('components/AdminConsole/CustomUrlSchemeSetting', () => {
const baseProps = {
id: 'MySetting',
value: ['git', 'smtp'],
onChange: jest.fn(),
disabled: false,
setByEnv: false,
};

describe('initial state', () => {
test('with no items', () => {
const props = {
...baseProps,
value: [],
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);
expect(wrapper).toMatchSnapshot();

expect(wrapper.state('value')).toEqual('');
});

test('with one item', () => {
const props = {
...baseProps,
value: ['git'],
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);
expect(wrapper).toMatchSnapshot();

expect(wrapper.state('value')).toEqual('git');
});

test('with multiple items', () => {
const props = {
...baseProps,
value: ['git', 'smtp', 'steam'],
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);
expect(wrapper).toMatchSnapshot();

expect(wrapper.state('value')).toEqual('git,smtp,steam');
});
});

describe('onChange', () => {
test('called on change to empty', () => {
const props = {
...baseProps,
onChange: jest.fn(),
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);

wrapper.find('input').simulate('change', {target: {value: ''}});

expect(props.onChange).toBeCalledWith(baseProps.id, []);
});

test('called on change to one item', () => {
const props = {
...baseProps,
onChange: jest.fn(),
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);

wrapper.find('input').simulate('change', {target: {value: ' steam '}});

expect(props.onChange).toBeCalledWith(baseProps.id, ['steam']);
});

test('called on change to two items', () => {
const props = {
...baseProps,
onChange: jest.fn(),
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);

wrapper.find('input').simulate('change', {target: {value: 'steam, git'}});

expect(props.onChange).toBeCalledWith(baseProps.id, ['steam', 'git']);
});

test('called on change to more items', () => {
const props = {
...baseProps,
onChange: jest.fn(),
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);

wrapper.find('input').simulate('change', {target: {value: 'ts3server, smtp, ms-excel'}});

expect(props.onChange).toBeCalledWith(baseProps.id, ['ts3server', 'smtp', 'ms-excel']);
});

test('called on change with extra commas', () => {
const props = {
...baseProps,
onChange: jest.fn(),
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);

wrapper.find('input').simulate('change', {target: {value: ',,,,,chrome,,,,ms-excel,,'}});

expect(props.onChange).toBeCalledWith(baseProps.id, ['chrome', 'ms-excel']);
});
});

test('renders properly when disabled', () => {
const props = {
...baseProps,
disabled: true,
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);
expect(wrapper).toMatchSnapshot();
});

test('renders properly when set by environment variable', () => {
const props = {
...baseProps,
setByEnv: true,
};

const wrapper = shallow(
<CustomUrlSchemesSetting {...props}/>
);
expect(wrapper).toMatchSnapshot();
});
});
38 changes: 38 additions & 0 deletions tests/components/markdown.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';
import {shallow} from 'enzyme';

import Markdown from 'components/markdown/markdown';

describe('components/Markdown', () => {
const baseProps = {
channelNamesMap: {},
enableFormatting: true,
mentionKeys: [],
message: 'This _is_ some **Markdown**',
siteURL: 'https://markdown.example.com',
team: {name: 'yourteamhere'},
hasImageProxy: false,
};

test('should render properly', () => {
const wrapper = shallow(
<Markdown {...baseProps}/>
);
expect(wrapper).toMatchSnapshot();
});

test('should not render markdown when formatting is disabled', () => {
const props = {
...baseProps,
enableFormatting: false,
};

const wrapper = shallow(
<Markdown {...props}/>
);
expect(wrapper).toMatchSnapshot();
});
});