Skip to content

Commit

Permalink
fix: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kiliman committed Apr 6, 2022
1 parent c14eade commit c969879
Showing 1 changed file with 62 additions and 178 deletions.
240 changes: 62 additions & 178 deletions integration/meta-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("meta object syntax", () => {
files: {
"app/root.jsx": js`
import { json } from "@remix-run/node";
import { Meta, Links, Outlet, Scripts } from "@remix-run/react";
import { Links, Meta, Outlet, Scripts } from "@remix-run/react";
export const loader = async () =>
json({
Expand All @@ -23,10 +23,6 @@ describe("meta object syntax", () => {
description: data.description,
"og:image": "https://picsum.photos/200/200",
"og:type": data.contentType, // undefined
refresh: {
httpEquiv: "refresh",
content: "3;url=https://www.mozilla.org",
},
title: data.title,
});
Expand Down Expand Up @@ -105,19 +101,6 @@ describe("meta object syntax", () => {
expect(await app.getHtml('meta[name="description"]')).toBeTruthy();
await enableJavaScript();
});

test("meta { refresh } adds a <meta http-equiv='refresh' content='3;url=https://www.mozilla.org' />", async () => {
let enableJavaScript = await app.disableJavaScript();

await app.goto("/");

expect(
await app.getHtml(
'meta[http-equiv="refresh"][content="3;url=https://www.mozilla.org"]'
)
).toBeTruthy();
await enableJavaScript();
});
});

describe("meta array syntax", () => {
Expand All @@ -128,125 +111,8 @@ describe("meta array syntax", () => {
fixture = await createFixture({
files: {
"app/root.jsx": js`
import { json, Meta, Links, Outlet, Scripts } from "remix";
// export const loader = async () =>
// json({
// description: "This is a meta page",
// title: "Meta Page",
// });
// export const meta = ({ data }) => ({
// charset: "utf-8",
// description: data.description,
// "og:image": "https://picsum.photos/200/200",
// "og:type": data.contentType, // undefined
// refresh: {
// httpEquiv: "refresh",
// content: "3;url=https://www.mozilla.org",
// },
// title: data.title,
// });
// export default function Root() {
// return (
// <html lang="en">
// <head>
// <Meta />
// <Links />
// </head>
// <body>
// <Outlet />
// <Scripts />
// </body>
// </html>
// );
// }
// `,

// "app/routes/index.jsx": js`
// export default function Index() {
// return <div>This is the index file</div>;
// }
// `,
// },
// });

// app = await createAppFixture(fixture);
// });

// afterAll(async () => await app.close());

// test("empty meta does not render a tag", async () => {
// let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");

// await expect(app.getHtml('meta[property="og:type"]')).rejects.toThrowError(
// 'No element matches selector "meta[property="og:type"]"'
// );
// await enableJavaScript();
// });

// test("meta { charset } adds a <meta charset='utf-8' />", async () => {
// let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");

// expect(await app.getHtml('meta[charset="utf-8"]')).toBeTruthy();
// await enableJavaScript();
// });

// test("meta { title } adds a <title />", async () => {
// let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");

// expect(await app.getHtml("title")).toBeTruthy();
// await enableJavaScript();
// });

// test("meta { 'og:*' } adds a <meta property='og:*' />", async () => {
// let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");

// expect(await app.getHtml('meta[property="og:image"]')).toBeTruthy();
// await enableJavaScript();
// });

// test("meta { description } adds a <meta name='description' />", async () => {
// let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");

// expect(await app.getHtml('meta[name="description"]')).toBeTruthy();
// await enableJavaScript();
// });

// test("meta { refresh } adds a <meta http-equiv='refresh' content='3;url=https://www.mozilla.org' />", async () => {
// let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");

// expect(
// await app.getHtml(
// 'meta[http-equiv="refresh"][content="3;url=https://www.mozilla.org"]'
// )
// ).toBeTruthy();
// await enableJavaScript();
// });
// });

describe("meta array-syntax", () => {
let fixture: Fixture;
let app: AppFixture;

beforeAll(async () => {
fixture = await createFixture({
files: {
"app/root.jsx": js`
import { json, Meta, Links, Outlet, Scripts } from "remix";
import { json } from "@remix-run/node";
import { Links, Meta, Outlet, Scripts } from "@remix-run/react";
export const loader = async () =>
json({
Expand All @@ -259,22 +125,32 @@ describe("meta array-syntax", () => {
{ name: "description", content: data.description },
{ property: "og:image", content: "https://picsum.photos/200/200" },
{ property: "og:type", content: data.contentType }, // undefined
{ key: "http-equiv:refresh", httpEquiv: "refresh", content: "3;url=https://www.mozilla.org" },
{ key: "title", content: data.title },
{ key: "httpEquiv:refresh", httpEquiv: "refresh", content: "3;url=https://www.mozilla.org" },
{ title: data.title },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
];
export default function Root() {
return (
<html lang="en">
<head>
<Meta />
</head>
<head>
<Meta />
<Links />
</head>
<body>
<Outlet />
<Scripts />
</body>
</html>
);
}
`,

"app/routes/index.jsx": js`
export const meta = ({ data }) => [
{ title: 'Override Title' },
];
export default function Index() {
return <div>This is the index file</div>;
}
Expand All @@ -291,60 +167,68 @@ describe("meta array-syntax", () => {
let enableJavaScript = await app.disableJavaScript();

await app.goto("/");
let head = await app.getHtml("head");
console.log(head);

await expect(app.getHtml('meta[property="og:type"]')).rejects.toThrowError(
'No element matches selector "meta[property="og:type"]"'
);
await enableJavaScript();
});

// test("meta { charset } adds a <meta charset='utf-8' />", async () => {
// let enableJavaScript = await app.disableJavaScript();
test("meta { charset } adds a <meta charset='utf-8' />", async () => {
let enableJavaScript = await app.disableJavaScript();

await app.goto("/");

expect(await app.getHtml('meta[charset="utf-8"]')).toBeTruthy();
await enableJavaScript();
});

test("meta { title } adds a <title />", async () => {
let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");
await app.goto("/");

// expect(await app.getHtml('meta[charset="utf-8"]')).toBeTruthy();
// await enableJavaScript();
// });
expect(await app.getHtml("title")).toBeTruthy();
await enableJavaScript();
});

// test("meta { title } adds a <title />", async () => {
// let enableJavaScript = await app.disableJavaScript();
test("meta { title } overrides a <title />", async () => {
let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");
await app.goto("/");

// expect(await app.getHtml("title")).toBeTruthy();
// await enableJavaScript();
// });
expect(await app.getHtml("title")).toBe("<title>Override Title</title>");
await enableJavaScript();
});

// test("meta { 'og:*' } adds a <meta property='og:*' />", async () => {
// let enableJavaScript = await app.disableJavaScript();
test("meta { 'og:*' } adds a <meta property='og:*' />", async () => {
let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");
await app.goto("/");

// expect(await app.getHtml('meta[property="og:image"]')).toBeTruthy();
// await enableJavaScript();
// });
expect(await app.getHtml('meta[property="og:image"]')).toBeTruthy();
await enableJavaScript();
});

// test("meta { description } adds a <meta name='description' />", async () => {
// let enableJavaScript = await app.disableJavaScript();
test("meta { description } adds a <meta name='description' />", async () => {
let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");
await app.goto("/");

// expect(await app.getHtml('meta[name="description"]')).toBeTruthy();
// await enableJavaScript();
// });
expect(await app.getHtml('meta[name="description"]')).toBeTruthy();
await enableJavaScript();
});

// test("meta { refresh } adds a <meta http-equiv='refresh' content='3;url=https://www.mozilla.org' />", async () => {
// let enableJavaScript = await app.disableJavaScript();
test("meta { refresh } adds a <meta http-equiv='refresh' content='3;url=https://www.mozilla.org' />", async () => {
let enableJavaScript = await app.disableJavaScript();

// await app.goto("/");
await app.goto("/");

// expect(
// await app.getHtml(
// 'meta[http-equiv="refresh"][content="3;url=https://www.mozilla.org"]'
// )
// ).toBeTruthy();
// await enableJavaScript();
// });
expect(
await app.getHtml(
'meta[http-equiv="refresh"][content="3;url=https://www.mozilla.org"]'
)
).toBeTruthy();
await enableJavaScript();
});
});

0 comments on commit c969879

Please sign in to comment.