Fix tests that wasn't working with the router import

This commit is contained in:
soupette 2019-03-09 11:06:43 +01:00
parent bac6dad0a6
commit f344e33341
12 changed files with 47 additions and 14 deletions

View File

@ -55,4 +55,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -1,6 +1,24 @@
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
const propTypes = (params) => ({ const propTypes = (params = {}) => ({
history: PropTypes.shape({
action: PropTypes.string,
block: PropTypes.func,
createHref: PropTypes.func,
go: PropTypes.func,
goBack: PropTypes.func,
goForward: PropTypes.func,
length: PropTypes.number,
listen: PropTypes.func,
location: PropTypes.shape({
pathname: PropTypes.string,
search: PropTypes.string,
hash: PropTypes.string,
key: PropTypes.string,
}),
push: PropTypes.func,
replace: PropTypes.func,
}).isRequired,
match: PropTypes.shape({ match: PropTypes.shape({
isExact: PropTypes.bool, isExact: PropTypes.bool,
params: PropTypes.shape(params), params: PropTypes.shape(params),

View File

@ -52,4 +52,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -15,6 +15,8 @@ import styles from './styles.scss';
class TableList extends React.Component { // eslint-disable-line react/prefer-stateless-function class TableList extends React.Component { // eslint-disable-line react/prefer-stateless-function
render() { render() {
const { push } = this.props;
return ( return (
<div className={styles.tableListContainer}> <div className={styles.tableListContainer}>
<div className="container-fluid"> <div className="container-fluid">
@ -49,6 +51,7 @@ class TableList extends React.Component { // eslint-disable-line react/prefer-st
<TableListRow <TableListRow
key={key} key={key}
onDelete={this.props.onHandleDelete} onDelete={this.props.onHandleDelete}
push={push}
rowItem={rowItem} rowItem={rowItem}
/> />
))} ))}
@ -66,6 +69,7 @@ TableList.propTypes = {
buttonLabel: PropTypes.string.isRequired, buttonLabel: PropTypes.string.isRequired,
onButtonClick: PropTypes.func.isRequired, onButtonClick: PropTypes.func.isRequired,
onHandleDelete: PropTypes.func.isRequired, onHandleDelete: PropTypes.func.isRequired,
push: PropTypes.func.isRequired,
rowItems: PropTypes.array.isRequired, rowItems: PropTypes.array.isRequired,
title: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
}; };

View File

@ -11,7 +11,6 @@ import { FormattedMessage } from 'react-intl';
import IcoContainer from 'components/IcoContainer'; import IcoContainer from 'components/IcoContainer';
import ListRow from 'components/ListRow'; import ListRow from 'components/ListRow';
import PopUpWarning from 'components/PopUpWarning'; import PopUpWarning from 'components/PopUpWarning';
import { router } from 'app';
import styles from '../TableList/styles.scss'; import styles from '../TableList/styles.scss';
/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable react/jsx-curly-brace-presence */ /* eslint-disable react/jsx-curly-brace-presence */
@ -26,7 +25,8 @@ class TableListRow extends React.Component {
} }
handleEdit = () => { handleEdit = () => {
router.push( const { push } = this.props;
push(
`/plugins/content-type-builder/#edit${this.props.rowItem.name}::contentType::baseSettings`, `/plugins/content-type-builder/#edit${this.props.rowItem.name}::contentType::baseSettings`,
); );
}; };
@ -39,7 +39,8 @@ class TableListRow extends React.Component {
}; };
handleGoTo = () => { handleGoTo = () => {
router.push( const { push } = this.props;
push(
`/plugins/content-type-builder/models/${this.props.rowItem.name}${ `/plugins/content-type-builder/models/${this.props.rowItem.name}${
this.props.rowItem.source ? `&source=${this.props.rowItem.source}` : '' this.props.rowItem.source ? `&source=${this.props.rowItem.source}` : ''
}`, }`,
@ -109,6 +110,7 @@ class TableListRow extends React.Component {
TableListRow.propTypes = { TableListRow.propTypes = {
onDelete: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired,
push: PropTypes.func.isRequired,
rowItem: PropTypes.object.isRequired, rowItem: PropTypes.object.isRequired,
}; };

View File

@ -11,6 +11,9 @@ import { createStructuredSelector } from 'reselect';
import { bindActionCreators, compose } from 'redux'; import { bindActionCreators, compose } from 'redux';
import PluginHeader from 'components/PluginHeader'; import PluginHeader from 'components/PluginHeader';
import { routerPropTypes } from 'commonPropTypes';
import EmptyContentTypeView from '../../components/EmptyContentTypeView'; import EmptyContentTypeView from '../../components/EmptyContentTypeView';
import TableList from '../../components/TableList'; import TableList from '../../components/TableList';
@ -24,13 +27,17 @@ import saga from './saga';
export class HomePage extends React.Component { // eslint-disable-line react/prefer-stateless-function export class HomePage extends React.Component { // eslint-disable-line react/prefer-stateless-function
handleDeleteModel = (modelName) => { handleDeleteModel = (modelName) => {
this.props.deleteModel(modelName); this.props.deleteModel(modelName);
} }
render() { render() {
const { models } = this.props; const {
history: {
push,
},
models,
} = this.props;
const availableNumber = models.length; const availableNumber = models.length;
const title = availableNumber > 1 ? `${pluginId}.table.contentType.title.plural` const title = availableNumber > 1 ? `${pluginId}.table.contentType.title.plural`
: `${pluginId}.table.contentType.title.singular`; : `${pluginId}.table.contentType.title.singular`;
@ -45,6 +52,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre
onButtonClick={() => {}} onButtonClick={() => {}}
onHandleDelete={this.handleDeleteModel} onHandleDelete={this.handleDeleteModel}
rowItems={this.props.models} rowItems={this.props.models}
push={push}
/> />
); );
@ -69,6 +77,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre
} }
HomePage.propTypes = { HomePage.propTypes = {
...routerPropTypes().history,
deleteModel: PropTypes.func.isRequired, deleteModel: PropTypes.func.isRequired,
models: PropTypes.array.isRequired, models: PropTypes.array.isRequired,
}; };

View File

@ -51,4 +51,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -50,4 +50,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -54,4 +54,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -53,4 +53,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -46,4 +46,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

View File

@ -56,4 +56,4 @@
"npm": ">= 6.0.0" "npm": ">= 6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }