Skip to content

Commit f288a60

Browse files
committed
Jest refactoring
1 parent 92b4457 commit f288a60

File tree

14 files changed

+155
-234
lines changed

14 files changed

+155
-234
lines changed

packages/devextreme/js/__internal/grids/new/grid_core/columns_controller/columns_controller.test.ts

+10-21
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
/* eslint-disable spellcheck/spell-checker */
22
import { describe, expect, it } from '@jest/globals';
3-
import { SearchController } from '@ts/grids/new/grid_core/search';
43

5-
import { DataController } from '../data_controller/data_controller';
6-
import { FilterController } from '../filtering';
4+
import { DataController } from '../data_controller';
75
import { ItemsController } from '../items_controller/items_controller';
86
import type { Options } from '../options';
9-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
10-
import { SortingController } from '../sorting_controller';
7+
import { OptionsController } from '../options_controller/options_controller';
8+
import type { OptionsControllerMock } from '../options_controller/options_controller.mock';
9+
import { getContext } from '../test_utils';
1110
import { ColumnsController } from './columns_controller';
1211

1312
const setup = (config: Options = {}) => {
14-
const options = new OptionsControllerMock(config);
15-
const filterController = new FilterController(options);
16-
const columnsController = new ColumnsController(options);
17-
const sortingController = new SortingController(options, columnsController);
18-
const searchController = new SearchController(options, columnsController);
19-
const dataController = new DataController(
20-
options,
21-
sortingController,
22-
filterController,
23-
searchController,
24-
);
25-
const itemsController = new ItemsController(
26-
dataController,
27-
columnsController,
28-
searchController,
29-
);
13+
const context = getContext(config);
14+
15+
const dataController = context.get(DataController);
16+
const options = context.get(OptionsController) as OptionsControllerMock;
17+
const columnsController = context.get(ColumnsController);
18+
const itemsController = context.get(ItemsController);
3019

3120
return {
3221
options,

packages/devextreme/js/__internal/grids/new/grid_core/columns_controller/options.test.ts

+5-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
/* eslint-disable spellcheck/spell-checker */
22
import { describe, expect, it } from '@jest/globals';
3-
import { SearchController } from '@ts/grids/new/grid_core/search';
43

5-
import { DataController } from '../data_controller';
6-
import { FilterController } from '../filtering';
74
import { ItemsController } from '../items_controller/items_controller';
85
import type { Options } from '../options';
9-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
10-
import { SortingController } from '../sorting_controller';
6+
import { getContext } from '../test_utils';
117
import { ColumnsController } from './columns_controller';
128

139
const setup = (config: Options) => {
14-
const options = new OptionsControllerMock(config);
15-
16-
const columnsController = new ColumnsController(options);
17-
const filterController = new FilterController(options);
18-
const sortingController = new SortingController(options, columnsController);
19-
const searchController = new SearchController(options, columnsController);
20-
const dataController = new DataController(
21-
options,
22-
sortingController,
23-
filterController,
24-
searchController,
25-
);
26-
const itemsController = new ItemsController(
27-
dataController,
28-
columnsController,
29-
searchController,
30-
);
10+
const context = getContext(config);
11+
12+
const columnsController = context.get(ColumnsController);
13+
const itemsController = context.get(ItemsController);
3114

3215
return {
33-
options,
34-
dataController,
3516
columnsController,
3617
itemsController,
3718
};

packages/devextreme/js/__internal/grids/new/grid_core/columns_controller/public_methods.test.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
11
import { describe, expect, it } from '@jest/globals';
22

3-
import { DataController } from '../data_controller';
4-
import { FilterController } from '../filtering';
5-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
6-
import { SearchController } from '../search';
7-
import { SortingController } from '../sorting_controller';
3+
import { getContext } from '../test_utils';
84
import { ColumnsController } from './columns_controller';
95
import type { Options } from './options';
106
import { PublicMethods } from './public_methods';
117

128
const setup = (config: Options = {}) => {
13-
const options = new OptionsControllerMock(config);
14-
const filterController = new FilterController(options);
15-
const columnsController = new ColumnsController(options);
16-
const searchController = new SearchController(options, columnsController);
17-
const sortingController = new SortingController(options, columnsController);
18-
const dataController = new DataController(
19-
options,
20-
sortingController,
21-
filterController,
22-
searchController,
23-
);
9+
const context = getContext(config);
10+
11+
const columnsController = context.get(ColumnsController);
2412

2513
// @ts-expect-error
2614
const gridCore = new (PublicMethods(class {
2715
protected columnsController = columnsController;
2816
}))();
2917

3018
return {
31-
options,
32-
dataController,
33-
columnsController,
3419
gridCore,
3520
};
3621
};

packages/devextreme/js/__internal/grids/new/grid_core/data_controller/options.test.ts

+13-22
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import DataSource from '@js/data/data_source';
99
import { logger } from '@ts/core/utils/m_console';
1010
import ArrayStore from '@ts/data/m_array_store';
1111

12-
import { ColumnsController } from '../columns_controller';
13-
import { FilterController } from '../filtering';
1412
import type { Options } from '../options';
15-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
16-
import { SearchController } from '../search/controller';
17-
import { SortingController } from '../sorting_controller';
13+
import { OptionsController } from '../options_controller/options_controller';
14+
import type { OptionsControllerMock } from '../options_controller/options_controller.mock';
15+
import { getContext } from '../test_utils';
1816
import { DataController } from './data_controller';
1917

2018
beforeAll(() => {
@@ -24,21 +22,14 @@ afterAll(() => {
2422
jest.restoreAllMocks();
2523
});
2624

27-
const setup = (options: Options) => {
28-
const optionsController = new OptionsControllerMock(options);
29-
const filterController = new FilterController(optionsController);
30-
const columnsController = new ColumnsController(optionsController);
31-
const sortingController = new SortingController(optionsController, columnsController);
32-
const searchController = new SearchController(optionsController, columnsController);
33-
const dataController = new DataController(
34-
optionsController,
35-
sortingController,
36-
filterController,
37-
searchController,
38-
);
25+
const setup = (config: Options) => {
26+
const context = getContext(config);
27+
28+
const dataController = context.get(DataController);
29+
const options = context.get(OptionsController) as OptionsControllerMock;
3930

4031
return {
41-
optionsController,
32+
options,
4233
dataController,
4334
};
4435
};
@@ -207,7 +198,7 @@ describe('Options', () => {
207198

208199
describe('paging.pageIndex', () => {
209200
it('should change current page', () => {
210-
const { dataController, optionsController } = setup({
201+
const { dataController, options } = setup({
211202
dataSource: [{ a: '1' }, { a: '2' }, { a: '3' }, { a: '4' }],
212203
paging: {
213204
pageSize: 2,
@@ -218,15 +209,15 @@ describe('Options', () => {
218209
let items = dataController.items.unreactive_get();
219210
expect(items).toEqual([{ a: '3' }, { a: '4' }]);
220211

221-
optionsController.option('paging.pageIndex', 0);
212+
options.option('paging.pageIndex', 0);
222213
items = dataController.items.unreactive_get();
223214
expect(items).toEqual([{ a: '1' }, { a: '2' }]);
224215
});
225216
});
226217

227218
describe('paging.pageSize', () => {
228219
it('should change size of current page', () => {
229-
const { dataController, optionsController } = setup({
220+
const { dataController, options } = setup({
230221
dataSource: [{ a: '1' }, { a: '2' }, { a: '3' }, { a: '4' }],
231222
paging: {
232223
pageSize: 2,
@@ -236,7 +227,7 @@ describe('Options', () => {
236227
let items = dataController.items.unreactive_get();
237228
expect(items).toEqual([{ a: '1' }, { a: '2' }]);
238229

239-
optionsController.option('paging.pageSize', 3);
230+
options.option('paging.pageSize', 3);
240231
items = dataController.items.unreactive_get();
241232
expect(items).toEqual([{ a: '1' }, { a: '2' }, { a: '3' }]);
242233
});

packages/devextreme/js/__internal/grids/new/grid_core/data_controller/public_methods.test.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,22 @@ import {
44
} from '@jest/globals';
55
import ArrayStore from '@ts/data/m_array_store';
66

7-
import { ColumnsController } from '../columns_controller';
8-
import { FilterController } from '../filtering';
97
import type { Options } from '../options';
10-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
11-
import { SearchController } from '../search';
12-
import { SortingController } from '../sorting_controller';
8+
import { getContext } from '../test_utils';
139
import { DataController } from './data_controller';
1410
import { PublicMethods } from './public_methods';
1511

16-
const setup = (options: Options) => {
17-
const optionsController = new OptionsControllerMock(options);
18-
const filterController = new FilterController(optionsController);
19-
const columnsController = new ColumnsController(optionsController);
20-
const sortingController = new SortingController(optionsController, columnsController);
21-
const searchController = new SearchController(optionsController, columnsController);
22-
const dataController = new DataController(
23-
optionsController,
24-
sortingController,
25-
filterController,
26-
searchController,
27-
);
12+
const setup = (config: Options) => {
13+
const context = getContext(config);
14+
15+
const dataController = context.get(DataController);
2816

2917
// @ts-expect-error
3018
const gridCore = new (PublicMethods(class {
3119
protected dataController = dataController;
3220
}))();
3321

3422
return {
35-
optionsController,
3623
dataController,
3724
gridCore,
3825
};

packages/devextreme/js/__internal/grids/new/grid_core/editing/controller.test.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
/* eslint-disable spellcheck/spell-checker */
22
import { describe, expect, it } from '@jest/globals';
33

4-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
4+
import { getContext } from '../test_utils';
55
import { ToolbarController } from '../toolbar/controller';
6-
import { EditingController } from './controller';
76
import type { Options } from './options';
87

9-
const setup = (options: Options) => {
10-
const optionsController = new OptionsControllerMock(options);
11-
const toolbarController = new ToolbarController(optionsController);
12-
const editingController = new EditingController(toolbarController, optionsController);
8+
const setup = (config: Options) => {
9+
const context = getContext(config);
10+
11+
const toolbarController = context.get(ToolbarController);
1312

1413
return {
15-
optionsController,
1614
toolbarController,
17-
editingController,
1815
};
1916
};
2017

packages/devextreme/js/__internal/grids/new/grid_core/editing/modes/popup/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export class PopupMode implements EditMode {
2121
constructor(
2222
private readonly options: OptionsController,
2323
private readonly editing: EditingController,
24-
private readonly toolbar: ToolbarController,
24+
private readonly toolbarController: ToolbarController,
2525
) {
26-
this.toolbar.addDefaultItem(this.addCardButton);
26+
this.toolbarController.addDefaultItem(this.addCardButton);
2727
}
2828

2929
public addNewCardImpl(): Promise<void> {

packages/devextreme/js/__internal/grids/new/grid_core/filtering/header_filter/controller.test.ts

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
11
/* eslint-disable spellcheck/spell-checker, no-spaced-func */
22
import { describe, expect, it } from '@jest/globals';
3-
import { ColumnsController } from '@ts/grids/new/grid_core/columns_controller';
43
import type { Column } from '@ts/grids/new/grid_core/columns_controller/types';
5-
import { DataController } from '@ts/grids/new/grid_core/data_controller';
6-
import { FilterController } from '@ts/grids/new/grid_core/filtering';
7-
import { HeaderFilterController } from '@ts/grids/new/grid_core/filtering/header_filter/controller';
84
import type { HeaderFilterColumnOptions } from '@ts/grids/new/grid_core/filtering/header_filter/types';
95
import type { Options } from '@ts/grids/new/grid_core/options';
10-
import { OptionsControllerMock } from '@ts/grids/new/grid_core/options_controller/options_controller.mock';
116

12-
import { SearchController } from '../../search';
13-
import { SortingController } from '../../sorting_controller/sorting_controller';
7+
import { ColumnsController } from '../../columns_controller/columns_controller';
8+
import { getContext } from '../../test_utils';
9+
import { HeaderFilterController } from './controller';
1410

1511
const setup = (config: Options = {}) => {
16-
const options = new OptionsControllerMock(config);
17-
const filterController = new FilterController(options);
18-
const columnsController = new ColumnsController(options);
19-
const sortingController = new SortingController(options, columnsController);
20-
const searchController = new SearchController(options, columnsController);
21-
const dataController = new DataController(
22-
options,
23-
sortingController,
24-
filterController,
25-
searchController,
26-
);
27-
const headerFilterController = new HeaderFilterController(
28-
options,
29-
dataController,
30-
columnsController,
31-
);
12+
const context = getContext(config);
13+
14+
const headerFilterController = context.get(HeaderFilterController);
15+
const columnsController = context.get(ColumnsController);
3216

3317
return {
3418
headerFilterController,

packages/devextreme/js/__internal/grids/new/grid_core/items_controller/items_controller.test.ts

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
/* eslint-disable spellcheck/spell-checker */
22
import { describe, expect, it } from '@jest/globals';
3-
import { SearchController } from '@ts/grids/new/grid_core/search';
43

54
import { ColumnsController } from '../columns_controller/columns_controller';
6-
import { DataController } from '../data_controller';
7-
import { FilterController } from '../filtering';
85
import type { Options } from '../options';
9-
import { OptionsControllerMock } from '../options_controller/options_controller.mock';
10-
import { SortingController } from '../sorting_controller';
6+
import { getContext } from '../test_utils';
117
import { ItemsController } from './items_controller';
128

139
const setup = (config: Options = {}) => {
14-
const options = new OptionsControllerMock(config);
10+
const context = getContext(config);
1511

16-
const columnsController = new ColumnsController(options);
17-
const filterController = new FilterController(options);
18-
const sortingController = new SortingController(options, columnsController);
19-
const searchController = new SearchController(options, columnsController);
20-
const dataController = new DataController(
21-
options,
22-
sortingController,
23-
filterController,
24-
searchController,
25-
);
26-
const itemsController = new ItemsController(
27-
dataController,
28-
columnsController,
29-
searchController,
30-
);
12+
const columnsController = context.get(ColumnsController);
13+
const itemsController = context.get(ItemsController);
3114

3215
return {
33-
options,
34-
dataController,
3516
columnsController,
3617
itemsController,
3718
};

0 commit comments

Comments
 (0)