Files
kandev/apps/web/components/sentry/sentry-issue-dialog.test.tsx
T
João Salavisa 409fdcd3da feat(i18n): localize the Azure DevOps, Jira, Linear and Sentry task surfaces (#2284)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 17:42:20 +02:00

128 lines
4.3 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { listSentryProjects, searchSentryIssues } from "@/lib/api/domains/sentry-api";
import { useSentryInstances } from "@/hooks/domains/sentry/use-sentry-availability";
import type { SentryConfig } from "@/lib/types/sentry";
vi.mock("@/lib/api/domains/sentry-api", () => ({
listSentryProjects: vi.fn(),
searchSentryIssues: vi.fn(),
}));
vi.mock("@/hooks/domains/sentry/use-sentry-availability", () => ({
useSentryInstances: vi.fn(),
}));
import { SentryIssueDialog } from "./sentry-issue-dialog";
const instance: SentryConfig = {
id: "shared-instance",
workspaceId: "workspace-1",
name: "Production",
authMethod: "auth_token",
url: "https://sentry.example.com",
hasSecret: true,
lastOk: true,
createdAt: "2026-01-01T00:00:00Z",
updatedAt: "2026-01-01T00:00:00Z",
};
function mockAvailability() {
vi.mocked(useSentryInstances).mockReturnValue({
loading: false,
instances: [instance],
healthy: [instance],
available: true,
state: "single",
});
}
afterEach(() => {
cleanup();
vi.clearAllMocks();
});
describe("SentryIssueDialog", () => {
it("clears filters and results when its workspace changes", async () => {
mockAvailability();
vi.mocked(listSentryProjects).mockResolvedValue({
projects: [{ id: "project-1", slug: "web", name: "Web", orgSlug: "acme" }],
} as never);
vi.mocked(searchSentryIssues).mockResolvedValue({
issues: [
{
id: "issue-1",
shortId: "WEB-1",
title: "Stale workspace issue",
permalink: "https://sentry.example.com/issues/1",
projectSlug: "web",
level: "error",
status: "unresolved",
},
],
isLast: true,
} as never);
const view = render(
<SentryIssueDialog open={true} onOpenChange={vi.fn()} workspaceId="workspace-1" />,
);
await waitFor(() => {
expect((screen.getByLabelText("Organization") as HTMLInputElement).value).toBe("acme");
});
fireEvent.change(screen.getByLabelText("Query"), { target: { value: "is:unresolved" } });
fireEvent.click(screen.getByRole("button", { name: "Search" }));
await screen.findByText("Stale workspace issue");
view.rerender(
<SentryIssueDialog open={true} onOpenChange={vi.fn()} workspaceId="workspace-2" />,
);
expect((screen.getByLabelText("Query") as HTMLInputElement).value).toBe("");
expect(screen.queryByText("Stale workspace issue")).toBeNull();
});
it("clears a stuck loading state when a workspace change interrupts an in-flight search", async () => {
mockAvailability();
vi.mocked(listSentryProjects).mockResolvedValue({
projects: [{ id: "project-1", slug: "web", name: "Web", orgSlug: "acme" }],
} as never);
const pendingSearch = new Promise<never>(() => {});
vi.mocked(searchSentryIssues).mockReturnValue(pendingSearch);
const view = render(
<SentryIssueDialog open={true} onOpenChange={vi.fn()} workspaceId="workspace-1" />,
);
await waitFor(() => {
expect((screen.getByLabelText("Organization") as HTMLInputElement).value).toBe("acme");
});
fireEvent.click(screen.getByRole("button", { name: "Search" }));
await waitFor(() => {
expect(document.querySelector(".animate-spin")).not.toBeNull();
});
view.rerender(
<SentryIssueDialog open={true} onOpenChange={vi.fn()} workspaceId="workspace-2" />,
);
expect(document.querySelector(".animate-spin")).toBeNull();
});
// The query placeholder is Sentry search syntax the user copies. It must stay
// outside the catalog: a translated `is:` or `release:` is invalid syntax and
// silently returns nothing. Only the surrounding "e.g." wrapper is localized.
it("keeps the Sentry query syntax out of the translated placeholder", async () => {
mockAvailability();
vi.mocked(listSentryProjects).mockResolvedValue({
projects: [{ id: "project-1", slug: "web", name: "Web", orgSlug: "acme" }],
} as never);
render(<SentryIssueDialog open={true} onOpenChange={vi.fn()} workspaceId="workspace-1" />);
const query = await screen.findByLabelText("Query");
expect(query.getAttribute("placeholder")).toContain("is:unresolved release:1.2.3");
});
});