Skip to content

Commit

Permalink
[test] Smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 6, 2020
1 parent 983d7aa commit 4ada4a5
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 139 deletions.
118 changes: 0 additions & 118 deletions packages/grid/data-grid/src/DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,122 +181,4 @@ describe('<DataGrid />', () => {
);
});
});

describe('column width', () => {
before(function beforeHook() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
this.skip();
}
});

it('should set the columns width to 100px by default', () => {
const rows = [
{
id: 1,
username: 'John Doe',
age: 30,
},
];

const columns = [
{
field: 'id',
},
{
field: 'name',
},
{
field: 'age',
},
];

const { getAllByRole } = render(
<div style={{ width: 300, height: 300 }}>
<DataGrid columns={columns} rows={rows} />
</div>,
);

const DOMColumns = getAllByRole('columnheader');
DOMColumns.forEach((col) => {
// @ts-expect-error need to migrate helpers to TypeScript
expect(col).toHaveInlineStyle({ width: '100px' });
});
});

it('should set the columns width value to what is provided', () => {
const rows = [
{
id: 1,
username: 'John Doe',
age: 30,
},
];

const colWidthValues = [50, 50, 200];
const columns = [
{
field: 'id',
width: colWidthValues[0],
},
{
field: 'name',
width: colWidthValues[1],
},
{
field: 'age',
width: colWidthValues[2],
},
];

const { getAllByRole } = render(
<div style={{ width: 300, height: 300 }}>
<DataGrid columns={columns} rows={rows} />
</div>,
);

const DOMColumns = getAllByRole('columnheader');
DOMColumns.forEach((col, index) => {
// @ts-expect-error need to migrate helpers to TypeScript
expect(col).toHaveInlineStyle({ width: `${colWidthValues[index]}px` });
});
});

it('should set the first column to be twice as wide as the second one', () => {
const rows = [
{
id: 1,
username: 'John Doe',
age: 30,
},
];

const columns = [
{
field: 'id',
flex: 1,
},
{
field: 'name',
flex: 0.5,
},
];

render(
<div style={{ width: 200, height: 300 }}>
<DataGrid columns={columns} rows={rows} />
</div>,
);

const firstColumn = document.querySelector('[role="columnheader"][aria-colindex="1"]');
const secondColumn: HTMLElement | null = document.querySelector(
'[role="columnheader"][aria-colindex="2"]',
);
const secondColumnWidthVal = secondColumn!.style.width.split('px')[0];
// @ts-expect-error need to migrate helpers to TypeScript
expect(firstColumn).toHaveInlineStyle({
width: `${2 * parseInt(secondColumnWidthVal, 10)}px`,
});
});
});
});
9 changes: 9 additions & 0 deletions packages/grid/x-grid/src/XGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ describe('<XGrid />', () => {
container.firstChild.firstChild.firstChild,
);
});

it('should not fail after scheduled tasks are run', async () => {
render(
<div style={{ width: 300, height: 300 }}>
<XGrid {...defaultProps} />
</div>,
);
await sleep(0);
});
});

describe('keyboard', () => {
Expand Down
1 change: 1 addition & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = function setKarmaConfig(config) {
'process.env': {
NODE_ENV: JSON.stringify('test'),
CI: JSON.stringify(process.env.CI),
KARMA: JSON.stringify(true),
},
}),
],
Expand Down
52 changes: 50 additions & 2 deletions test/karma.tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
/* eslint-env mocha */
import './utils/init';
import consoleError from './utils/consoleError';
import { createMochaHooks } from '@material-ui/monorepo/test/utils/mochaHooks';

consoleError();
const mochaHooks = createMochaHooks(window.Mocha);

before(function beforeAllHook() {
mochaHooks.beforeAll.forEach((mochaHook) => {
mochaHook.call(this);
});
});

after(function afterAllHook() {
mochaHooks.afterAll.forEach((mochaHook) => {
mochaHook.call(this);
});
});

beforeEach(function beforeEachHook() {
mochaHooks.beforeEach.forEach((mochaHook) => {
mochaHook.call(this);
});
});

afterEach(function afterEachHook() {
mochaHooks.afterEach.forEach((mochaHook) => {
mochaHook.call(this);
});
});

// Ensure that uncaught exceptions between tests result in the tests failing.
// This works around an issue with mocha / karma-mocha, see
// https://github.com/karma-runner/karma-mocha/issues/227
let pendingError = null;
let pendingErrorNotice = null;

window.addEventListener('error', event => {
pendingError = event.error;
pendingErrorNotice = 'An uncaught exception was thrown between tests';
});

window.addEventListener('unhandledrejection', event => {
pendingError = event.reason;
pendingErrorNotice = 'An uncaught promise rejection occurred between tests';
});

afterEach(() => {
if (pendingError) {
console.error(pendingErrorNotice);
throw pendingError;
}
});

const packagesContext = require.context('../packages', true, /\.test\.tsx$/);
packagesContext.keys().forEach(packagesContext);
17 changes: 0 additions & 17 deletions test/utils/consoleError.js

This file was deleted.

4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2735,8 +2735,8 @@
resolved "https://github.com/mui-org/material-ui.git#3c078f2f6943976fc4d3ed5d886bbfa0f391e4a2"

"@material-ui/monorepo@https://github.com/mui-org/material-ui.git#next":
version "5.0.0-alpha.13"
resolved "https://github.com/mui-org/material-ui.git#13f3e9d8db81b40e1b08f43e4d45e37f3926c37d"
version "5.0.0-alpha.15"
resolved "https://github.com/mui-org/material-ui.git#c500fc3faf873142b9124319cebf728dd9a12cc5"

"@material-ui/styles@^4.10.0":
version "4.10.0"
Expand Down

0 comments on commit 4ada4a5

Please sign in to comment.