Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move scroll test to it's own file #5590

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 18 additions & 34 deletions integration/bug-report-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,27 @@ test.beforeAll(async () => {
////////////////////////////////////////////////////////////////////////////
files: {
"app/routes/index.jsx": js`
import { redirect } from "@remix-run/node";
import { Form } from "@remix-run/react";

export const action = async () => {
await new Promise((resolve) => setTimeout(resolve, 500));

return redirect("/test");
};

import { json } from "@remix-run/node";
import { useLoaderData, Link } from "@remix-run/react";

export function loader() {
return json("pizza");
}

export default function Index() {
let data = useLoaderData();
return (
<div>
<h1>Scroll down to test</h1>

<Form method="post" action="/?index" style={{ marginTop: "150vh" }}>
<h1>Test here</h1>
<button type="submit">test</button>
</Form>
{data}
<Link to="/burgers">Other Route</Link>
</div>
);
}
)
}
`,

"app/routes/test.jsx": js`
"app/routes/burgers.jsx": js`
export default function Index() {
return (
<div>
<h1>This is the top</h1>
<h1 style={{ marginTop: "150vh" }}>This is the bottom</h1>
</div>
)
return <div>cheeseburger</div>;
}
`,
},
Expand All @@ -97,22 +87,16 @@ test.afterAll(() => {
// add a good description for what you expect Remix to do 👇🏽
////////////////////////////////////////////////////////////////////////////////

test("page scroll should be at the top on the new page", async ({ page }) => {
test("[description of what you expect it to do]", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
// You can test any request your app might get using `fixture`.
let response = await fixture.requestDocument("/");
expect(await response.text()).toMatch("Scroll down to test");
expect(await response.text()).toMatch("pizza");

// If you need to test interactivity use the `app`
await app.goto("/");
// scroll to the bottom
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await app.clickSubmitButton("/?index");

expect(await app.getHtml()).toMatch("This is the bottom");

let newScrollY = await page.evaluate(() => window.scrollY);
expect(newScrollY).toBe(0);
await app.clickLink("/burgers");
expect(await app.getHtml()).toMatch("cheeseburger");

// If you're not sure what's going on, you can "poke" the app, it'll
// automatically open up in your browser for 20 seconds, so be quick!
Expand Down
68 changes: 68 additions & 0 deletions integration/scroll-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { test, expect } from "@playwright/test";

import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture";

let fixture: Fixture;
let appFixture: AppFixture;

test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/routes/index.jsx": js`
import { redirect } from "@remix-run/node";
import { Form } from "@remix-run/react";

export function action() {
return redirect("/test");
};

export default function Component() {
return (
<>
<h1>Index Page - Scroll Down</h1>
<Form method="post" style={{ marginTop: "150vh" }}>
<button type="submit">Submit</button>
</Form>
</>
);
}
`,

"app/routes/test.jsx": js`
export default function Component() {
return (
<>
<h1 id="redirected">Redirected!</h1>
<p style={{ marginTop: "150vh" }}>I should not be visible!!</p>
</>
);
}
`,
},
});

// This creates an interactive app using puppeteer.
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => {
appFixture.close();
});

test("page scroll should be at the top on the new page", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");

// Scroll to the bottom and submit
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
let scroll = await page.evaluate(() => window.scrollY);
expect(scroll).toBeGreaterThan(0);
await app.clickSubmitButton("/?index");
await page.waitForSelector("#redirected");

// Ensure we scrolled back to the top
scroll = await page.evaluate(() => window.scrollY);
expect(scroll).toBe(0);
});