1- import {
2- ComputedAtom ,
3- DerivedPropsGate ,
4- SetupComponent ,
5- SetupComponentHost
6- } from "@mendix/widget-plugin-mobx-kit/main" ;
1+ import { DerivedPropsGate , SetupComponent , SetupComponentHost } from "@mendix/widget-plugin-mobx-kit/main" ;
72import { editable } from "@mendix/widget-plugin-test-utils" ;
83import { Big } from "big.js" ;
9- import { action , makeObservable , observable , runInAction } from "mobx" ;
4+ import { action , IObservableValue , makeObservable , observable , runInAction } from "mobx" ;
105import { EditableValue } from "mendix" ;
116import { GridPageControl } from "../../interfaces/GridPageControl" ;
127import { DynamicPaginationFeature } from "../DynamicPagination.feature" ;
@@ -18,18 +13,13 @@ type GateProps = {
1813 loadedRowsValue ?: EditableValue < Big > ;
1914} ;
2015
21- type NumberAtomBox = {
22- atom : ComputedAtom < number > ;
23- set : ( value : number ) => void ;
24- } ;
25-
2616type AtomsFixture = {
27- dynamicPage : NumberAtomBox ;
28- dynamicPageSize : NumberAtomBox ;
29- totalCount : NumberAtomBox ;
30- currentPage : NumberAtomBox ;
31- pageSize : NumberAtomBox ;
32- loadedRows : NumberAtomBox ;
17+ dynamicPage : IObservableValue < number > ;
18+ dynamicPageSize : IObservableValue < number > ;
19+ totalCount : IObservableValue < number > ;
20+ currentPage : IObservableValue < number > ;
21+ pageSize : IObservableValue < number > ;
22+ loadedRows : IObservableValue < number > ;
3323} ;
3424
3525type AttributesFixture = {
@@ -50,14 +40,6 @@ function lastArgToNumber(mockFn: jest.MockedFunction<any>): number {
5040 return calls [ calls . length - 1 ] [ 0 ] . toNumber ( ) ;
5141}
5242
53- function boxAtom ( initial : number ) : NumberAtomBox {
54- const box = observable . box ( initial ) ;
55- return {
56- atom : box as unknown as ComputedAtom < number > ,
57- set : value => box . set ( value )
58- } ;
59- }
60-
6143function makeHost ( ) : SetupComponentHost {
6244 return {
6345 add : ( _component : SetupComponent ) => { } ,
@@ -77,12 +59,12 @@ function createMockService(): jest.Mocked<GridPageControl> {
7759
7860function createAtoms ( overrides ?: Partial < Record < keyof AtomsFixture , number > > ) : AtomsFixture {
7961 return {
80- dynamicPage : boxAtom ( overrides ?. dynamicPage ?? - 1 ) ,
81- dynamicPageSize : boxAtom ( overrides ?. dynamicPageSize ?? - 1 ) ,
82- totalCount : boxAtom ( overrides ?. totalCount ?? 0 ) ,
83- currentPage : boxAtom ( overrides ?. currentPage ?? 0 ) ,
84- pageSize : boxAtom ( overrides ?. pageSize ?? 10 ) ,
85- loadedRows : boxAtom ( overrides ?. loadedRows ?? 0 )
62+ dynamicPage : observable . box ( overrides ?. dynamicPage ?? - 1 ) ,
63+ dynamicPageSize : observable . box ( overrides ?. dynamicPageSize ?? - 1 ) ,
64+ totalCount : observable . box ( overrides ?. totalCount ?? 0 ) ,
65+ currentPage : observable . box ( overrides ?. currentPage ?? 0 ) ,
66+ pageSize : observable . box ( overrides ?. pageSize ?? 10 ) ,
67+ loadedRows : observable . box ( overrides ?. loadedRows ?? 0 )
8668 } ;
8769}
8870
@@ -111,11 +93,11 @@ function createFeature(
11193 const feature = new DynamicPaginationFeature (
11294 makeHost ( ) ,
11395 config ,
114- atoms . dynamicPage . atom ,
115- atoms . dynamicPageSize . atom ,
116- atoms . totalCount . atom ,
117- atoms . currentPage . atom ,
118- atoms . loadedRows . atom ,
96+ atoms . dynamicPage ,
97+ atoms . dynamicPageSize ,
98+ atoms . totalCount ,
99+ atoms . currentPage ,
100+ atoms . loadedRows ,
119101 gate ,
120102 service
121103 ) ;
0 commit comments