Skip to content

Commit

Permalink
test: isolate Playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Dec 13, 2024
1 parent 3228dc0 commit def7990
Show file tree
Hide file tree
Showing 36 changed files with 1,233 additions and 852 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { notFound } from "next/navigation";
import { NotFoundError, isFilled } from "@prismicio/client";
import { PrismicNextImage } from "@prismicio/next";
import { isFilled } from "@prismicio/client";
import assert from "assert";

import { createClient } from "@/prismicio";

export default async function Page() {
const client = createClient();
const { data: tests } = await client.getSingle("image_test");
type Params = { uid: string };

export default async function Page({ params }: { params: Promise<Params> }) {
const { uid } = await params;

const client = await createClient();
const { data: tests } = await client
.getByUID("image_test", uid)
.catch((error) => {
if (error instanceof NotFoundError) notFound();
throw error;
});

assert(
isFilled.image(tests.with_alt_text) && tests.with_alt_text.alt !== null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import Link from "next/link";
import { isFilled } from "@prismicio/client";
import { notFound } from "next/navigation";
import { NotFoundError, isFilled } from "@prismicio/client";
import { PrismicNextLink } from "@prismicio/next";
import assert from "assert";

import { createClient } from "@/prismicio";

export default async function Page() {
const client = createClient();
const { data: tests } = await client.getSingle("link_test");
type Params = { uid: string };

export default async function Page({ params }: { params: Promise<Params> }) {
const { uid } = await params;

const client = await createClient({
routes: [{ type: "page", path: "/:uid" }],
});
const { data: tests } = await client
.getByUID("link_test", uid)
.catch((error) => {
if (error instanceof NotFoundError) notFound();
throw error;
});
assert(isFilled.contentRelationship(tests.document) && tests.document.url);
const doc = await client.getByID(tests.document.id);
console.log({ doc: JSON.stringify(doc) });

assert(isFilled.linkToMedia(tests.media));
assert(
Expand Down
16 changes: 7 additions & 9 deletions e2e-projects/app-router/app/[uid]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { PrismicPreview } from "@prismicio/next";
import { NotFoundError } from "@prismicio/client";
import { PrismicPreview } from "@prismicio/next";
import { notFound } from "next/navigation";

import { createClient, repositoryName } from "@/prismicio";
import { createClient } from "@/prismicio";

type Params = { uid: string };

export default async function Page({
params,
}: {
params: Promise<{ uid: string }>;
}) {
export default async function Page({ params }: { params: Promise<Params> }) {
const { uid } = await params;

const client = createClient();
const client = await createClient();
const page = await client.getByUID("page", uid).catch((error) => {
if (error instanceof NotFoundError) notFound();
throw error;
Expand All @@ -20,7 +18,7 @@ export default async function Page({
return (
<>
<div data-testid="payload">{page.data.payload}</div>
<PrismicPreview repositoryName={repositoryName} />
<PrismicPreview repositoryName={client.repositoryName} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { exitPreview } from "@prismicio/next";

/** This endpoint exits a preview session. */
export function GET() {
return exitPreview();
}
5 changes: 3 additions & 2 deletions e2e-projects/app-router/app/api/custom-preview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { redirectToPreviewURL } from "@prismicio/next";

import { createClient } from "@/prismicio";

/** This endpoint handles previews that are launched from the Page Builder. */
export async function GET(request: NextRequest) {
const client = createClient();
const client = await createClient({
routes: [{ type: "page", path: "/:uid" }],
});

return await redirectToPreviewURL({ client, request });
}
1 change: 0 additions & 1 deletion e2e-projects/app-router/app/api/exit-preview/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { exitPreview } from "@prismicio/next";

/** This endpoint exits a preview session. */
export function GET() {
return exitPreview();
}
5 changes: 3 additions & 2 deletions e2e-projects/app-router/app/api/preview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { redirectToPreviewURL } from "@prismicio/next";

import { createClient } from "@/prismicio";

/** This endpoint handles previews that are launched from the Page Builder. */
export async function GET(request: NextRequest) {
const client = createClient();
const client = await createClient({
routes: [{ type: "page", path: "/:uid" }],
});

return await redirectToPreviewURL({ client, request });
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@ import { NotFoundError } from "@prismicio/client";
import { PrismicPreview } from "@prismicio/next";
import { notFound } from "next/navigation";

import { createClient, repositoryName } from "@/prismicio";
import { createClient } from "@/prismicio";

export default async function Page({
params,
}: {
params: Promise<{ uid: string }>;
}) {
type Params = { uid: string };

export default async function Page({ params }: { params: Promise<Params> }) {
const { uid } = await params;

const client = createClient();
const client = await createClient();
const page = await client.getByUID("page", uid).catch((error) => {
if (error instanceof NotFoundError) {
console.log(error.url);
notFound();
}
if (error instanceof NotFoundError) notFound();
throw error;
});

return (
<>
<div data-testid="payload">{page.data.payload}</div>
<PrismicPreview
repositoryName={repositoryName}
repositoryName={client.repositoryName}
updatePreviewURL="/api/custom-preview"
exitPreviewURL="/api/custom-exit-preview"
/>
Expand Down
Loading

0 comments on commit def7990

Please sign in to comment.