Skip to content

Commit 588e22d

Browse files
nstepienamanmahajan7
authored andcommitted
Reorganize tests (adazzle#1878)
* Reorganize tests * consistent describe, merge column utils tests
1 parent f4e3804 commit 588e22d

37 files changed

+328
-340
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ module.exports = {
579579
}, {
580580
// TODO: remove
581581
files: [
582-
'src/**/__tests__/**/*'
582+
'*.test.*'
583583
],
584584
rules: {
585585
'sonarjs/no-identical-functions': 0

jest.config.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ module.exports = {
2121
],
2222
restoreMocks: true,
2323
moduleNameMapper: {
24-
'^@material-ui/icons$': '<rootDir>/test/iconsMock.ts'
24+
'^@material-ui/icons$': '<rootDir>/jest/iconsMock.ts'
2525
},
2626
setupFiles: [
27-
'<rootDir>/test/setupTests.ts'
27+
'<rootDir>/jest/setupTests.ts'
2828
],
2929
testMatch: [
30-
'<rootDir>/src/**/*.spec.(ts|tsx)',
31-
'<rootDir>/test/**/*.test.(ts|tsx)'
30+
'<rootDir>/src/**/*.test.*'
3231
]
3332
};
File renamed without changes.

test/setupTests.ts renamed to jest/setupTests.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ import enzyme from 'enzyme';
22
import Adapter from 'enzyme-adapter-react-16';
33

44
enzyme.configure({
5-
adapter: new Adapter(),
6-
disableLifecycleMethods: true
5+
adapter: new Adapter()
76
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"postbuild": "node tools/buildStylesheets.mjs",
3030
"test": "jest",
3131
"test:watch": "jest --watch",
32-
"eslint": "eslint --ext js,mjs,ts,tsx --max-warnings 0 -f codeframe --cache --color examples src test tools",
32+
"eslint": "eslint --ext js,mjs,ts,tsx --max-warnings 0 -f codeframe --cache --color examples src jest tools",
3333
"eslint:fix": "npm run eslint -- --fix",
3434
"typecheck": "tsc -p tsconfig.all.json",
3535
"prepublishOnly": "npm install && npm run build",

src/__tests__/Canvas.spec.tsx renamed to src/Canvas.test.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33

4-
import InteractionMasks from '../masks/InteractionMasks';
5-
import Canvas, { CanvasProps } from '../Canvas';
6-
import { CellNavigationMode } from '../common/enums';
7-
import { CalculatedColumn } from '../common/types';
8-
import RowComponent from '../Row';
9-
import { ValueFormatter } from '../formatters';
4+
import InteractionMasks from './masks/InteractionMasks';
5+
import Canvas, { CanvasProps } from './Canvas';
6+
import { CellNavigationMode } from './common/enums';
7+
import { CalculatedColumn } from './common/types';
8+
import RowComponent from './Row';
9+
import { ValueFormatter } from './formatters';
1010

1111
interface Row {
1212
id: number;
@@ -60,7 +60,7 @@ function renderComponent(extraProps?: Partial<CanvasProps<Row, 'id'>>) {
6060
return mount(<Canvas<Row, 'id'> {...testProps} {...extraProps} />);
6161
}
6262

63-
describe('Canvas Tests', () => {
63+
describe('Canvas', () => {
6464
it('Should render the InteractionMasks component', () => {
6565
const wrapper = renderComponent();
6666

src/__tests__/Cell.spec.tsx renamed to src/Cell.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { PropsWithChildren } from 'react';
22
import { mount } from 'enzyme';
33

4-
import Cell, { CellProps } from '../Cell';
5-
import helpers, { Row } from './GridPropHelpers';
6-
import { SimpleCellFormatter } from '../formatters';
7-
import { CalculatedColumn, FormatterProps } from '../common/types';
8-
import EventBus from '../EventBus';
4+
import Cell, { CellProps } from './Cell';
5+
import helpers, { Row } from './test/GridPropHelpers';
6+
import { SimpleCellFormatter } from './formatters';
7+
import { CalculatedColumn, FormatterProps } from './common/types';
8+
import EventBus from './EventBus';
99

1010
const defaultColumn: CalculatedColumn<Row> = {
1111
idx: 0,
@@ -33,7 +33,7 @@ const renderComponent = (extraProps?: PropsWithChildren<Partial<CellProps<Row>>>
3333
return mount(<Cell<Row> {...testProps} {...extraProps} />);
3434
};
3535

36-
describe('Cell Tests', () => {
36+
describe('Cell', () => {
3737
it('should render a SimpleCellFormatter with value', () => {
3838
const wrapper = renderComponent();
3939
const formatter = wrapper.find(SimpleCellFormatter);

test/DataGrid.test.ts renamed to src/DataGrid.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setup } from './utils';
1+
import { setup } from './test';
22

33
test('rendering <DataGrid /> should work', () => {
44
const { container } = setup();

src/__tests__/EventBus.spec.ts renamed to src/EventBus.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import EventBus from '../EventBus';
2-
import { EventTypes } from '../common/enums';
1+
import EventBus from './EventBus';
2+
import { EventTypes } from './common/enums';
33

44
describe('EventBus', () => {
55
it('should call registered event handlers when event is dispatched', () => {

src/__tests__/HeaderCell.spec.tsx renamed to src/HeaderCell.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33

4-
import HeaderCell, { HeaderCellProps } from '../HeaderCell';
5-
import { ValueFormatter } from '../formatters';
6-
import { CalculatedColumn } from '../common/types';
4+
import HeaderCell, { HeaderCellProps } from './HeaderCell';
5+
import { ValueFormatter } from './formatters';
6+
import { CalculatedColumn } from './common/types';
77

88
interface Row {
99
bla?: string;
1010
}
1111

12-
describe('Header Cell Tests', () => {
12+
describe('HeaderCell', () => {
1313
function DraggableHeaderCell() {
1414
return <div />;
1515
}

src/__tests__/HeaderRow.spec.tsx renamed to src/HeaderRow.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33

4-
import helpers, { Row } from './GridPropHelpers';
5-
import HeaderRow, { HeaderRowProps } from '../HeaderRow';
6-
import HeaderCell from '../HeaderCell';
7-
import { DEFINE_SORT } from '../common/enums';
4+
import helpers, { Row } from './test/GridPropHelpers';
5+
import HeaderRow, { HeaderRowProps } from './HeaderRow';
6+
import HeaderCell from './HeaderCell';
7+
import { DEFINE_SORT } from './common/enums';
88

9-
describe('Header Row Unit Tests', () => {
9+
describe('HeaderRow', () => {
1010
const defaultProps: HeaderRowProps<Row, 'id'> = {
1111
rowKey: 'id',
1212
rowsCount: 20,

src/__tests__/Row.spec.tsx renamed to src/Row.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import React from 'react';
33
import { shallow } from 'enzyme';
44

5-
import Row from '../Row';
6-
import Cell from '../Cell';
7-
import { createColumns } from './utils';
8-
import { IRowRendererProps } from '../common/types';
9-
import EventBus from '../EventBus';
5+
import Row from './Row';
6+
import Cell from './Cell';
7+
import { createColumns } from './test/utils';
8+
import { IRowRendererProps } from './common/types';
9+
import EventBus from './EventBus';
1010

1111
type RowType = any;
1212

src/editors/__tests__/EditorContainer.spec.tsx renamed to src/editors/EditorContainer.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { mount, MountRendererProps } from 'enzyme';
44

5-
import EditorContainer, { Props } from '../EditorContainer';
6-
import SimpleTextEditor from '../SimpleTextEditor';
7-
import { ValueFormatter } from '../../formatters';
8-
import { CalculatedColumn, EditorProps } from '../../common/types';
5+
import EditorContainer, { Props } from './EditorContainer';
6+
import SimpleTextEditor from './SimpleTextEditor';
7+
import { ValueFormatter } from '../formatters';
8+
import { CalculatedColumn, EditorProps } from '../common/types';
99

1010
interface Row {
1111
id: string;
@@ -71,7 +71,7 @@ const setup = (extraProps?: Partial<Props<Row, 'id'>>, opts?: MountRendererProps
7171
return { wrapper, props };
7272
};
7373

74-
describe('Editor Container Tests', () => {
74+
describe('EditorContainer', () => {
7575
describe('Basic render tests', () => {
7676
it('should select the text of the default input when the editor is rendered', () => {
7777
const { wrapper } = setup();

src/editors/__tests__/SimpleTextEditor.spec.tsx renamed to src/editors/SimpleTextEditor.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3-
import SimpleTextEditor from '../SimpleTextEditor';
4-
import { ValueFormatter } from '../../formatters';
5-
import { CalculatedColumn } from '../../common/types';
3+
import SimpleTextEditor from './SimpleTextEditor';
4+
import { ValueFormatter } from '../formatters';
5+
import { CalculatedColumn } from '../common/types';
66

77
interface Row { text: string }
88

src/headerCells/__tests__/SortableHeaderCell.spec.tsx renamed to src/headerCells/SortableHeaderCell.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
3-
import SortableHeaderCell, { Props } from '../SortableHeaderCell';
4-
import { DEFINE_SORT } from '../../common/enums';
5-
import { ValueFormatter } from '../../formatters';
3+
import SortableHeaderCell, { Props } from './SortableHeaderCell';
4+
import { DEFINE_SORT } from '../common/enums';
5+
import { ValueFormatter } from '../formatters';
66

77
interface Row { col1: string }
88

9-
describe('<SortableHeaderCell/>', () => {
9+
describe('SortableHeaderCell', () => {
1010
const setup = (overrideColumn = {}) => {
1111
const props: Props<Row> = {
1212
column: {

src/masks/__tests__/CellMask.spec.tsx renamed to src/masks/CellMask.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
33

4-
import { Z_INDEXES } from './../../common/enums';
5-
import { sel } from '../../__tests__/utils';
6-
import CellMask from '../CellMask';
4+
import { Z_INDEXES } from '../common/enums';
5+
import { sel } from '../test/utils';
6+
import CellMask from './CellMask';
77

88
describe('CellMask', () => {
99
const setup = (children?: JSX.Element) => {

src/masks/__tests__/DragHandle.spec.tsx renamed to src/masks/DragHandle.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
33

4-
import DragHandle from '../DragHandle';
4+
import DragHandle from './DragHandle';
55

66
describe('DragHandle', () => {
77
const setup = () => {

src/masks/__tests__/DragMask.spec.tsx renamed to src/masks/DragMask.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
33

4-
import { Position } from '../../common/types';
5-
import CellMask from '../CellMask';
6-
import DragMask, { DraggedPosition } from '../DragMask';
4+
import { Position } from '../common/types';
5+
import CellMask from './CellMask';
6+
import DragMask, { DraggedPosition } from './DragMask';
77

88
describe('DragMask', () => {
99
const setup = (draggedPosition: DraggedPosition) => {

src/masks/__tests__/InteractionMasks.spec.tsx renamed to src/masks/InteractionMasks.test.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import React from 'react';
22
import { mount } from 'enzyme';
33
import { act } from 'react-dom/test-utils';
44

5-
import InteractionMasks, { InteractionMasksProps, KeyCodes } from '../InteractionMasks';
6-
import SelectionMask from '../SelectionMask';
5+
import InteractionMasks, { InteractionMasksProps, KeyCodes } from './InteractionMasks';
6+
import SelectionMask from './SelectionMask';
77
// import SelectionRangeMask from '../SelectionRangeMask';
8-
import CopyMask from '../CopyMask';
9-
import DragMask from '../DragMask';
10-
import DragHandle from '../DragHandle';
11-
import EventBus from '../../EventBus';
12-
import EditorContainer from '../../editors/EditorContainer';
13-
import { createColumns } from '../../__tests__/utils';
14-
import { CellNavigationMode, EventTypes, UpdateActions } from '../../common/enums';
15-
import { Position } from '../../common/types';
8+
import CopyMask from './CopyMask';
9+
import DragMask from './DragMask';
10+
import DragHandle from './DragHandle';
11+
import EventBus from '../EventBus';
12+
import EditorContainer from '../editors/EditorContainer';
13+
import { createColumns } from '../test/utils';
14+
import { CellNavigationMode, EventTypes, UpdateActions } from '../common/enums';
15+
import { Position } from '../common/types';
1616

1717
const NUMBER_OF_COLUMNS = 10;
1818
const ROWS_COUNT = 5;
@@ -22,7 +22,7 @@ interface Row {
2222
[key: string]: React.ReactNode;
2323
}
2424

25-
describe('<InteractionMasks/>', () => {
25+
describe('InteractionMasks', () => {
2626
const rowGetter = () => ({ col1: 1 });
2727

2828
function setup(overrideProps?: Partial<InteractionMasksProps<Row, 'id'>>, initialPosition?: Position) {
File renamed without changes.

test/utils.tsx renamed to src/test/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { StrictMode } from 'react';
22
import { render } from '@testing-library/react';
3-
import DataGrid, { DataGridProps } from '../src';
3+
import DataGrid, { DataGridProps } from '../';
44

55
interface RowType {
66
id: number;

src/__tests__/utils/index.ts renamed to src/test/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ValueFormatter } from '../../formatters';
2-
import { CalculatedColumn } from '../../common/types';
1+
import { ValueFormatter } from '../formatters';
2+
import { CalculatedColumn } from '../common/types';
33

44
function createColumn(index: number): CalculatedColumn<{ [key: string]: React.ReactNode }> {
55
const key = `Column${index}`;

src/utils/__tests__/canvasUtils.spec.ts

-48
This file was deleted.

0 commit comments

Comments
 (0)