memos/web/tests/auth-page-layout.test.tsx
boojack 564da949cb chore(auth): redesign sign-in and sign-up pages with panel layout
Rebuild the auth pages around a shared AuthPageLayout card with a
three-tier guidance hierarchy: the form (or provider buttons) on top,
a centered switch sentence below it, and a quiet explore band anchored
to the card foot on public instances.

- add AuthPageLayout (brand row, chip, empty state, link prompt,
  explore band gated by instance URL with hideExplore opt-out)
- extract CredentialFields shared by sign-in and sign-up forms
- extract IdentityProviderButtons; fetch the provider list via a
  cached TanStack Query hook with an enabled flag
- cover every instance config: SSO-only, password-only, registrations
  closed, private instance, nothing enabled, first-run setup, admin
- promote /auth/signup, /auth/admin, /auth/callback to ROUTES and add
  appendSearchParams for param-preserving auth links
- move the explore link out of AuthFooter (selectors only now)
- refresh en and zh-Hans auth strings; drop dead keys
2026-07-13 19:40:31 +08:00

52 lines
1.6 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { beforeEach, describe, expect, it, vi } from "vitest";
import AuthPageLayout from "@/components/AuthPageLayout";
const instance = vi.hoisted(() => ({ instanceUrl: "" }));
vi.mock("@/contexts/InstanceContext", () => ({
useInstance: () => ({ profile: instance, generalSetting: {} }),
}));
vi.mock("@/utils/i18n", () => ({
useTranslate: () => (key: string) => key,
loadLocale: vi.fn(),
}));
vi.mock("@/components/AuthFooter", () => ({ default: () => <div data-testid="auth-footer" /> }));
const renderLayout = (props?: { hideExplore?: boolean }) =>
render(
<MemoryRouter>
<AuthPageLayout title="Sign in" {...props}>
<div />
</AuthPageLayout>
</MemoryRouter>,
);
describe("<AuthPageLayout> explore band", () => {
beforeEach(() => {
instance.instanceUrl = "";
});
it("links to Explore on public instances", () => {
instance.instanceUrl = "https://demo.example.com";
renderLayout();
expect(screen.getByRole("link", { name: /auth\.explore-public-memos/ })).toHaveAttribute("href", "/explore");
});
it("omits the band on private instances", () => {
renderLayout();
expect(screen.queryByRole("link", { name: /auth\.explore-public-memos/ })).not.toBeInTheDocument();
});
it("omits the band when hideExplore is set (first-run setup)", () => {
instance.instanceUrl = "https://demo.example.com";
renderLayout({ hideExplore: true });
expect(screen.queryByRole("link", { name: /auth\.explore-public-memos/ })).not.toBeInTheDocument();
});
});