Update generators to the new architecture

This commit is contained in:
soupette 2019-04-02 13:30:35 +02:00
parent 67099a676a
commit 0cd5473675
4 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,27 @@
/**
*
* Initializer
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import pluginId from '../../pluginId';
class Initializer extends React.PureComponent {
// eslint-disable-line react/prefer-stateless-function
componentDidMount() {
// Emit the event 'pluginReady'
this.props.updatePlugin(pluginId, 'isReady', true);
}
render() {
return null;
}
}
Initializer.propTypes = {
updatePlugin: PropTypes.func.isRequired,
};
export default Initializer;

View File

@ -0,0 +1,21 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import Initializer from '../index';
describe('<Initializer />', () => {
it('Should not crash', () => {
const updatePlugin = jest.fn();
const renderedComponent = shallow(<Initializer updatePlugin={updatePlugin} />);
expect(renderedComponent.children()).toHaveLength(0);
});
it('should call the updatePlugin props when mounted', () => {
const updatePlugin = jest.fn();
const wrapper = mount(<Initializer updatePlugin={updatePlugin} />);
expect(wrapper.prop('updatePlugin')).toHaveBeenCalledWith('upload', 'isReady', true);
});
});

View File

@ -0,0 +1,23 @@
/*
*
* SET THE HOOKS TO ENABLE THE MAGIC OF STRAPI.
* -------------------------------------------
*
* Secure, customise and enhance your project by setting
* the hooks via this file.
*
*/
module.exports = function lifecycles() {
// Set hooks for the AdminPage container.
// Note: we don't need to specify the first argument because we already know what "willSecure" refers to.
this.setHooks({
didGetSecuredData: () => console.log('do something'),
});
// Set hooks for the App container of the Content Manager.
// Note: we have to specify the first argument to select a specific container which is located in a plugin, or not.
// this.setHooks('content-manager.App', {
// willSomething: () => { console.log("Do Something"); }
// });
};