quivr/frontend/app/user/components/ApiKeyConfig/__tests__/ApiKeyConfig.test.tsx
Nick Guernsey 253e866a86
feat: enhance user page UI (#1319)
# Description

Hope ya'll don't mind, I updated the User Profile's UI to be a bit more
readable. Kept the design neutral to not impose styles.

I also kept the original toggle buttons for Theme and Language in case
we still want to use those in other places in the app, where a select
menu isn't necessary.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):


https://github.com/StanGirard/quivr/assets/64866427/d0320852-ece1-4002-a180-0005df132e71


https://github.com/StanGirard/quivr/assets/64866427/be3c67ec-8d42-44f9-8131-35a70aec20ef

---------

Co-authored-by: Zineb El Bachiri <100568984+gozineb@users.noreply.github.com>
Co-authored-by: Stan Girard <girard.stanislas@gmail.com>
2023-10-05 17:50:02 +02:00

55 lines
1.8 KiB
TypeScript

import { fireEvent, render } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ApiKeyConfig } from "../ApiKeyConfig";
const handleCreateClickMock = vi.fn(() => ({}));
const handleCopyClickMock = vi.fn(() => ({}));
const useApiKeyConfigMock = vi.fn(() => ({
apiKey: "",
handleCreateClick: () => handleCreateClickMock(),
handleCopyClick: () => handleCopyClickMock(),
}));
vi.mock("../hooks/useApiKeyConfig", () => ({
useApiKeyConfig: () => useApiKeyConfigMock(),
}));
describe("ApiKeyConfig", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("should render ApiConfig Component", () => {
const { getByTestId } = render(<ApiKeyConfig />);
expect(getByTestId("create-new-key")).toBeDefined();
expect(getByTestId("open-ai-api-key-input")).toBeDefined();
expect(getByTestId("save-open-ai-api-key")).toBeDefined();
});
it("renders 'Create New Key' button when apiKey is empty", () => {
const { getByTestId } = render(<ApiKeyConfig />);
const createButton = getByTestId("create-new-key");
expect(createButton).toBeDefined();
fireEvent.click(createButton);
expect(handleCreateClickMock).toHaveBeenCalledTimes(1);
expect(handleCreateClickMock).toHaveBeenCalledWith();
});
it('renders "Copy" button when apiKey is not empty', () => {
useApiKeyConfigMock.mockReturnValue({
apiKey: "123456789",
handleCreateClick: () => handleCreateClickMock(),
handleCopyClick: () => handleCopyClickMock(),
});
const { getByTestId } = render(<ApiKeyConfig />);
const copyButton = getByTestId("copy-api-key-button");
expect(copyButton).toBeDefined();
fireEvent.click(copyButton);
expect(handleCopyClickMock).toHaveBeenCalledTimes(1);
});
});