@@ -9,12 +9,10 @@ import DataSource from '@js/data/data_source';
9
9
import { logger } from '@ts/core/utils/m_console' ;
10
10
import ArrayStore from '@ts/data/m_array_store' ;
11
11
12
- import { ColumnsController } from '../columns_controller' ;
13
- import { FilterController } from '../filtering' ;
14
12
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 ' ;
18
16
import { DataController } from './data_controller' ;
19
17
20
18
beforeAll ( ( ) => {
@@ -24,21 +22,14 @@ afterAll(() => {
24
22
jest . restoreAllMocks ( ) ;
25
23
} ) ;
26
24
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 ;
39
30
40
31
return {
41
- optionsController ,
32
+ options ,
42
33
dataController,
43
34
} ;
44
35
} ;
@@ -207,7 +198,7 @@ describe('Options', () => {
207
198
208
199
describe ( 'paging.pageIndex' , ( ) => {
209
200
it ( 'should change current page' , ( ) => {
210
- const { dataController, optionsController } = setup ( {
201
+ const { dataController, options } = setup ( {
211
202
dataSource : [ { a : '1' } , { a : '2' } , { a : '3' } , { a : '4' } ] ,
212
203
paging : {
213
204
pageSize : 2 ,
@@ -218,15 +209,15 @@ describe('Options', () => {
218
209
let items = dataController . items . unreactive_get ( ) ;
219
210
expect ( items ) . toEqual ( [ { a : '3' } , { a : '4' } ] ) ;
220
211
221
- optionsController . option ( 'paging.pageIndex' , 0 ) ;
212
+ options . option ( 'paging.pageIndex' , 0 ) ;
222
213
items = dataController . items . unreactive_get ( ) ;
223
214
expect ( items ) . toEqual ( [ { a : '1' } , { a : '2' } ] ) ;
224
215
} ) ;
225
216
} ) ;
226
217
227
218
describe ( 'paging.pageSize' , ( ) => {
228
219
it ( 'should change size of current page' , ( ) => {
229
- const { dataController, optionsController } = setup ( {
220
+ const { dataController, options } = setup ( {
230
221
dataSource : [ { a : '1' } , { a : '2' } , { a : '3' } , { a : '4' } ] ,
231
222
paging : {
232
223
pageSize : 2 ,
@@ -236,7 +227,7 @@ describe('Options', () => {
236
227
let items = dataController . items . unreactive_get ( ) ;
237
228
expect ( items ) . toEqual ( [ { a : '1' } , { a : '2' } ] ) ;
238
229
239
- optionsController . option ( 'paging.pageSize' , 3 ) ;
230
+ options . option ( 'paging.pageSize' , 3 ) ;
240
231
items = dataController . items . unreactive_get ( ) ;
241
232
expect ( items ) . toEqual ( [ { a : '1' } , { a : '2' } , { a : '3' } ] ) ;
242
233
} ) ;
0 commit comments