mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-18 08:02:03 +03:00
b0514d6149
* add libraries for traslation purposes * Add button and service for language selection * add spanish translation on login page * add spanish translation on upload page * Add spanish translations for explore page * Add translations on user page * Add translations for config page * Add spanish translations on chat page * add translations for brain page * fix GUI and save on local storage * fix (i18n) init and types * fix (i18n): typos * add translation on new brain modal * add translations on metadata * Add translations on home page * fixes types * fix(frontend-tests): use get by id instead of text --------- Co-authored-by: Gustavo Maciel <gustavo_m13@outlook.com>
56 lines
1.8 KiB
TypeScript
56 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-key-divider")).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);
|
|
});
|
|
});
|