Skip to content

Commit

Permalink
Fix front unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soupette committed Apr 23, 2019
1 parent ff31c75 commit adf4e88
Show file tree
Hide file tree
Showing 41 changed files with 582 additions and 176 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

10 changes: 10 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
presets: [
require.resolve('@babel/preset-env'),
require.resolve('@babel/preset-react'),
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
].map(require.resolve),
};
26 changes: 15 additions & 11 deletions jest.config.front.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,41 @@ const jest = require('jest');
module.exports = {
collectCoverageFrom: [
'packages/strapi-admin/admin/src/**/**/*.js',
'!packages/strapi-admin/admin/src/*.js',
'!packages/strapi-admin/admin/src/utils/*.js',
'packages/strapi-plugin-*/admin/src/**/**/*.js',
'packages/strapi-plugin-*/admin/src/InjectedComponents/*.js',
'packages/strapi-plugin-*/admin/src/InjectedComponents/tests/*.js',
'!packages/strapi-plugin-content-type-builder/admin/src/components/TableList/*.js',
'!packages/strapi-plugin-content-type-builder/admin/src/components/TableListRow/*.js',
'!packages/strapi-plugin-*/admin/src/utils/*.js',
'!packages/strapi-plugin-*/admin/src/lifecycles/*.js',
'!packages/strapi-plugin-*/admin/src/**/**/tests/*.test.{js,jsx}',
],
globals: {
__webpack_public_path__: 'http://localhost:4000',
strapi: {},
BACKEND_URL: 'http://localhost:1337',
MODE: 'host',
PUBLIC_PATH: '/admin',
REMOTE_URL: '/',
NODE_ENV: 'test',
},
moduleDirectories: [
'node_modules',
'<rootDir>/packages/strapi-helper-plugin/node_modules',
'<rootDir>/packages/strapi-helper-plugin',
'<rootDir>/packages/strapi-helper-plugin/lib/src',
'<rootDir>/packages/strapi-admin/node_modules',
'<rootDir>/test/config/front',
],
moduleNameMapper: {
'.*\\.(css|less|styl|scss|sass)$':
'<rootDir>/packages/strapi-helper-plugin/lib/internals/mocks/cssModule.js',
'<rootDir>/test/config/front/mocks/cssModule.js',
'.*\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/packages/strapi-helper-plugin/lib/internals/mocks/image.js',
'<rootDir>/test/config/front/mocks/image.js',
},
rootDir: process.cwd(),
setupTestFrameworkScriptFile:
'<rootDir>/packages/strapi-helper-plugin/lib/internals/testing/test-bundler.js',
setupFilesAfterEnv: ['<rootDir>/test/config/front/test-bundler.js'],
setupFiles: [
'<rootDir>/packages/strapi-helper-plugin/node_modules/raf/polyfill',
'<rootDir>/packages/strapi-helper-plugin/lib/internals/testing/enzyme-setup.js',
'<rootDir>/packages/strapi-helper-plugin/lib/internals/testing/strapi.js',
'<rootDir>/test/config/front/enzyme-setup.js',
'<rootDir>/test/config/front/strapi.js',
],
testRegex: 'tests/.*\\.test\\.js$',
transform: {
Expand Down
31 changes: 20 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
{
"private": true,
"version": "3.0.0-alpha.25.2",
"dependencies": {},
"dependencies": {
"npm": "^6.9.0",
"uninstall": "0.0.0"
},
"devDependencies": {
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/polyfill": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-react": "^7.0.0",
"assert": "~1.3.0",
"axios": "^0.18.0",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "^6.1.2",
"babel-jest": "^24.1.0",
"babel-loader": "7.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "6.23.0",
"babel-plugin-transform-es2015-parameters": "6.24.1",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-react-constant-elements": "6.23.0",
"babel-plugin-transform-react-inline-elements": "6.22.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.18",
"babel-polyfill": "6.26.0",
"babel-preset-env": "1.6.1",
"babel-preset-react": "6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-constant-elements": "^6.23.0",
"babel-plugin-transform-react-inline-elements": "^6.22.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.18",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chalk": "^2.4.1",
"cross-env": "^5.2.0",
"cypress": "3.1.2",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.12.1",
"eslint": "^4.19.1",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-react": "^7.7.0",
Expand Down
40 changes: 21 additions & 19 deletions packages/strapi-admin/admin/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ import plugins from './plugins';
const initialState = {};
const store = configureStore(initialState, history);
const { dispatch } = store;
const MOUNT_NODE = document.getElementById('app');
const MOUNT_NODE =
document.getElementById('app') || document.createElement('div');

dispatch(getAppPluginsSucceeded(Object.keys(plugins)));

Expand Down Expand Up @@ -165,7 +166,6 @@ const render = messages => {
ReactDOM.render(
<Provider store={store}>
<LanguageProvider messages={messages}>
{/* <ConnectedRouter history={history}> */}
<BrowserRouter basename={basename}>
<App store={store} />
</BrowserRouter>
Expand All @@ -183,23 +183,25 @@ if (module.hot) {
});
}

// Chunked polyfill for browsers without Intl support
if (!window.Intl) {
new Promise(resolve => {
resolve(import('intl'));
})
.then(() =>
Promise.all([
import('intl/locale-data/jsonp/en.js'),
import('intl/locale-data/jsonp/de.js'),
]),
) // eslint-disable-line prettier/prettier
.then(() => render(translationMessages))
.catch(err => {
throw err;
});
} else {
render(translationMessages);
if (NODE_ENV !== 'test') {
// Chunked polyfill for browsers without Intl support
if (!window.Intl) {
new Promise(resolve => {
resolve(import('intl'));
})
.then(() =>
Promise.all([
import('intl/locale-data/jsonp/en.js'),
import('intl/locale-data/jsonp/de.js'),
]),
) // eslint-disable-line prettier/prettier
.then(() => render(translationMessages))
.catch(err => {
throw err;
});
} else {
render(translationMessages);
}
}

// @Pierre Burgy exporting dispatch for the notifications...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ import { compose } from 'redux';
import {
disableGlobalOverlayBlocker,
enableGlobalOverlayBlocker,
} from 'actions/overlayBlocker';
updatePlugin,
} from '../../App/actions';

import LoadingIndicatorPage from 'components/LoadingIndicatorPage';
import OverlayBlocker from 'components/OverlayBlocker';
import { LoadingIndicatorPage, OverlayBlocker } from 'strapi-helper-plugin';

import injectReducer from '../../../utils/injectReducer';
import history from '../../../utils/history';
import configureStore from '../../../configureStore';
import { messages } from '../../../i18n';
// import { store } from '../../../createStore';
import messages from 'testUtils/commonTrads.json';

import Header from '../../../components/Header/index';
import Onboarding from '../../Onboarding';
import Logout from '../../../components/Logout';

import { updatePlugin } from '../../App/actions';
import localeToggleReducer from '../../LocaleToggle/reducer';

import {
Expand Down
3 changes: 0 additions & 3 deletions packages/strapi-admin/admin/src/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ function App(props) {
);
}

// App.contextTypes = {
// store: PropTypes.object,
// };
App.propTypes = {};

export default App;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { shallow } from 'enzyme';
import { Route } from 'react-router-dom';

import AppLoader from '../../AppLoader';
import App from '../index';
import App from '../../App';

describe('<App />', () => {
it('should render the <AppLoader />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { fromJS, List } from 'immutable';
import {
disableGlobalOverlayBlocker,
enableGlobalOverlayBlocker,
} from 'actions/overlayBlocker';
import {
freezeApp,
getAppPluginsSucceeded,
pluginDeleted,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import BlockerComponent from 'components/BlockerComponent';
import { BlockerComponent } from 'strapi-helper-plugin';
import { PluginDispatcher } from '../index';

const BlockerComponent2 = () => <div>BlockerComponent</div>;
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('<PluginDispatcher />', () => {
expect(renderedComponent.find(BlockerComponent2)).toHaveLength(1);
});

it("Should return the plugin's mainComponent if all conditions are met", () => {
it('Should return the plugin\'s mainComponent if all conditions are met', () => {
const props = {
global: {
plugins: {
Expand Down
35 changes: 25 additions & 10 deletions packages/strapi-admin/admin/src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,36 @@ window.strapi = Object.assign(window.strapi || {}, {
injectSaga,
});

// module.exports = {
// documentation: require('../../../strapi-plugin-documentation/admin/dist/strapi-plugin-documentation.esm.js')
// .default,
// 'content-manager': require('../../../strapi-plugin-content-manager/admin/dist/strapi-plugin-content-manager.esm.js')
// .default,
// 'content-type-builder': require('../../../strapi-plugin-content-type-builder/admin/dist/strapi-plugin-content-type-builder.esm.js')
// .default,
// email: require('../../../strapi-plugin-email/admin/dist/strapi-plugin-email.esm.js')
// .default,
// 'users-permissions': require('../../../strapi-plugin-users-permissions/admin/dist/strapi-plugin-users-permissions.esm.js')
// .default,
// upload: require('../../../strapi-plugin-upload/admin/dist/strapi-plugin-upload.esm.js')
// .default,
// 'settings-manager':
// // 'settings-manager': require('../../../strapi-plugin-settings-manager/admin/src')
// require('../../../strapi-plugin-settings-manager/admin/dist/strapi-plugin-settings-manager.esm.js')
// .default,
// };
module.exports = {
documentation: require('../../../strapi-plugin-documentation/admin/dist/strapi-plugin-documentation.esm.js')
documentation: require('../../../strapi-plugin-documentation/admin/src')
.default,
'content-manager': require('../../../strapi-plugin-content-manager/admin/dist/strapi-plugin-content-manager.esm.js')
'content-manager': require('../../../strapi-plugin-content-manager/admin/src')
.default,
'content-type-builder': require('../../../strapi-plugin-content-type-builder/admin/dist/strapi-plugin-content-type-builder.esm.js')
'content-type-builder': require('../../../strapi-plugin-content-type-builder/admin/src')
.default,
email: require('../../../strapi-plugin-email/admin/dist/strapi-plugin-email.esm.js')
.default,
'users-permissions': require('../../../strapi-plugin-users-permissions/admin/dist/strapi-plugin-users-permissions.esm.js')
.default,
upload: require('../../../strapi-plugin-upload/admin/dist/strapi-plugin-upload.esm.js')
email: require('../../../strapi-plugin-email/admin/src').default,
'users-permissions': require('../../../strapi-plugin-users-permissions/admin/src')
.default,
upload: require('../../../strapi-plugin-upload/admin/src').default,
'settings-manager':
// 'settings-manager': require('../../../strapi-plugin-settings-manager/admin/src')
require('../../../strapi-plugin-settings-manager/admin/dist/strapi-plugin-settings-manager.esm.js')
.default,
require('../../../strapi-plugin-settings-manager/admin/src').default,
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
*
* BlockerComponent
*
*/
*
* BlockerComponent
*
*/

import React from 'react';
import { FormattedMessage } from 'react-intl';
Expand All @@ -12,8 +12,14 @@ import PropTypes from 'prop-types';
import styles from './styles.scss';

/* eslint-disable react/require-default-props */
function BlockerComponent({ blockerComponentTitle, blockerComponentDescription, blockerComponentIcon, blockerComponentContent = '' }) {
function BlockerComponent({
blockerComponentTitle,
blockerComponentDescription,
blockerComponentIcon,
blockerComponentContent = '',
}) {
let content;
console.log(blockerComponentContent);

switch (blockerComponentContent) {
case 'renderIde':
Expand Down Expand Up @@ -50,15 +56,15 @@ const renderIde = () => (
<div className={styles.ide}>
<p>./config/environments/development/server.json</p>
<div>
<pre style={{ whiteSpace: 'pre-wrap'}}>
<pre style={{ whiteSpace: 'pre-wrap' }}>
<code>
&#123;
<br />
&nbsp;"host": "localhost",
<br />
&nbsp;"port": 1337,
<br />
<span style={{ color: '#006EE7'}}>
<span style={{ color: '#006EE7' }}>
&nbsp;"autoReload": &#123; enabled: true &#125;
</span>
<br />
Expand All @@ -83,12 +89,25 @@ const renderIde = () => (

const renderButton = () => (
<div className={styles.buttonContainer}>
<a className={cn(styles.primary, 'btn')} href="http://strapi.io" target="_blank">Read the documentation</a>
<a
className={cn(styles.primary, 'btn')}
href="http://strapi.io"
target="_blank"
>
Read the documentation
</a>
</div>
);

BlockerComponent.defaultProps = {
blockerComponentContent: '',
blockerComponentDescription: 'app.utils.defaultMessage',
blockerComponentIcon: '',
blockerComponentTitle: 'app.utils.defaultMessage',
};

BlockerComponent.propTypes = {
blockerComponentContent: PropTypes.string.isRequired,
blockerComponentContent: PropTypes.string,
blockerComponentDescription: PropTypes.string.isRequired,
blockerComponentIcon: PropTypes.string.isRequired,
blockerComponentTitle: PropTypes.string.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi-plugin-content-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
"npm": ">= 6.0.0"
},
"license": "MIT"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { shallow } from 'enzyme';

import LiLink from 'components/LiLink';
import { LiLink } from 'strapi-helper-plugin';
import EditViewLink from '../EditViewLink';

describe('<EditViewLink />', () => {
Expand Down
Loading

0 comments on commit adf4e88

Please sign in to comment.