Skip to content

Commit 4cc8eec

Browse files
authoredAug 23, 2023
Add some redirect unit tests from Remix (#10810)
1 parent ae75cdc commit 4cc8eec

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
 

‎packages/router/__tests__/router-test.ts

+109
Original file line numberDiff line numberDiff line change
@@ -7080,6 +7080,115 @@ describe("a router", () => {
70807080
expect(t.window.location.replace).not.toHaveBeenCalled();
70817081
});
70827082

7083+
it("preserves action revalidation across multiple redirects", async () => {
7084+
let t = setup({
7085+
initialEntries: ["/action"],
7086+
routes: [
7087+
{
7088+
id: "action",
7089+
path: "/action",
7090+
loader: true,
7091+
children: [
7092+
{
7093+
id: "index",
7094+
index: true,
7095+
action: true,
7096+
loader: true,
7097+
},
7098+
{
7099+
id: "one",
7100+
path: "1",
7101+
loader: true,
7102+
},
7103+
{
7104+
path: "2",
7105+
},
7106+
],
7107+
},
7108+
],
7109+
hydrationData: {
7110+
loaderData: {
7111+
action: "ACTION 0",
7112+
},
7113+
},
7114+
});
7115+
7116+
let A = await t.navigate("/action?index", {
7117+
formMethod: "post",
7118+
formData: createFormData({}),
7119+
});
7120+
7121+
let B = await A.actions.index.redirectReturn("/action/1");
7122+
await B.loaders.action.resolve("ACTION 1");
7123+
let C = await B.loaders.one.redirectReturn("/action/2");
7124+
await C.loaders.action.resolve("ACTION 2");
7125+
7126+
expect(t.router.state).toMatchObject({
7127+
location: {
7128+
pathname: "/action/2",
7129+
},
7130+
navigation: IDLE_NAVIGATION,
7131+
loaderData: {
7132+
action: "ACTION 2",
7133+
},
7134+
});
7135+
});
7136+
7137+
it("preserves X-Remix-Revalidate revalidation across multiple redirects", async () => {
7138+
let t = setup({
7139+
initialEntries: ["/loader"],
7140+
routes: [
7141+
{
7142+
id: "loader",
7143+
path: "/loader",
7144+
loader: true,
7145+
children: [
7146+
{
7147+
id: "index",
7148+
index: true,
7149+
},
7150+
{
7151+
id: "one",
7152+
path: "1",
7153+
loader: true,
7154+
},
7155+
{
7156+
id: "two",
7157+
path: "2",
7158+
loader: true,
7159+
},
7160+
{
7161+
path: "3",
7162+
},
7163+
],
7164+
},
7165+
],
7166+
hydrationData: {
7167+
loaderData: {
7168+
loader: "LOADER 0",
7169+
},
7170+
},
7171+
});
7172+
7173+
let A = await t.navigate("/loader/1");
7174+
let B = await A.loaders.one.redirectReturn("/loader/2", undefined, {
7175+
"X-Remix-Revalidate": "true",
7176+
});
7177+
await B.loaders.loader.resolve("LOADER 3");
7178+
let C = await B.loaders.two.redirectReturn("/loader/3");
7179+
await C.loaders.loader.resolve("LOADER 3");
7180+
7181+
expect(t.router.state).toMatchObject({
7182+
location: {
7183+
pathname: "/loader/3",
7184+
},
7185+
navigation: IDLE_NAVIGATION,
7186+
loaderData: {
7187+
loader: "LOADER 3",
7188+
},
7189+
});
7190+
});
7191+
70837192
describe("redirect status code handling", () => {
70847193
it("should not treat 300 as a redirect", async () => {
70857194
let t = setup({ routes: REDIRECT_ROUTES });

0 commit comments

Comments
 (0)
Please sign in to comment.