@@ -1955,7 +1955,7 @@ describe("a router", () => {
1955
1955
} ) ;
1956
1956
} ) ;
1957
1957
1958
- describe ( "POP navigations after action redirect " , ( ) => {
1958
+ describe ( "POP navigations" , ( ) => {
1959
1959
it ( "does a normal load when backing into an action redirect" , async ( ) => {
1960
1960
let t = initializeTmTest ( ) ;
1961
1961
let A = await t . navigate ( "/foo" , {
@@ -1979,14 +1979,131 @@ describe("a router", () => {
1979
1979
baz : "C LOADER" ,
1980
1980
} ) ;
1981
1981
1982
- let D = await t . navigate ( - 2 ) ;
1982
+ let D = await t . navigate ( - 1 ) ;
1983
1983
await D . loaders . bar . resolve ( "D LOADER" ) ;
1984
1984
expect ( D . loaders . root . stub . mock . calls . length ) . toBe ( 0 ) ;
1985
1985
expect ( t . router . state . loaderData ) . toMatchObject ( {
1986
1986
root : "ROOT DATA" ,
1987
1987
bar : "D LOADER" ,
1988
1988
} ) ;
1989
1989
} ) ;
1990
+
1991
+ it ( "navigates correctly using POP navigations" , async ( ) => {
1992
+ let t = initializeTmTest ( ) ;
1993
+
1994
+ let A = await t . navigate ( "/foo" ) ;
1995
+ await A . loaders . foo . resolve ( "FOO" ) ;
1996
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
1997
+
1998
+ let B = await t . navigate ( "/bar" ) ;
1999
+ await B . loaders . bar . resolve ( "BAR" ) ;
2000
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2001
+
2002
+ let C = await t . navigate ( - 1 ) ;
2003
+ await C . loaders . foo . resolve ( "FOO*" ) ;
2004
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2005
+
2006
+ let D = await t . navigate ( "/baz" , { replace : true } ) ;
2007
+ await D . loaders . baz . resolve ( "BAZ" ) ;
2008
+ expect ( t . router . state . location . pathname ) . toEqual ( "/baz" ) ;
2009
+
2010
+ // POP to /
2011
+ let E = await t . navigate ( - 1 ) ;
2012
+ await E . loaders . index . resolve ( "INDEX*" ) ;
2013
+ expect ( t . router . state . location . pathname ) . toEqual ( "/" ) ;
2014
+ } ) ;
2015
+
2016
+ it ( "navigates correctly using POP navigations across actions" , async ( ) => {
2017
+ let t = initializeTmTest ( ) ;
2018
+
2019
+ // Navigate to /foo
2020
+ let A = await t . navigate ( "/foo" ) ;
2021
+ await A . loaders . foo . resolve ( "FOO" ) ;
2022
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2023
+
2024
+ // Navigate to /bar
2025
+ let B = await t . navigate ( "/bar" ) ;
2026
+ await B . loaders . bar . resolve ( "BAR" ) ;
2027
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2028
+
2029
+ // Post to /bar (should replace)
2030
+ let C = await t . navigate ( "/bar" , {
2031
+ formMethod : "post" ,
2032
+ formData : createFormData ( { key : "value" } ) ,
2033
+ } ) ;
2034
+ await C . actions . bar . resolve ( "BAR ACTION" ) ;
2035
+ await C . loaders . root . resolve ( "ROOT" ) ;
2036
+ await C . loaders . bar . resolve ( "BAR" ) ;
2037
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2038
+
2039
+ // POP to /foo
2040
+ let D = await t . navigate ( - 1 ) ;
2041
+ await D . loaders . foo . resolve ( "FOO" ) ;
2042
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2043
+ } ) ;
2044
+
2045
+ it ( "navigates correctly using POP navigations across action redirects" , async ( ) => {
2046
+ let t = initializeTmTest ( ) ;
2047
+
2048
+ // Navigate to /foo
2049
+ let A = await t . navigate ( "/foo" ) ;
2050
+ await A . loaders . foo . resolve ( "FOO" ) ;
2051
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2052
+
2053
+ // Navigate to /bar
2054
+ let B = await t . navigate ( "/bar" ) ;
2055
+ let getBarKey = t . router . state . navigation . location ?. key ;
2056
+ await B . loaders . bar . resolve ( "BAR" ) ;
2057
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2058
+
2059
+ // Post to /bar, redirect to /baz
2060
+ let C = await t . navigate ( "/bar" , {
2061
+ formMethod : "post" ,
2062
+ formData : createFormData ( { key : "value" } ) ,
2063
+ } ) ;
2064
+ let postBarKey = t . router . state . navigation . location ?. key ;
2065
+ let D = await C . actions . bar . redirect ( "/baz" ) ;
2066
+ await D . loaders . root . resolve ( "ROOT" ) ;
2067
+ await D . loaders . baz . resolve ( "BAZ" ) ;
2068
+ expect ( t . router . state . location . pathname ) . toEqual ( "/baz" ) ;
2069
+
2070
+ // POP to /bar
2071
+ let E = await t . navigate ( - 1 ) ;
2072
+ await E . loaders . bar . resolve ( "BAR" ) ;
2073
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2074
+ expect ( t . router . state . location . key ) . toBe ( getBarKey ) ;
2075
+ expect ( t . router . state . location . key ) . not . toBe ( postBarKey ) ;
2076
+ } ) ;
2077
+
2078
+ it ( "navigates correctly using POP navigations across <Form replace> redirects" , async ( ) => {
2079
+ let t = initializeTmTest ( ) ;
2080
+
2081
+ // Navigate to /foo
2082
+ let A = await t . navigate ( "/foo" ) ;
2083
+ await A . loaders . foo . resolve ( "FOO" ) ;
2084
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2085
+
2086
+ // Navigate to /bar
2087
+ let B = await t . navigate ( "/bar" ) ;
2088
+ await B . loaders . bar . resolve ( "BAR" ) ;
2089
+ expect ( t . router . state . location . pathname ) . toEqual ( "/bar" ) ;
2090
+
2091
+ // Post to /bar, redirect to /baz
2092
+ let C = await t . navigate ( "/bar" , {
2093
+ formMethod : "post" ,
2094
+ formData : createFormData ( { key : "value" } ) ,
2095
+ replace : true ,
2096
+ } ) ;
2097
+ let D = await C . actions . bar . redirect ( "/baz" ) ;
2098
+ await D . loaders . root . resolve ( "ROOT" ) ;
2099
+ await D . loaders . baz . resolve ( "BAZ" ) ;
2100
+ expect ( t . router . state . location . pathname ) . toEqual ( "/baz" ) ;
2101
+
2102
+ // POP to /foo
2103
+ let E = await t . navigate ( - 1 ) ;
2104
+ await E . loaders . foo . resolve ( "FOO" ) ;
2105
+ expect ( t . router . state . location . pathname ) . toEqual ( "/foo" ) ;
2106
+ } ) ;
1990
2107
} ) ;
1991
2108
1992
2109
describe ( "submission navigations" , ( ) => {
@@ -4602,7 +4719,7 @@ describe("a router", () => {
4602
4719
await N . loaders . root . resolve ( "ROOT_DATA*" ) ;
4603
4720
await N . loaders . tasks . resolve ( "TASKS_DATA" ) ;
4604
4721
expect ( t . router . state ) . toMatchObject ( {
4605
- historyAction : "PUSH " ,
4722
+ historyAction : "REPLACE " ,
4606
4723
location : { pathname : "/tasks" } ,
4607
4724
navigation : IDLE_NAVIGATION ,
4608
4725
revalidation : "idle" ,
@@ -4614,7 +4731,7 @@ describe("a router", () => {
4614
4731
tasks : "TASKS_ACTION" ,
4615
4732
} ,
4616
4733
} ) ;
4617
- expect ( t . history . push ) . toHaveBeenCalledWith (
4734
+ expect ( t . history . replace ) . toHaveBeenCalledWith (
4618
4735
t . router . state . location ,
4619
4736
t . router . state . location . state
4620
4737
) ;
@@ -4814,7 +4931,7 @@ describe("a router", () => {
4814
4931
await R . loaders . root . resolve ( "ROOT_DATA*" ) ;
4815
4932
await R . loaders . tasks . resolve ( "TASKS_DATA*" ) ;
4816
4933
expect ( t . router . state ) . toMatchObject ( {
4817
- historyAction : "PUSH " ,
4934
+ historyAction : "REPLACE " ,
4818
4935
location : { pathname : "/tasks" } ,
4819
4936
navigation : IDLE_NAVIGATION ,
4820
4937
revalidation : "idle" ,
@@ -4823,7 +4940,7 @@ describe("a router", () => {
4823
4940
tasks : "TASKS_DATA*" ,
4824
4941
} ,
4825
4942
} ) ;
4826
- expect ( t . history . push ) . toHaveBeenCalledWith (
4943
+ expect ( t . history . replace ) . toHaveBeenCalledWith (
4827
4944
t . router . state . location ,
4828
4945
t . router . state . location . state
4829
4946
) ;
@@ -4901,7 +5018,7 @@ describe("a router", () => {
4901
5018
await R . loaders . root . resolve ( "ROOT_DATA*" ) ;
4902
5019
await R . loaders . tasks . resolve ( "TASKS_DATA*" ) ;
4903
5020
expect ( t . router . state ) . toMatchObject ( {
4904
- historyAction : "PUSH " ,
5021
+ historyAction : "REPLACE " ,
4905
5022
location : { pathname : "/tasks" } ,
4906
5023
navigation : IDLE_NAVIGATION ,
4907
5024
revalidation : "idle" ,
@@ -4913,7 +5030,7 @@ describe("a router", () => {
4913
5030
tasks : "TASKS_ACTION" ,
4914
5031
} ,
4915
5032
} ) ;
4916
- expect ( t . history . push ) . toHaveBeenCalledWith (
5033
+ expect ( t . history . replace ) . toHaveBeenCalledWith (
4917
5034
t . router . state . location ,
4918
5035
t . router . state . location . state
4919
5036
) ;
0 commit comments