From 38298c6ca37e8e5729bc5820c1d668ba0fe11993 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Nov 2024 15:08:55 -0800 Subject: [PATCH] run gui tests in PR checks --- .github/workflows/pr_checks.yaml | 7 +- .../dialogs/ConfirmationDialog.test.tsx | 79 +++++++++++++++++++ gui/src/pages/history/history.test.tsx | 8 +- 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 gui/src/components/dialogs/ConfirmationDialog.test.tsx diff --git a/.github/workflows/pr_checks.yaml b/.github/workflows/pr_checks.yaml index 30c63ad7d6..a879c3d9da 100644 --- a/.github/workflows/pr_checks.yaml +++ b/.github/workflows/pr_checks.yaml @@ -105,4 +105,9 @@ jobs: - name: Run core tests run: | cd core - npm run test + npm test + + - name: Run gui tests + run: | + cd gui + npm test diff --git a/gui/src/components/dialogs/ConfirmationDialog.test.tsx b/gui/src/components/dialogs/ConfirmationDialog.test.tsx new file mode 100644 index 0000000000..d426791de7 --- /dev/null +++ b/gui/src/components/dialogs/ConfirmationDialog.test.tsx @@ -0,0 +1,79 @@ +import { configureStore } from "@reduxjs/toolkit"; +import { fireEvent, render, screen } from "@testing-library/react"; +import { Provider } from "react-redux"; +import { describe, expect, it, vi } from "vitest"; +import { uiStateSlice } from "../../redux/slices/uiStateSlice"; +import ConfirmationDialog from "./ConfirmationDialog"; + +const createMockStore = () => { + return configureStore({ + reducer: { + uiState: uiStateSlice.reducer, + }, + }); +}; + +describe("ConfirmationDialog", () => { + const renderDialog = (props: any) => { + const store = createMockStore(); + return render( + + + , + ); + }; + + it("renders with default props", () => { + const onConfirm = vi.fn(); + renderDialog({ text: "Are you sure?", onConfirm }); + + expect(screen.getByText("Confirmation")).toBeInTheDocument(); + expect(screen.getByText("Are you sure?")).toBeInTheDocument(); + expect(screen.getByText("Cancel")).toBeInTheDocument(); + expect(screen.getByText("Confirm")).toBeInTheDocument(); + }); + + it("renders with custom title and confirm text", () => { + const onConfirm = vi.fn(); + renderDialog({ + text: "Delete item?", + title: "Custom Title", + confirmText: "Delete", + onConfirm, + }); + + expect(screen.getByText("Custom Title")).toBeInTheDocument(); + expect(screen.getByText("Delete item?")).toBeInTheDocument(); + expect(screen.getByText("Delete")).toBeInTheDocument(); + }); + + it("hides cancel button when hideCancelButton is true", () => { + const onConfirm = vi.fn(); + renderDialog({ + text: "Proceed?", + hideCancelButton: true, + onConfirm, + }); + + expect(screen.queryByText("Cancel")).not.toBeInTheDocument(); + }); + + it("calls onConfirm and dispatches actions when confirm button is clicked", () => { + const onConfirm = vi.fn(); + renderDialog({ text: "Confirm action?", onConfirm }); + + fireEvent.click(screen.getByText("Confirm")); + + expect(onConfirm).toHaveBeenCalledTimes(1); + }); + + it("calls onCancel and dispatches actions when cancel button is clicked", () => { + const onConfirm = vi.fn(); + const onCancel = vi.fn(); + renderDialog({ text: "Cancel action?", onConfirm, onCancel }); + + fireEvent.click(screen.getByText("Cancel")); + + expect(onCancel).toHaveBeenCalledTimes(1); + }); +}); diff --git a/gui/src/pages/history/history.test.tsx b/gui/src/pages/history/history.test.tsx index fa6e6e8891..f739220cb1 100644 --- a/gui/src/pages/history/history.test.tsx +++ b/gui/src/pages/history/history.test.tsx @@ -1,6 +1,6 @@ -import HistoryPage from "./index"; -import { renderWithProviders } from "../../util/test/render"; import { screen } from "@testing-library/dom"; +import { renderWithProviders } from "../../util/test/render"; +import HistoryPage from "./index"; const navigateFn = vi.fn(); @@ -15,6 +15,8 @@ vi.mock("react-router-dom", async () => { describe("history Page test", () => { it("History text is existed after render", () => { renderWithProviders(); - expect(screen.getByText("History")).toBeInTheDocument(); + expect( + screen.getByText("All session data is saved in ~/.continue/sessions"), + ).toBeInTheDocument(); }); });