-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
scroll-restoration-test.tsx
104 lines (97 loc) · 2.54 KB
/
scroll-restoration-test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as React from "react";
import { MemoryRouter, Outlet } from "react-router-dom";
import { render, screen } from "@testing-library/react";
import { LiveReload, 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");
});