Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Aug 27, 2020
1 parent 0e1507e commit c020fad
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 58 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/enzyme": "^3.10.5",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^25.1.2",
"@types/mocha": "^8.0.3",
"@types/node": "^12.0.0",
"@types/react": "^16.9.25",
"@types/react-dom": "^16.9.5",
Expand Down
17 changes: 9 additions & 8 deletions packages/grid/data-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"publishConfig": {
"access": "public"
},
"scripts": {
"precommit": "npm run lint",
"build": "rollup -c ",
"start": "rollup -cw",
"lint": "eslint 'src/**/*.{ts,tsx}' --quiet --fix -c ../../../.eslintrc.js && npm run lint:css",
"lint:css": "stylelint 'src/**/*.{ts,tsx}' ../../../.stylelintrc.js",
"test": "../../../node_modules/.bin/jest --config jest.config.js",
"typescript": "tsc -p tsconfig.json"
},
"dependencies": {
"prop-types": "^15.7.2",
"tslib": "^2.0.0"
Expand All @@ -33,14 +42,6 @@
"react": "^16.8.0",
"styled-components": "^5.1.0"
},
"scripts": {
"precommit": "npm run lint",
"build": "rollup -c ",
"start": "rollup -cw",
"lint": "eslint 'src/**/*.{ts,tsx}' --quiet --fix -c ../../../.eslintrc.js && npm run lint:css",
"lint:css": "stylelint 'src/**/*.{ts,tsx}' ../../../.stylelintrc.js",
"test": "../../../node_modules/.bin/jest --config jest.config.js"
},
"setupFiles": [
"<rootDir>/src/setupTests.js"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/data-grid/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default [
cleaner({
targets: ['./dist/'],
}),
typescript({ build: true }),
typescript({ tsconfig: 'tsconfig.build.json' }),
!production && sourceMaps(),
production && terser(),
],
Expand Down
13 changes: 13 additions & 0 deletions packages/grid/data-grid/src/DataGrid.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import { DataGrid } from '@material-ui/data-grid';

function EnterpriseTest() {
return (
<div>
<DataGrid rows={[]} columns={[]} />
<DataGrid rows={[]} columns={[]} pagination />
{/* @ts-expect-error Type 'false' is not assignable to type 'true | undefined' */}
<DataGrid pagination={false} />
</div>
);
}
87 changes: 56 additions & 31 deletions packages/grid/data-grid/src/DataGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable react/forbid-foreign-prop-types */
import * as React from 'react';
import PropTypes from 'prop-types';
// @ts-ignore
import { createClientRender } from 'test/utils';
import { expect } from 'chai';
import { DataGrid } from '@material-ui/data-grid';
Expand All @@ -19,42 +22,64 @@ describe('<DataGrid />', () => {
],
};

before(function beforeHook() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
this.skip();
}
});

// Adapation of describeConformance()
describe('Material-UI component API', () => {
it(`attaches the ref`, () => {
const ref = React.createRef();
const { container } = render(
<div style={{ width: 300, height: 300 }}>
<DataGrid {...defaultProps} ref={ref} />
</div>,
);
expect(ref.current).to.be.instanceof(window.HTMLDivElement);
expect(ref.current).to.equal(container.firstChild.firstChild.firstChild);
describe('layout', () => {
before(function beforeHook() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
this.skip();
}
});

function randomStringValue() {
return `r${Math.random().toString(36).slice(2)}`;
}
// Adapation of describeConformance()
describe('Material-UI component API', () => {
it(`attaches the ref`, () => {
const ref = React.createRef<HTMLDivElement>();
const { container } = render(
<div style={{ width: 300, height: 300 }}>
<DataGrid {...defaultProps} ref={ref} />
</div>,
);
expect(ref.current).to.be.instanceof(window.HTMLDivElement);
expect(ref.current).to.equal(container.firstChild.firstChild.firstChild);
});

function randomStringValue() {
return `r${Math.random().toString(36).slice(2)}`;
}

it('applies the className to the root component', () => {
const className = randomStringValue();

it('applies the className to the root component', () => {
const className = randomStringValue();
const { container } = render(
<div style={{ width: 300, height: 300 }}>
<DataGrid {...defaultProps} className={className} />
</div>,
);

const { container } = render(
<div style={{ width: 300, height: 300 }}>
<DataGrid {...defaultProps} className={className} />
</div>,
);
expect(document.querySelector(`.${className}`)).to.equal(
container.firstChild.firstChild.firstChild,
);
});
});
});

describe('warnings', () => {
before(() => {
PropTypes.resetWarningCache();
});

expect(document.querySelector(`.${className}`)).to.equal(
container.firstChild.firstChild.firstChild,
);
it('should raise a warning if trying to use an enterprise feature', () => {
expect(() => {
PropTypes.checkPropTypes(
// @ts-ignore
DataGrid.Naked.propTypes,
{
pagination: false,
},
'prop',
'MockedDataGrid',
);
}).toErrorDev('Material-UI: `<DataGrid pagination={false} />` is not a valid prop.');
});
});
});
3 changes: 3 additions & 0 deletions packages/grid/data-grid/src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ DataGrid2.propTypes = {
};

export const DataGrid = React.memo(DataGrid2);

// @ts-ignore
DataGrid.Naked = DataGrid2;
22 changes: 22 additions & 0 deletions packages/grid/data-grid/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"declaration": true,
"declarationDir": "./dist",
"module": "es6",
"noImplicitAny": false,
"strict": true,
"outDir": "./dist",
"target": "es6",
"sourceMap": true,
"build": true
},
"include": ["src"],
"exclude": ["__tests__", "**/*.test.ts", "node_modules", "lib"],
"references": [
{
"path": "../x-grid-modules"
}
]
}
20 changes: 3 additions & 17 deletions packages/grid/data-grid/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"declaration": true,
"declarationDir": "./dist",
"module": "es6",
"noImplicitAny": false,
"strict": true,
"outDir": "./dist",
"target": "es6",
"sourceMap": true,
"build": true
"noEmit": true,
"types": ["mocha", "node"]
},
"include": ["src"],
"exclude": ["__tests__", "**/*.test.ts", "node_modules", "lib"],
"references": [
{
"path": "../x-grid-modules"
}
]
"include": ["src"]
}
2 changes: 1 addition & 1 deletion packages/grid/x-grid/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default [
cleaner({
targets: ['./dist/'],
}),
typescript({ build: true }),
typescript(),
!production && sourceMaps(),
production && terser(),
],
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,11 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/mocha@^8.0.3":
version "8.0.3"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.0.3.tgz#51b21b6acb6d1b923bbdc7725c38f9f455166402"
integrity sha512-vyxR57nv8NfcU0GZu8EUXZLTbCMupIUwy95LJ6lllN+JRPG25CwMHoB1q5xKh8YKhQnHYRAn4yW2yuHbf/5xgg==

"@types/node-fetch@^2.5.4":
version "2.5.7"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
Expand Down

0 comments on commit c020fad

Please sign in to comment.