diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fbab4f1afb..4488f1eb09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -177,7 +177,6 @@ Here are the main files and folders of the project. ▸ components/ << The pReact components for the UI of our widgets (UI) ▸ connectors/ << The source of all the connectors (UX without UI) ▸ css/ << The source of the themes (reset / algolia theme) - ▸ decorators/ << Preact HoC that factorize some behaviour of the widgets ▸ lib/ << The core of the library, instantsearch, url ▸ widgets/ << The source of the widgets (UX + UI) ▸ helpers/ << The source of the method helpers diff --git a/src/decorators/__tests__/__snapshots__/autoHideContainer-test.js.snap b/src/decorators/__tests__/__snapshots__/autoHideContainer-test.js.snap deleted file mode 100644 index 5c80165103..0000000000 --- a/src/decorators/__tests__/__snapshots__/autoHideContainer-test.js.snap +++ /dev/null @@ -1,16 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`autoHideContainer should render autoHideContainer() 1`] = ` -
- -
-`; diff --git a/src/decorators/__tests__/__snapshots__/headerFooter-test.js.snap b/src/decorators/__tests__/__snapshots__/headerFooter-test.js.snap deleted file mode 100644 index c9d5b78383..0000000000 --- a/src/decorators/__tests__/__snapshots__/headerFooter-test.js.snap +++ /dev/null @@ -1,230 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`headerFooter collapsible when collapsed 1`] = ` -
- -
- -
- -
-`; - -exports[`headerFooter collapsible when true 1`] = ` -
- -
- -
- -
-`; - -exports[`headerFooter should add a footer if such a template is passed 1`] = ` -
-
- -
- -
-`; - -exports[`headerFooter should add a header if such a template is passed 1`] = ` -
- -
- -
-
-`; - -exports[`headerFooter should render the component in a root and body 1`] = ` -
-
- -
-
-`; diff --git a/src/decorators/__tests__/autoHideContainer-test.js b/src/decorators/__tests__/autoHideContainer-test.js deleted file mode 100644 index 90ffa8e1cd..0000000000 --- a/src/decorators/__tests__/autoHideContainer-test.js +++ /dev/null @@ -1,80 +0,0 @@ -import PropTypes from 'prop-types'; -import React, { Component } from 'react'; -import ReactDOM from 'react-dom'; -import { shallow } from 'enzyme'; -import autoHideContainer from '../autoHideContainer'; - -class TestComponent extends Component { - render() { - return
{this.props.hello}
; - } -} - -TestComponent.propTypes = { - hello: PropTypes.string, -}; - -describe('autoHideContainer', () => { - let props = {}; - - it('should render autoHideContainer()', () => { - props.hello = 'son'; - const AutoHide = autoHideContainer(TestComponent); - const out = shallow(); - expect(out).toMatchSnapshot(); - }); - - describe('props.shouldAutoHideContainer', () => { - let AutoHide; - let component; - let container; - let innerContainer; - - beforeEach(() => { - AutoHide = autoHideContainer(TestComponent); - container = document.createElement('div'); - props = { hello: 'mom', shouldAutoHideContainer: false }; - component = ReactDOM.render(, container); - }); - - it('creates a component', () => { - expect(component).toBeDefined(); - }); - - it('shows the container at first', () => { - expect(container.style.display).not.toEqual('none'); - }); - - describe('when set to true', () => { - beforeEach(() => { - jest.spyOn(component, 'render'); - props.shouldAutoHideContainer = true; - ReactDOM.render(, container); - innerContainer = container.firstElementChild; - }); - - it('hides the container', () => { - expect(innerContainer.style.display).toEqual('none'); - }); - - it('call component.render()', () => { - expect(component.render).toHaveBeenCalled(); - }); - - describe('when set back to false', () => { - beforeEach(() => { - props.shouldAutoHideContainer = false; - ReactDOM.render(, container); - }); - - it('shows the container', () => { - expect(innerContainer.style.display).not.toEqual('none'); - }); - - it('calls component.render()', () => { - expect(component.render).toHaveBeenCalledTimes(2); - }); - }); - }); - }); -}); diff --git a/src/decorators/__tests__/headerFooter-test.js b/src/decorators/__tests__/headerFooter-test.js deleted file mode 100644 index be3db8c15a..0000000000 --- a/src/decorators/__tests__/headerFooter-test.js +++ /dev/null @@ -1,122 +0,0 @@ -import React, { Component } from 'react'; -import { shallow } from 'enzyme'; -import { createRenderer } from 'react-test-renderer/shallow'; - -import headerFooter from '../headerFooter'; - -class TestComponent extends Component { - render() { - return
; - } -} - -describe('headerFooter', () => { - let renderer; - let defaultProps; - - function render(props = {}) { - const HeaderFooter = headerFooter(TestComponent); - renderer.render(); - return renderer.getRenderOutput(); - } - - function shallowRender(extraProps = {}) { - const props = { - templateProps: {}, - ...extraProps, - }; - const componentWrappedInHeaderFooter = headerFooter(TestComponent); - return shallow(React.createElement(componentWrappedInHeaderFooter, props)); - } - - beforeEach(() => { - defaultProps = { - cssClasses: { - root: 'root', - body: 'body', - }, - collapsible: false, - templateProps: {}, - }; - renderer = createRenderer(); - }); - - it('should render the component in a root and body', () => { - const out = render(defaultProps); - expect(out).toMatchSnapshot(); - }); - - it('should add a header if such a template is passed', () => { - // Given - defaultProps.templateProps.templates = { - header: 'HEADER', - }; - // When - const out = render(defaultProps); - // Then - expect(out).toMatchSnapshot(); - }); - - it('should add a footer if such a template is passed', () => { - // Given - defaultProps.templateProps.templates = { - footer: 'FOOTER', - }; - // When - const out = render(defaultProps); - // Then - expect(out).toMatchSnapshot(); - }); - - describe('collapsible', () => { - beforeEach(() => { - defaultProps.templateProps.templates = { - header: 'yo header', - footer: 'yo footer', - }; - }); - - it('when true', () => { - defaultProps.collapsible = true; - const out = render(defaultProps); - expect(out).toMatchSnapshot(); - }); - - it('when collapsed', () => { - defaultProps.collapsible = { collapsed: true }; - const out = render(defaultProps); - expect(out).toMatchSnapshot(); - }); - }); - - describe('headerFooterData', () => { - it('should call the header and footer template with the given data', () => { - // Given - const props = { - headerFooterData: { - header: { - foo: 'bar', - }, - footer: { - foo: 'baz', - }, - }, - templateProps: { - templates: { - header: 'header', - footer: 'footer', - }, - }, - }; - - // When - const actual = shallowRender(props); - const header = actual.find({ templateKey: 'header' }); - const footer = actual.find({ templateKey: 'footer' }); - - // Then - expect(header.props().data.foo).toEqual('bar'); - expect(footer.props().data.foo).toEqual('baz'); - }); - }); -}); diff --git a/src/decorators/autoHideContainer.js b/src/decorators/autoHideContainer.js deleted file mode 100644 index 6590f4b0d7..0000000000 --- a/src/decorators/autoHideContainer.js +++ /dev/null @@ -1,18 +0,0 @@ -import PropTypes from 'prop-types'; -import React, { Component } from 'preact-compat'; - -export default function(ComposedComponent) { - return class AutoHide extends Component { - static displayName = `${ComposedComponent.name}-AutoHide`; - static propTypes = { shouldAutoHideContainer: PropTypes.bool.isRequired }; - - render() { - const { shouldAutoHideContainer } = this.props; - return ( -
- -
- ); - } - }; -} diff --git a/src/decorators/headerFooter.js b/src/decorators/headerFooter.js deleted file mode 100644 index fc6ad94a47..0000000000 --- a/src/decorators/headerFooter.js +++ /dev/null @@ -1,113 +0,0 @@ -import PropTypes from 'prop-types'; -// Issue with eslint + high-order components like decorators -/* eslint react/prop-types: 0 */ - -import React, { Component } from 'preact-compat'; - -import cx from 'classnames'; -import getKey from 'lodash/get'; - -import Template from '../components/Template.js'; - -function headerFooter(ComposedComponent) { - class HeaderFooter extends Component { - constructor(props) { - super(props); - this.handleHeaderClick = this.handleHeaderClick.bind(this); - this.state = { - collapsed: props.collapsible && props.collapsible.collapsed, - }; - - this._cssClasses = { - root: cx('ais-root', this.props.cssClasses.root), - body: cx('ais-body', this.props.cssClasses.body), - }; - - this._footerElement = this._getElement({ type: 'footer' }); - } - _getElement({ type, handleClick = null }) { - const templates = - this.props.templateProps && this.props.templateProps.templates; - if (!templates || !templates[type]) { - return null; - } - const className = cx(this.props.cssClasses[type], `ais-${type}`); - - const templateData = getKey(this.props, `headerFooterData.${type}`); - - return ( -