@@ -120,6 +120,7 @@ test(`can render one item`, async () => {
120
120
pop : expect . any ( Function ) ,
121
121
replace : expect . any ( Function ) ,
122
122
reset : expect . any ( Function ) ,
123
+ setParameters : expect . any ( Function ) ,
123
124
bottom : true ,
124
125
top : true ,
125
126
parameters : {
@@ -367,6 +368,7 @@ test(`can render two items`, async () => {
367
368
pop : expect . any ( Function ) ,
368
369
replace : expect . any ( Function ) ,
369
370
reset : expect . any ( Function ) ,
371
+ setParameters : expect . any ( Function ) ,
370
372
bottom : true ,
371
373
top : false ,
372
374
parameters : {
@@ -404,6 +406,7 @@ test(`can render two items`, async () => {
404
406
pop : expect . any ( Function ) ,
405
407
replace : expect . any ( Function ) ,
406
408
reset : expect . any ( Function ) ,
409
+ setParameters : expect . any ( Function ) ,
407
410
bottom : false ,
408
411
top : true ,
409
412
parameters : {
@@ -668,6 +671,7 @@ test(`can render three items`, async () => {
668
671
pop : expect . any ( Function ) ,
669
672
replace : expect . any ( Function ) ,
670
673
reset : expect . any ( Function ) ,
674
+ setParameters : expect . any ( Function ) ,
671
675
bottom : true ,
672
676
top : false ,
673
677
parameters : {
@@ -705,6 +709,7 @@ test(`can render three items`, async () => {
705
709
pop : expect . any ( Function ) ,
706
710
replace : expect . any ( Function ) ,
707
711
reset : expect . any ( Function ) ,
712
+ setParameters : expect . any ( Function ) ,
708
713
bottom : false ,
709
714
top : false ,
710
715
parameters : {
@@ -742,6 +747,7 @@ test(`can render three items`, async () => {
742
747
pop : expect . any ( Function ) ,
743
748
replace : expect . any ( Function ) ,
744
749
reset : expect . any ( Function ) ,
750
+ setParameters : expect . any ( Function ) ,
745
751
bottom : false ,
746
752
top : true ,
747
753
parameters : {
@@ -2038,3 +2044,148 @@ test(`reset`, async () => {
2038
2044
2039
2045
renderer . unmount ( ) ;
2040
2046
} ) ;
2047
+
2048
+ test ( `setParameters` , async ( ) => {
2049
+ type ParametersA = {
2050
+ readonly testRouteAParameterKey :
2051
+ | `Test Route A Parameter Value A`
2052
+ | `Test Route A Parameter Value B`
2053
+ | `Test Route A Parameter Value C`;
2054
+ } ;
2055
+
2056
+ type ParametersB = {
2057
+ readonly testRouteBParameterKey :
2058
+ | `Test Route B Parameter Value A`
2059
+ | `Test Route B Parameter Value B`;
2060
+ } ;
2061
+
2062
+ type ParametersC = {
2063
+ readonly testRouteCParameterKey :
2064
+ | `Test Route C Parameter Value A`
2065
+ | `Test Route C Parameter Value B`;
2066
+ } ;
2067
+
2068
+ type Parameters = {
2069
+ testRouteAKey : ParametersA ;
2070
+ testRouteBKey : ParametersB ;
2071
+ testRouteCKey : ParametersC ;
2072
+ } ;
2073
+
2074
+ type OtherProps = {
2075
+ exampleOtherPropKey : `Example Other Prop Value`;
2076
+ } ;
2077
+
2078
+ const RouteA : StackRoute < Parameters , `testRouteAKey`, OtherProps > = ( {
2079
+ parameters : { testRouteAParameterKey } ,
2080
+ exampleOtherPropKey,
2081
+ } ) => (
2082
+ < Text >
2083
+ Example Route A with parameter { testRouteAParameterKey } { " " }
2084
+ { exampleOtherPropKey }
2085
+ </ Text >
2086
+ ) ;
2087
+
2088
+ const RouteB : StackRoute < Parameters , `testRouteBKey`, OtherProps > = ( {
2089
+ parameters : { testRouteBParameterKey } ,
2090
+ exampleOtherPropKey,
2091
+ } ) => (
2092
+ < Text >
2093
+ Example Route B with parameter { testRouteBParameterKey } { " " }
2094
+ { exampleOtherPropKey }
2095
+ </ Text >
2096
+ ) ;
2097
+
2098
+ const RouteC : StackRoute < Parameters , `testRouteCKey`, OtherProps > = ( {
2099
+ parameters : { testRouteCParameterKey } ,
2100
+ exampleOtherPropKey,
2101
+ } ) => (
2102
+ < Text >
2103
+ Example Route C with parameter { testRouteCParameterKey } { " " }
2104
+ { exampleOtherPropKey }
2105
+ </ Text >
2106
+ ) ;
2107
+
2108
+ const routeTable : StackRouteTable < Parameters , OtherProps > = {
2109
+ testRouteAKey : RouteA ,
2110
+ testRouteBKey : RouteB ,
2111
+ testRouteCKey : RouteC ,
2112
+ } ;
2113
+
2114
+ const routeState : StackRouterState < Parameters > = [
2115
+ {
2116
+ uuid : `ec055b0f-0659-4e9a-a889-06a7586bb61a` ,
2117
+ key : `testRouteBKey` ,
2118
+ parameters : {
2119
+ testRouteBParameterKey : `Test Route B Parameter Value A` ,
2120
+ } ,
2121
+ } ,
2122
+ {
2123
+ uuid : `f36ce5e7-d37e-443a-8635-718118c27128` ,
2124
+ key : `testRouteAKey` ,
2125
+ parameters : {
2126
+ testRouteAParameterKey : `Test Route A Parameter Value A` ,
2127
+ } ,
2128
+ } ,
2129
+ {
2130
+ uuid : "345d1eff-3d1d-4d93-8136-e0c3ff0f7f7c" ,
2131
+ key : `testRouteAKey` ,
2132
+ parameters : {
2133
+ testRouteAParameterKey : `Test Route A Parameter Value B` ,
2134
+ } ,
2135
+ } ,
2136
+ ] ;
2137
+
2138
+ const setRouteState = jest . fn ( ) ;
2139
+ const onBack = jest . fn ( ) ;
2140
+
2141
+ const Component = createStackRoutingComponent ( routeTable ) ;
2142
+
2143
+ const renderer = TestRenderer . create (
2144
+ < Component
2145
+ routeState = { routeState }
2146
+ setRouteState = { setRouteState }
2147
+ exampleOtherPropKey = "Example Other Prop Value"
2148
+ onBack = { onBack }
2149
+ />
2150
+ ) ;
2151
+
2152
+ await new Promise < void > ( ( resolve ) => {
2153
+ setTimeout ( resolve , 100 ) ;
2154
+ } ) ;
2155
+
2156
+ (
2157
+ renderer . toTree ( )
2158
+ ?. rendered as ReadonlyArray < TestRenderer . ReactTestRendererTree >
2159
+ ) [ 1 ] ?. props [ `children` ] . props . children . props . setParameters ( {
2160
+ testRouteAParameterKey : `Test Route A Parameter Value C` ,
2161
+ } ) ;
2162
+
2163
+ expect ( setRouteState ) . toBeCalledTimes ( 1 ) ;
2164
+ expect ( setRouteState ) . toHaveBeenCalledWith ( [
2165
+ {
2166
+ uuid : `ec055b0f-0659-4e9a-a889-06a7586bb61a` ,
2167
+ key : `testRouteBKey` ,
2168
+ parameters : {
2169
+ testRouteBParameterKey : `Test Route B Parameter Value A` ,
2170
+ } ,
2171
+ } ,
2172
+ {
2173
+ uuid : `f36ce5e7-d37e-443a-8635-718118c27128` ,
2174
+ key : `testRouteAKey` ,
2175
+ parameters : {
2176
+ testRouteAParameterKey : `Test Route A Parameter Value C` ,
2177
+ } ,
2178
+ } ,
2179
+ {
2180
+ uuid : "345d1eff-3d1d-4d93-8136-e0c3ff0f7f7c" ,
2181
+ key : `testRouteAKey` ,
2182
+ parameters : {
2183
+ testRouteAParameterKey : `Test Route A Parameter Value B` ,
2184
+ } ,
2185
+ } ,
2186
+ ] ) ;
2187
+
2188
+ expect ( onBack ) . not . toHaveBeenCalled ( ) ;
2189
+
2190
+ renderer . unmount ( ) ;
2191
+ } ) ;
0 commit comments