@@ -64,27 +64,52 @@ test.beforeAll(async () => {
64
64
// `createFixture` will make an app and run your tests against it.
65
65
////////////////////////////////////////////////////////////////////////////
66
66
files : {
67
+ "app/routes.ts" : js `
68
+ import { type RouteConfig } from "@react-router/dev/routes";
69
+ import { flatRoutes } from "@react-router/fs-routes";
70
+
71
+ export default flatRoutes() satisfies RouteConfig;
72
+ ` ,
73
+
67
74
"app/routes/_index.tsx" : js `
68
- import { useLoaderData, Link } from "react-router";
75
+ import { href } from "react-router";
76
+ import type { Route } from "./+types/_index";
69
77
70
78
export function loader() {
71
- return "pizza" ;
79
+ return { id: "a123" } ;
72
80
}
73
81
74
- export default function Index() {
75
- let data = useLoaderData();
82
+ export default function Home({ loaderData }: Route.ComponentProps) {
76
83
return (
77
84
<div>
78
- {data}
79
- <Link to="/burgers">Other Route</Link>
85
+ <ul>
86
+ <li>
87
+ <a href={href("/text/:id.txt", { id: loaderData.id })} id="with-href">
88
+ View text file for id {loaderData.id} with href()
89
+ </a>
90
+ </li>
91
+ <li>
92
+ <a href={${ "`" } /text/\${loaderData.id}.txt${ "`" } } id="with-template-string">
93
+ View text file for id {loaderData.id} with template string
94
+ </a>
95
+ </li>
96
+ </ul>
80
97
</div>
81
- )
98
+ );
82
99
}
83
100
` ,
84
101
85
- "app/routes/burgers.tsx" : js `
86
- export default function Index() {
87
- return <div>cheeseburger</div>;
102
+ "app/routes/text.$id[.txt].ts" : js `
103
+ import type { Route } from "./+types/text.$id[.txt]";
104
+
105
+ export async function loader({ params }: Route.LoaderArgs) {
106
+ const text = "The text file content for id: " + params.id;
107
+ return new Response(text, {
108
+ status: 200,
109
+ headers: {
110
+ "Content-Type": "text/plain",
111
+ },
112
+ });
88
113
}
89
114
` ,
90
115
} ,
@@ -103,22 +128,22 @@ test.afterAll(() => {
103
128
// add a good description for what you expect React Router to do 👇🏽
104
129
////////////////////////////////////////////////////////////////////////////////
105
130
106
- test ( "[description of what you expect it to do] " , async ( { page } ) => {
131
+ test ( "link from template string is correct " , async ( { page } ) => {
107
132
let app = new PlaywrightFixture ( appFixture , page ) ;
108
- // You can test any request your app might get using `fixture`.
109
- let response = await fixture . requestDocument ( "/" ) ;
110
- expect ( await response . text ( ) ) . toMatch ( "pizza" ) ;
111
-
112
- // If you need to test interactivity use the `app`
113
133
await app . goto ( "/" ) ;
114
- await app . clickLink ( "/burgers" ) ;
115
- await page . waitForSelector ( "text=cheeseburger" ) ;
116
-
117
- // If you're not sure what's going on, you can "poke" the app, it'll
118
- // automatically open up in your browser for 20 seconds, so be quick!
119
- // await app.poke(20);
134
+ await app . clickElement ( "a#with-template-string" ) ;
135
+ await page . waitForURL ( "**/text/**" ) ;
136
+ let content = await page . content ( ) ;
137
+ await expect ( content ) . toContain ( "The text file content for id:" ) ;
138
+ } ) ;
120
139
121
- // Go check out the other tests to see what else you can do.
140
+ test ( "link from href is correct" , async ( { page } ) => {
141
+ let app = new PlaywrightFixture ( appFixture , page ) ;
142
+ await app . goto ( "/" ) ;
143
+ await app . clickElement ( "a#with-href" ) ;
144
+ await page . waitForURL ( "**/text/**" ) ;
145
+ let content = await page . content ( ) ;
146
+ await expect ( content ) . toContain ( "The text file content for id:" ) ;
122
147
} ) ;
123
148
124
149
////////////////////////////////////////////////////////////////////////////////
0 commit comments