Commit a53bd74f authored by Saturnino Abril's avatar Saturnino Abril Committed by GitHub

fix unit test of AboutBuildModal component (#111)

parent fd765b68
......@@ -68,6 +68,7 @@
"cross-env": "5.0.5",
"css-loader": "0.28.7",
"enzyme": "3.0.0",
"enzyme-adapter-react-15": "1.0.1",
"enzyme-to-json": "3.0.1",
"eslint": "3.17.1",
"eslint-plugin-react": "6.10.0",
......@@ -89,6 +90,7 @@
"node-sass": "4.5.3",
"raw-loader": "0.5.1",
"react-addons-test-utils": "15.6.2",
"react-test-renderer": "15",
"remote-redux-devtools": "0.5.12",
"remote-redux-devtools-on-debugger": "0.8.2",
"sass-loader": "6.0.6",
......@@ -109,7 +111,7 @@
"collectCoverageFrom": [
"actions/**/*.{js,jsx}",
"client/**/*.{js,jsx}",
"components/**/*.{js,jsx}",
"components/**/*.jsx",
"routes/**/*.{js,jsx}",
"stores/**/*.{js,jsx}",
"utils/**/*.{js,jsx}"
......
......@@ -2,20 +2,28 @@
// See License.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import {Modal} from 'react-bootstrap';
import {configure, shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx';
import AboutBuildModal from 'components/about_build_modal.jsx';
import {Modal} from 'react-bootstrap';
import AboutBuildModal from 'components/about_build_modal/about_build_modal.jsx';
configure({adapter: new Adapter()});
describe('components/AboutBuildModal', () => {
let config = null;
let license = null;
afterEach(() => {
global.window.mm_config = null;
global.window.mm_license = null;
config = null;
license = null;
});
test('should match snapshot for enterprise edition', () => {
global.window.mm_config = {
beforeEach(() => {
config = {
BuildEnterpriseReady: 'true',
Version: '3.6.0',
BuildNumber: '3.6.2',
......@@ -24,106 +32,84 @@ describe('components/AboutBuildModal', () => {
BuildHashEnterprise: '0123456789abcdef',
BuildDate: '21 January 2017'
};
global.window.mm_license = {
isLicensed: 'true',
license = {
IsLicensed: 'true',
Company: 'Mattermost Inc'
};
});
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
test('should match snapshot for enterprise edition', () => {
const wrapper = shallowAboutBuildModal({config, license});
expect(wrapper.find('#versionString').text()).toBe(' 3.6.0\u00a0 (3.6.2)');
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot for team edition', () => {
global.window.mm_config = {
const teamConfig = {
...config,
BuildEnterpriseReady: 'false',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
BuildHashEnterprise: ''
};
global.window.mm_license = null;
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
const wrapper = shallowAboutBuildModal({config: teamConfig, license: {}});
expect(wrapper).toMatchSnapshot();
});
test('should hide the build number if it is the same as the version number', () => {
global.window.mm_config = {
const sameBuildConfig = {
...config,
BuildEnterpriseReady: 'false',
BuildHashEnterprise: '',
Version: '3.6.0',
BuildNumber: '3.6.0',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
BuildNumber: '3.6.0'
};
global.window.mm_license = null;
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
const wrapper = shallowAboutBuildModal({config: sameBuildConfig, license: {}});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('#versionString').text()).toBe(' 3.6.0');
});
test('should show the build number if it is the different from the version number', () => {
global.window.mm_config = {
const differentBuildConfig = {
...config,
BuildEnterpriseReady: 'false',
BuildHashEnterprise: '',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
BuildNumber: '3.6.2'
};
global.window.mm_license = null;
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
const wrapper = shallowAboutBuildModal({config: differentBuildConfig, license: {}});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('#versionString').text()).toBe(' 3.6.0\u00a0 (3.6.2)');
});
test('should call onModalDismissed callback when the modal is hidden', (done) => {
global.window.mm_config = {
BuildEnterpriseReady: 'false',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
};
global.window.mm_license = null;
function onHide() {
done();
}
const wrapper = mountWithIntl(
<AboutBuildModal
config={config}
license={license}
show={true}
onModalDismissed={onHide}
/>
);
wrapper.find(Modal).first().props().onHide();
});
function shallowAboutBuildModal(props = {}) {
const onModalDismissed = jest.fn();
const show = true;
const allProps = {
show,
onModalDismissed,
...props
};
return shallow(<AboutBuildModal {...allProps}/>);
}
});
......@@ -2461,6 +2461,24 @@ entities@^1.1.1, entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
enzyme-adapter-react-15@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/enzyme-adapter-react-15/-/enzyme-adapter-react-15-1.0.1.tgz#c1a3e5966bf1c7221c40aa0f877850175035406f"
dependencies:
enzyme-adapter-utils "^1.0.0"
lodash "^4.17.4"
object.assign "^4.0.4"
object.values "^1.0.4"
prop-types "^15.5.10"
enzyme-adapter-utils@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/enzyme-adapter-utils/-/enzyme-adapter-utils-1.0.1.tgz#fcd81223339a55a312f7552641e045c404084009"
dependencies:
lodash "^4.17.4"
object.assign "^4.0.4"
prop-types "^15.5.10"
enzyme-to-json@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/enzyme-to-json/-/enzyme-to-json-3.0.1.tgz#16468e2ff3e4db817d84f9df38760abbc322273d"
......@@ -6716,6 +6734,13 @@ react-select@1.0.0-rc.10:
prop-types "^15.5.8"
react-input-autosize "^2.0.1"
react-test-renderer@15:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-15.6.2.tgz#d0333434fc2c438092696ca770da5ed48037efa8"
dependencies:
fbjs "^0.8.9"
object-assign "^4.1.0"
react@15.6.1:
version "15.6.1"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment