Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Upgrade material-ui to 4.2.1 #3457

Merged
merged 2 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.0.0-beta.2",
"@material-ui/icons": "^4.0.0-beta.0",
"@material-ui/core": "^4.2.1",
"@material-ui/icons": "^4.2.1",
"data-generator-retail": "^2.7.0",
"fakerest": "~2.1.0",
"fetch-mock": "~6.3.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
"@material-ui/core": "^4.0.0-beta.2",
"@material-ui/icons": "^4.0.0-beta.0",
"@material-ui/core": "^4.2.1",
"@material-ui/icons": "^4.2.1",
"ra-data-fakerest": "^3.0.0-alpha.0",
"ra-input-rich-text": "^3.0.0-alpha.0",
"ra-language-english": "^3.0.0-alpha.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.0.0-beta.2",
"@material-ui/core": "^4.2.1",
"ra-data-json-server": "^3.0.0-alpha.0",
"react": "~16.8.0",
"react-admin": "^3.0.0-alpha.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"/node_modules/",
"/lib/",
"/esm/",
"/examples/simple/"
"/examples/simplme/"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for resurrecting an old PR. I think this change may have not been intentional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I opened a PR to fix that #3498

],
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$"
Expand Down
12 changes: 6 additions & 6 deletions packages/ra-ui-materialui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"watch": "rimraf ./lib && tsc --watch"
},
"devDependencies": {
"@material-ui/core": "^4.0.0-beta.2",
"@material-ui/icons": "^4.0.0-beta.0",
"@material-ui/styles": "^4.0.0-beta.2",
"@material-ui/core": "^4.2.1",
"@material-ui/icons": "^4.2.1",
"@material-ui/styles": "^4.2.1",
"cross-env": "^5.2.0",
"enzyme": "~3.9.0",
"enzyme-adapter-react-16": "~1.12.1",
Expand All @@ -45,9 +45,9 @@
"react-dom": "^16.8.0"
},
"dependencies": {
"@material-ui/core": "^4.0.0-beta.2",
"@material-ui/icons": "^4.0.0-beta.0",
"@material-ui/styles": "^4.0.0-beta.2",
"@material-ui/core": "^4.2.1",
"@material-ui/icons": "^4.2.1",
"@material-ui/styles": "^4.2.1",
"autosuggest-highlight": "^3.1.1",
"classnames": "~2.2.5",
"connected-react-router": "^6.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/auth/Logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const useStyles = makeStyles((theme: Theme) => ({
* Used for the Logout Menu item in the sidebar
*/
const LogoutWithRef: FunctionComponent<
Props & MenuItemProps
Props & MenuItemProps<'li', { button: true }> // HACK: https://github.com/mui-org/material-ui/issues/16245
> = React.forwardRef(function Logout(props, ref) {
const { className, redirectTo, ...rest } = props;
const classes = useStyles();
Expand Down
65 changes: 33 additions & 32 deletions packages/ra-ui-materialui/src/form/SimpleForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
import assert from 'assert';
import { shallow } from 'enzyme';
import { render, cleanup } from 'react-testing-library';
import React from 'react';
import { renderWithRedux } from 'ra-core';

import { SimpleForm } from './SimpleForm';
import SimpleForm, { SimpleForm as SimpleFormView } from './SimpleForm';
import TextInput from '../input/TextInput';

describe('<SimpleForm />', () => {
afterEach(cleanup);

it('should embed a form with given component children', () => {
const wrapper = shallow(
const { queryByLabelText } = renderWithRedux(
<SimpleForm>
<TextInput source="name" />
<TextInput source="city" />
</SimpleForm>
);
const inputs = wrapper.find('WithStyles(FormInput)');
assert.deepEqual(inputs.map(i => i.prop('input').props.source), [
'name',
'city',
]);

expect(queryByLabelText('Name')).not.toBeNull();
expect(queryByLabelText('City')).not.toBeNull();
});

it('should display <Toolbar />', () => {
const wrapper = shallow(
<SimpleForm>
<TextInput source="name" />
</SimpleForm>
);
const button = wrapper.find(
'WithTheme(WithWidth(WithStyles(Toolbar)))'
const Toolbar = () => <p>TOOLBAR</p>;

const { queryByText } = render(
<SimpleFormView toolbar={<Toolbar />} />
);
assert.equal(button.length, 1);
expect(queryByText('TOOLBAR')).not.toBeNull();
});

it('should pass submitOnEnter to <Toolbar />', () => {
const handleSubmit = () => {};
const wrapper1 = shallow(
<SimpleForm submitOnEnter={false} handleSubmit={handleSubmit}>
<TextInput source="name" />
</SimpleForm>
);
const button1 = wrapper1.find(
'WithTheme(WithWidth(WithStyles(Toolbar)))'
const Toolbar = ({ submitOnEnter }) => (
<p>submitOnEnter: {submitOnEnter.toString()}</p>
);
assert.equal(button1.prop('submitOnEnter'), false);

const wrapper2 = shallow(
<SimpleForm submitOnEnter={true} handleSubmit={handleSubmit}>
<TextInput source="name" />
</SimpleForm>
const { queryByText, rerender } = render(
<SimpleFormView
submitOnEnter={false}
handleSubmit={handleSubmit}
toolbar={<Toolbar />}
/>
);
const button2 = wrapper2.find(
'WithTheme(WithWidth(WithStyles(Toolbar)))'

expect(queryByText('submitOnEnter: false')).not.toBeNull();

rerender(
<SimpleFormView
submitOnEnter
handleSubmit={handleSubmit}
toolbar={<Toolbar />}
/>
);
assert.equal(button2.prop('submitOnEnter'), true);

expect(queryByText('submitOnEnter: true')).not.toBeNull();
});
});
64 changes: 32 additions & 32 deletions packages/ra-ui-materialui/src/form/TabbedForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import assert from 'assert';
import { shallow } from 'enzyme';
import { render, cleanup } from 'react-testing-library';
import React, { createElement } from 'react';
import { MemoryRouter } from 'react-router';

import { TabbedForm, findTabsWithErrors } from './TabbedForm';
import FormTab from './FormTab';

const translate = label => label;
const muiTheme = { textField: { errorColor: 'red' } };

describe('<TabbedForm />', () => {
it('should display <Toolbar />', () => {
const wrapper = shallow(
<TabbedForm
location={{}}
match={{}}
translate={translate}
muiTheme={muiTheme}
tabsWithErrors={[]}
>
<FormTab />
<FormTab />
</TabbedForm>
);
afterEach(cleanup);

const toolbar = wrapper.find(
'WithTheme(WithWidth(WithStyles(Toolbar)))'
it('should display the tabs', () => {
const { queryAllByRole } = render(
<MemoryRouter initialEntries={['/']}>
<TabbedForm
location={{}}
match={{}}
translate={translate}
tabsWithErrors={[]}
>
<FormTab label="tab1" />
<FormTab label="tab2" />
</TabbedForm>
</MemoryRouter>
);
assert.equal(toolbar.length, 1);

const tabs = queryAllByRole('tab');
expect(tabs.length).toEqual(2);
});

it('should pass submitOnEnter to <Toolbar />', () => {
const handleSubmit = () => {};
const wrapper1 = shallow(
const Toolbar = ({ submitOnEnter }) => (
<p>submitOnEnter: {submitOnEnter.toString()}</p>
);

const { queryByText, rerender } = render(
<TabbedForm
location={{}}
match={{}}
translate={translate}
submitOnEnter={false}
handleSubmit={handleSubmit}
muiTheme={muiTheme}
tabsWithErrors={[]}
toolbar={<Toolbar />}
/>
);
const button1 = wrapper1.find(
'WithTheme(WithWidth(WithStyles(Toolbar)))'
);
assert.equal(button1.prop('submitOnEnter'), false);

const wrapper2 = shallow(
expect(queryByText('submitOnEnter: false')).not.toBeNull();

rerender(
<TabbedForm
location={{}}
match={{}}
translate={translate}
submitOnEnter
handleSubmit={handleSubmit}
muiTheme={muiTheme}
tabsWithErrors={[]}
toolbar={<Toolbar />}
/>
);
const button2 = wrapper2.find(
'WithTheme(WithWidth(WithStyles(Toolbar)))'
);
assert.strictEqual(button2.prop('submitOnEnter'), true);

expect(queryByText('submitOnEnter: true')).not.toBeNull();
});

describe('findTabsWithErrors', () => {
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('<TabbedForm />', () => {
};

const tabs = findTabsWithErrors(state, props, collectErrors);
assert.deepEqual(tabs, ['tab1', 'tab3']);
expect(tabs).toEqual(['tab1', 'tab3']);
});
});
});
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/layout/Responsive.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ Responsive.propTypes = {
width: PropTypes.string,
};

export default withWidth()(Responsive);
export default withWidth({ initialWidth: 'xs' })(Responsive);
5 changes: 3 additions & 2 deletions packages/ra-ui-materialui/src/list/FilterButton.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ describe('<FilterButton />', () => {
const hiddenFilter = (
<TextInput source="Returned" label="Returned" />
);
const { queryByText } = render(
const { getByLabelText, queryByText } = render(
<FilterButton
{...defaultProps}
filters={defaultProps.filters.concat(hiddenFilter)}
/>
);
fireEvent.click(queryByText('ra.action.add_filter'));

fireEvent.click(getByLabelText('ra.action.add_filter'));

expect(queryByText('Returned')).not.toBeNull();
expect(queryByText('Name')).toBeNull();
Expand Down
22 changes: 13 additions & 9 deletions packages/ra-ui-materialui/src/list/List.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { cleanup } from 'react-testing-library';
import { renderWithRedux } from 'ra-core';

import List, { ListView } from './List';
import { MemoryRouter } from 'react-router';

describe('<List />', () => {
afterEach(cleanup);
Expand Down Expand Up @@ -40,17 +41,20 @@ describe('<List />', () => {
const Filters = () => <div>filters</div>;
const Pagination = () => <div>pagination</div>;
const Datagrid = () => <div>datagrid</div>;
const { queryAllByText } = renderWithRedux(
<ListView
filters={<Filters />}
pagination={<Pagination />}
{...defaultProps}
>
<Datagrid />
</ListView>
const { queryAllByText, queryAllByLabelText } = renderWithRedux(
<MemoryRouter initialEntries={['/']}>
<ListView
filters={<Filters />}
pagination={<Pagination />}
{...defaultProps}
hasCreate
>
<Datagrid />
</ListView>
</MemoryRouter>
);
expect(queryAllByText('filters')).toHaveLength(2);
expect(queryAllByText('Export')).toHaveLength(1);
expect(queryAllByLabelText('Export')).toHaveLength(1);
expect(queryAllByText('pagination')).toHaveLength(1);
expect(queryAllByText('datagrid')).toHaveLength(1);
});
Expand Down
1 change: 1 addition & 0 deletions packages/ra-ui-materialui/src/list/Pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Pagination } from './Pagination';

describe('<Pagination />', () => {
const defaultProps = {
width: 'lg',
perPage: 10,
translate: x => x,
};
Expand Down
Loading