Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions packages/elements/__tests__/inline-citation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,39 @@ describe("inlineCitationCardTrigger", () => {
);
expect(screen.getByText("unknown")).toBeInTheDocument();
});

it("renders raw source for a bare domain without a scheme", () => {
expect(() =>
render(
<InlineCitationCard>
<InlineCitationCardTrigger sources={["example.com/nlp"]} />
</InlineCitationCard>
)
).not.toThrow();
expect(screen.getByText("example.com/nlp")).toBeInTheDocument();
});

it("renders raw source for a relative path", () => {
expect(() =>
render(
<InlineCitationCard>
<InlineCitationCardTrigger sources={["/nlp-advances"]} />
</InlineCitationCard>
)
).not.toThrow();
expect(screen.getByText("/nlp-advances")).toBeInTheDocument();
});

it("renders raw source for a non-URL string", () => {
expect(() =>
render(
<InlineCitationCard>
<InlineCitationCardTrigger sources={["not a url"]} />
</InlineCitationCard>
)
).not.toThrow();
expect(screen.getByText("not a url")).toBeInTheDocument();
});
});

describe("inlineCitationCardBody", () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/elements/src/inline-citation.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import { Badge } from "@repo/shadcn-ui/components/ui/badge";
import type { CarouselApi } from "@repo/shadcn-ui/components/ui/carousel";
import type { ComponentProps } from "react";

import { Badge } from "@repo/shadcn-ui/components/ui/badge";
import {
Carousel,
CarouselContent,
Expand All @@ -14,7 +16,6 @@ import {
} from "@repo/shadcn-ui/components/ui/hover-card";
import { cn } from "@repo/shadcn-ui/lib/utils";
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
import type { ComponentProps } from "react";
import {
createContext,
useCallback,
Expand Down Expand Up @@ -70,7 +71,7 @@ export const InlineCitationCardTrigger = ({
>
{sources[0] ? (
<>
{new URL(sources[0]).hostname}{" "}
{URL.canParse(sources[0]) ? new URL(sources[0]).hostname : sources[0]}{" "}
{sources.length > 1 && `+${sources.length - 1}`}
</>
) : (
Expand Down