Skip to content

Commit a2d4846

Browse files
Add failing multipart/form-data test
1 parent 39e4a69 commit a2d4846

File tree

1 file changed

+30
-80
lines changed

1 file changed

+30
-80
lines changed

integration/bug-report-test.ts

Lines changed: 30 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,6 @@ import {
1111
let fixture: Fixture;
1212
let appFixture: AppFixture;
1313

14-
////////////////////////////////////////////////////////////////////////////////
15-
// 👋 Hola! I'm here to help you write a great bug report pull request.
16-
//
17-
// You don't need to fix the bug, this is just to report one.
18-
//
19-
// The pull request you are submitting is supposed to fail when created, to let
20-
// the team see the erroneous behavior, and understand what's going wrong.
21-
//
22-
// If you happen to have a fix as well, it will have to be applied in a subsequent
23-
// commit to this pull request, and your now-succeeding test will have to be moved
24-
// to the appropriate file.
25-
//
26-
// First, make sure to install dependencies and build React Router. From the root of
27-
// the project, run this:
28-
//
29-
// ```
30-
// pnpm install && pnpm build
31-
// ```
32-
//
33-
// If you have never installed playwright on your system before, you may also need
34-
// to install a browser engine:
35-
//
36-
// ```
37-
// pnpm exec playwright install chromium
38-
// ```
39-
//
40-
// Now try running this test:
41-
//
42-
// ```
43-
// pnpm test:integration bug-report --project chromium
44-
// ```
45-
//
46-
// You can add `--watch` to the end to have it re-run on file changes:
47-
//
48-
// ```
49-
// pnpm test:integration bug-report --project chromium --watch
50-
// ```
51-
////////////////////////////////////////////////////////////////////////////////
52-
5314
test.beforeEach(async ({ context }) => {
5415
await context.route(/\.data$/, async (route) => {
5516
await new Promise((resolve) => setTimeout(resolve, 50));
@@ -59,34 +20,38 @@ test.beforeEach(async ({ context }) => {
5920

6021
test.beforeAll(async () => {
6122
fixture = await createFixture({
62-
////////////////////////////////////////////////////////////////////////////
63-
// 💿 Next, add files to this object, just like files in a real app,
64-
// `createFixture` will make an app and run your tests against it.
65-
////////////////////////////////////////////////////////////////////////////
6623
files: {
6724
"app/routes/_index.tsx": js`
68-
import { useLoaderData, Link } from "react-router";
25+
import { Form } from "react-router";
6926
70-
export function loader() {
71-
return "pizza";
27+
export function action({request}) {
28+
return { message: "Hey" + request.headers.get('content-type') };
7229
}
7330
74-
export default function Index() {
75-
let data = useLoaderData();
31+
export default function Index({actionData}) {
7632
return (
77-
<div>
78-
{data}
79-
<Link to="/burgers">Other Route</Link>
80-
</div>
33+
<Form method="POST">
34+
<button
35+
id="form-urlencoded"
36+
type="submit"
37+
formEncType="application/x-www-form-urlencoded"
38+
className="px-2 py-1 rounded bg-blue-500 text-white"
39+
>
40+
Go form urlencoded
41+
</button>
42+
<button
43+
id="multipart"
44+
type="submit"
45+
formEncType="multipart/form-data"
46+
className="px-2 py-1 rounded bg-blue-500 text-white"
47+
>
48+
Go multipart
49+
</button>
50+
{actionData?.message}
51+
</Form>
8152
)
8253
}
8354
`,
84-
85-
"app/routes/burgers.tsx": js`
86-
export default function Index() {
87-
return <div>cheeseburger</div>;
88-
}
89-
`,
9055
},
9156
});
9257

@@ -98,30 +63,15 @@ test.afterAll(() => {
9863
appFixture.close();
9964
});
10065

101-
////////////////////////////////////////////////////////////////////////////////
102-
// 💿 Almost done, now write your failing test case(s) down here Make sure to
103-
// add a good description for what you expect React Router to do 👇🏽
104-
////////////////////////////////////////////////////////////////////////////////
105-
106-
test("[description of what you expect it to do]", async ({ page }) => {
66+
test("[handle multipart/form-data actions]", async ({ page }) => {
10767
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`
11368
await app.goto("/");
114-
await app.clickLink("/burgers");
115-
await page.waitForSelector("text=cheeseburger");
11669

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);
70+
// This works correctly
71+
await app.clickElement("#form-urlencoded");
72+
await page.waitForSelector("text=application/x-www-form-urlencoded");
12073

121-
// Go check out the other tests to see what else you can do.
74+
// This should also work, but it fails
75+
await app.clickElement("#multipart");
76+
await page.waitForSelector("text=multipart/form-data");
12277
});
123-
124-
////////////////////////////////////////////////////////////////////////////////
125-
// 💿 Finally, push your changes to your fork of React Router
126-
// and open a pull request!
127-
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)