Skip to content

Commit

Permalink
run gui tests in PR checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Nov 10, 2024
1 parent c111402 commit 38298c6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pr_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
79 changes: 79 additions & 0 deletions gui/src/components/dialogs/ConfirmationDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<Provider store={store}>
<ConfirmationDialog {...props} />
</Provider>,
);
};

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);
});
});
8 changes: 5 additions & 3 deletions gui/src/pages/history/history.test.tsx
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -15,6 +15,8 @@ vi.mock("react-router-dom", async () => {
describe("history Page test", () => {
it("History text is existed after render", () => {
renderWithProviders(<HistoryPage />);
expect(screen.getByText("History")).toBeInTheDocument();
expect(
screen.getByText("All session data is saved in ~/.continue/sessions"),
).toBeInTheDocument();
});
});

0 comments on commit 38298c6

Please sign in to comment.