-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98b5718
commit 0c07312
Showing
2 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
packages/remix-react/__tests__/scroll-restoration-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import * as React from "react"; | ||
import { MemoryRouter, Outlet } from "react-router-dom"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
|
||
import { | ||
Link, | ||
Links, | ||
LiveReload, | ||
Meta, | ||
NavLink, | ||
RemixEntryContext, | ||
Scripts, | ||
} from "../components"; | ||
import type { RemixEntryContextType } from "../components"; | ||
import { ScrollRestoration } from "../scroll-restoration"; | ||
|
||
import "@testing-library/jest-dom/extend-expect"; | ||
|
||
function AppShell({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<React.Fragment> | ||
<Outlet /> | ||
{children} | ||
<Scripts /> | ||
<LiveReload /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
describe("<ScrollRestoration />", () => { | ||
function withContext(stuff: JSX.Element) { | ||
let context: RemixEntryContextType = { | ||
routeModules: { idk: { default: () => null } }, | ||
manifest: { | ||
routes: { | ||
idk: { | ||
hasLoader: true, | ||
hasAction: false, | ||
hasCatchBoundary: false, | ||
hasErrorBoundary: false, | ||
id: "idk", | ||
module: "idk", | ||
}, | ||
}, | ||
entry: { imports: [], module: "" }, | ||
url: "", | ||
version: "", | ||
}, | ||
matches: [], | ||
clientRoutes: [ | ||
{ | ||
id: "idk", | ||
path: "idk", | ||
hasLoader: true, | ||
element: "", | ||
module: "", | ||
async action() { | ||
return {}; | ||
}, | ||
async loader() { | ||
return {}; | ||
}, | ||
}, | ||
], | ||
routeData: {}, | ||
appState: {} as any, | ||
transitionManager: { | ||
getState() { | ||
return { | ||
transition: {}, | ||
}; | ||
}, | ||
} as any, | ||
}; | ||
return ( | ||
<RemixEntryContext.Provider value={context}> | ||
<MemoryRouter>{stuff}</MemoryRouter> | ||
</RemixEntryContext.Provider> | ||
); | ||
} | ||
|
||
it("should render a <script> tag", () => { | ||
render( | ||
withContext( | ||
<AppShell> | ||
<ScrollRestoration data-testid="scroll-script" /> | ||
</AppShell> | ||
) | ||
); | ||
let script = screen.getByTestId("scroll-script"); | ||
expect(script instanceof HTMLScriptElement).toBe(true); | ||
}); | ||
|
||
it("should pass props to <script>", () => { | ||
render( | ||
withContext( | ||
<AppShell> | ||
<ScrollRestoration | ||
data-testid="scroll-script" | ||
nonce="hello" | ||
crossOrigin="anonymous" | ||
/> | ||
</AppShell> | ||
) | ||
); | ||
let script = screen.getByTestId("scroll-script"); | ||
expect(script).toHaveAttribute("nonce", "hello"); | ||
expect(script).toHaveAttribute("crossorigin", "anonymous"); | ||
}); | ||
|
||
it.todo("should restore scroll position"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters