Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions prompt-manager/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ const config = {
}),
testEnvironment: "jsdom",
transform: {
"^.+.tsx?$": ["ts-jest", {}],
"^.+\\.(ts|tsx|js|jsx)$": ["ts-jest", {
useESM: true,
isolatedModules: true
}],
},
transformIgnorePatterns: [
"node_modules/(?!(@plasmohq|pify)/)"
],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node", "mjs"],
// Add this to tell Jest to mock this module
moduleDirectories: ["node_modules", "<rootDir>"]
}

export default config
export default config
4 changes: 4 additions & 0 deletions prompt-manager/tests/mocks/storageMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Mock implementation of @plasmohq/storage/hook
export const useStorage = jest.fn().mockImplementation((key, initialValue) => {
return [initialValue, jest.fn()]
})
60 changes: 60 additions & 0 deletions prompt-manager/tests/popup/IndexPopup.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, expect, it, jest } from "@jest/globals";
import { render, screen, fireEvent } from "@testing-library/react";
import IndexPopup from "~popup";
import { usePrompts } from "~hooks/usePrompts";

jest.mock("~hooks/usePrompts", () => ({
usePrompts: jest.fn()
}));

describe("IndexPopup - Saving and Searching Prompts", () => {
const mockSetPrompts = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
(usePrompts as jest.Mock).mockReturnValue({
prompts: [],
setPrompts: mockSetPrompts
});
});

describe("Saving Prompts", () => {
it("should add a new prompt when save button is clicked", () => {
render(<IndexPopup />);

const promptInput = screen.getByPlaceholderText("Enter Prompt");
fireEvent.change(promptInput, { target: { value: "New Test Prompt" } });

const saveButton = screen.getByText("Save Prompt");
fireEvent.click(saveButton);

expect(mockSetPrompts).toHaveBeenCalled();
});

it("should not add a prompt if the input is empty", () => {
render(<IndexPopup />);

const saveButton = screen.getByText("Save Prompt");
fireEvent.click(saveButton);

expect(mockSetPrompts).not.toHaveBeenCalled();
});
});

describe("Searching Prompts", () => {
it("should render search input", () => {
(usePrompts as jest.Mock).mockReturnValue({
prompts: [
{ title: "Work Prompt", prompt: "This is for work", tags: ["work"], category: "Work" },
{ title: "Personal Prompt", prompt: "This is personal", tags: ["personal"], category: "Personal" }
],
setPrompts: mockSetPrompts
});

render(<IndexPopup />);

const searchInput = screen.getByPlaceholderText("Search Saved Prompt");
expect(searchInput).toBeTruthy();
});
});
});