Skip to content

Commit

Permalink
test: improve view transition e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Oct 17, 2024
1 parent 8765cd4 commit 1946e59
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
import { ViewTransitions } from 'astro:transitions';
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/components";
interface Props {
title: string;
Expand All @@ -21,16 +20,6 @@ const { title } = Astro.props;
<ViewTransitions />
</head>
<body>
<header>
<nav>
<SignedOut>
<a href="/sign-in">Sign In</a>
</SignedOut>
<SignedIn>
<UserButton />
</SignedIn>
</nav>
</header>
<main>
<slot />
</main>
Expand Down
15 changes: 15 additions & 0 deletions integration/templates/astro-node/src/pages/transitions/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
import { SignedIn, SignedOut, UserButton } from "@clerk/astro/components";
import Layout from "../../layouts/ViewTransitionsLayout.astro";
---

<Layout title="Sign in">
<div class="w-full flex justify-center">
<SignedOut>
<a href="/transitions/sign-in">Sign in</a>
</SignedOut>
<SignedIn>
<UserButton />
</SignedIn>
</div>
</Layout>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import Layout from "../../layouts/ViewTransitionsLayout.astro";

<Layout title="Sign in">
<div class="w-full flex justify-center">
<SignIn forceRedirectUrl="/transitions/profile" />
<SignIn forceRedirectUrl="/transitions" />
</div>
</Layout>
18 changes: 16 additions & 2 deletions integration/tests/astro/components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,17 @@ testAgainstRunningApps({ withPattern: ['astro.node.withCustomRoles'] })('basic f
await expect(u.page.getByText('Not a member')).toBeVisible();
});

test('renders components when view transitions is enabled', async ({ page, context }) => {
test('renders components and keep internal routing behavior when view transitions is enabled', async ({
page,
context,
}) => {
const u = createTestUtils({ app, page, context });
await u.page.goToRelative('/transitions/sign-in');
await u.page.goToRelative('/transitions');
await u.page.getByRole('link', { name: /Sign in/i }).click();

// Components should be rendered on the new document
// when navigating through links
await u.page.waitForURL(`${app.serverUrl}/transitions/sign-in`);
await u.po.signIn.waitForMounted();

await u.po.signIn.setIdentifier(fakeAdmin.email);
Expand All @@ -465,5 +473,11 @@ testAgainstRunningApps({ withPattern: ['astro.node.withCustomRoles'] })('basic f
await u.po.signIn.continue();

await u.po.expect.toBeSignedIn();

// Internal Clerk routing should still work
await u.page.waitForURL(`${app.serverUrl}/transitions`);

// Components should be rendered on hard reload
await u.po.userButton.waitForMounted();
});
});
4 changes: 2 additions & 2 deletions packages/astro/src/internal/swap-document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-unresolved
import { swapFunctions } from 'astro:transitions/client';
// @ts-expect-error: todo
import { swapFunctions } from 'astro/virtual-modules/transitions-swap-functions.js';

const PERSIST_ATTR = 'data-astro-transition-persist';
const EMOTION_ATTR = 'data-emotion';
Expand Down

0 comments on commit 1946e59

Please sign in to comment.