Skip to content

Commit

Permalink
Update test files
Browse files Browse the repository at this point in the history
  • Loading branch information
m2rads committed Oct 20, 2024
1 parent 2514510 commit b90e21d
Showing 1 changed file with 8 additions and 37 deletions.
45 changes: 8 additions & 37 deletions app/(dashboard)/dashboard/pull-request.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { vi, describe, it, expect, beforeEach } from "vitest";
import { PullRequest } from "./types";
import useSWR from "swr";
import { fetchBuildStatus } from "@/lib/github";
import { experimental_useObject as useObject } from "ai/react";
import { act } from "react";

vi.mock("@/lib/github", async () => {
const actual = await vi.importActual("@/lib/github");
Expand Down Expand Up @@ -48,14 +46,6 @@ vi.mock("./log-view", () => ({
LogView: () => <div data-testid="log-view">Mocked Log View</div>,
}));

vi.mock("./log-view", () => ({
LogView: () => <div data-testid="log-view">Mocked Log View</div>,
}));

vi.mock("ai/react", () => ({
experimental_useObject: vi.fn(),
}));

describe("PullRequestItem", () => {
const mockPullRequest: PullRequest = {
id: 1,
Expand Down Expand Up @@ -84,11 +74,6 @@ describe("PullRequestItem", () => {
isValidating: false,
isLoading: false,
});
vi.mocked(useObject).mockReturnValue({
object: null,
submit: vi.fn(),
isLoading: false,
});
});

it("renders the pull request information correctly", () => {
Expand Down Expand Up @@ -157,8 +142,6 @@ describe("PullRequestItem", () => {
);
});

// Verify that fetchBuildStatus is called with the correct parameters

expect(fetchBuildStatusMock).toHaveBeenCalledWith(
mockPullRequest.repository.owner.login,
mockPullRequest.repository.name,
Expand All @@ -178,16 +161,6 @@ describe("PullRequestItem", () => {
"https://github.com/commit/123"
);

const mockSubmit = vi.fn();
vi.mocked(useObject).mockReturnValue({
object: null,
submit: mockSubmit,
isLoading: false,
setInput: vi.fn(),
error: null,
stop: vi.fn(),
});

const mutate = vi.fn();
vi.mocked(useSWR).mockReturnValue({
data: mockPullRequest,
Expand All @@ -197,6 +170,13 @@ describe("PullRequestItem", () => {
isLoading: false,
});

global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve({
tests: [{ name: "generated_test.ts", content: "generated content" }]
})
});

render(<PullRequestItem pullRequest={mockPullRequest} />);

const writeTestsButton = screen.getByText("Write new tests");
Expand All @@ -206,15 +186,6 @@ describe("PullRequestItem", () => {
expect(screen.getByText("Analyzing PR diff...")).toBeInTheDocument();
});

await act(async () => {
const { onFinish } = vi.mocked(useObject).mock.calls[0][0];
await onFinish({
object: {
tests: [{ name: "generated_test.ts", content: "generated content" }],
},
});
});

await waitFor(() => {

Check failure on line 189 in app/(dashboard)/dashboard/pull-request.test.tsx

View workflow job for this annotation

GitHub Actions / test

app/(dashboard)/dashboard/pull-request.test.tsx > PullRequestItem > triggers revalidation after committing changes

TestingLibraryElementError: Unable to find an element with the text: generated_test.ts. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible. Ignored nodes: comments, script, style <body> <div> <div class="bg-white p-4 rounded-lg shadow-md" > <div class="flex items-center justify-between mb-2" > <span class="flex items-center" > <svg class="lucide lucide-git-pull-request mr-2 h-4 w-4" fill="none" height="24" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" > <circle cx="18" cy="18" r="3" /> <circle cx="6" cy="6" r="3" /> <path d="M13 6h3a2 2 0 0 1 2 2v7" /> <line x1="6" x2="6" y1="9" y2="21" /> </svg> <span class="font-medium" > Test PR </span> </span> <a href="https://github.com/owner/test-repo/pull/123" > # 123 </a> </div> <div class="flex items-center justify-between" > <span class="flex items-center" > <svg class="lucide lucide-circle-check-big mr-2 h-4 w-4 text-green-500" fill="none" height="24" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" > <path d="M21.801 10A10 10 0 1 1 17 3.335" /> <path d="m9 11 3 3L22 4" /> </svg> <a href="https://github.com/owner/test-repo/pull/123/checks" > Build: success </a> <button class="flex items-center space-x-1 px-2 py-1 text-sm text-gray-600 hover:text-gray-900 transition-colors duration-100 ease-in-out" > <span> Show Logs </span> <span class="relative w-4 h-4" > <svg class="lucide lucide-chevron-up absolute inset-0 h-4 w-4 transition-opacity duration-100 opacity-0" fill="none" height="24" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" > <path d="m18 15-6-6-6 6" /> </svg> <svg class="lucide lucide-chevron-down absolute inset-0 h-4 w-4 transition-opacity duration-100 opacity-100" fill="none" height="24" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" > <path d="m6 9 6 6 6-6" /> </svg> </span> </button> </span> <button class="inline-flex items-center justify-center whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none
expect(screen.getByText("generated_test.ts")).toBeInTheDocument();
});
Expand Down Expand Up @@ -260,4 +231,4 @@ describe("PullRequestItem", () => {
expect(screen.getByText("Show Logs")).toBeInTheDocument();
});
});
});
});

0 comments on commit b90e21d

Please sign in to comment.