Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2e78eef
Create IndexPopup.test.tsx
iadeyefa Apr 11, 2025
137d030
Update IndexPopup.test.tsx
iadeyefa Apr 11, 2025
aa2982f
Update jest.config.mjs
iadeyefa Apr 11, 2025
b98def0
Update jest.config.mjs
iadeyefa Apr 11, 2025
286ea9d
Create mock storage hook
iadeyefa Apr 11, 2025
3c0ae2f
Update jest.config.mjs
iadeyefa Apr 11, 2025
639bb24
Update Prompt.ts
barnesrj Apr 12, 2025
c674354
Create get-tab-url.ts
barnesrj Apr 12, 2025
38a2e64
Create get-tab-url.ts
barnesrj Apr 12, 2025
b5f3e32
Update popup.tsx
barnesrj Apr 12, 2025
c5ff347
Update Prompt.ts
barnesrj Apr 12, 2025
5799a04
Update get-tab-url.ts
barnesrj Apr 14, 2025
3402373
Update popup.tsx
barnesrj Apr 14, 2025
f737dcb
Update popup.tsx
barnesrj Apr 14, 2025
e5653e4
Delete prompt-manager/utils/get-tab-url.ts
barnesrj Apr 14, 2025
d758af1
Delete prompt-manager/utils/prompt-manager/utils/get-tab-url.ts
barnesrj Apr 14, 2025
e837e15
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 14, 2025
bd64f51
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
panda Apr 18, 2025
d7100e9
Update usePrompts.test.ts
barnesrj Apr 18, 2025
94d3e71
Update PromptList.test.tsx
barnesrj Apr 18, 2025
75056cd
Update usePrompts.test.ts
barnesrj Apr 18, 2025
021f0ed
Update usePrompts.test.ts
barnesrj Apr 18, 2025
4aeb2d9
Update promptUtils.test.ts
barnesrj Apr 18, 2025
1cea80f
Update PromptList.test.tsx
barnesrj Apr 18, 2025
2563d4c
Update PromptListItem.test.tsx
barnesrj Apr 18, 2025
f62c975
Update Prompt.ts
barnesrj Apr 18, 2025
951de6d
Update Prompt.ts
barnesrj Apr 18, 2025
7ad7508
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 19, 2025
5f0642e
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 19, 2025
c4a3d91
Update promptUtils.ts
barnesrj Apr 19, 2025
06a22ac
Update package.json
barnesrj Apr 19, 2025
14c2d56
Update package.json to use correct host_permissions
panda Apr 19, 2025
48c8612
Merge pull request #98 from PromptManager/fix-permissions-package
panda Apr 19, 2025
13cbf72
Merge branch 'dev' into barnesrj-patch-1
JonCGroberg Apr 19, 2025
c4f8402
Update popup test file
iadeyefa Apr 21, 2025
0cb9599
Update jest config
iadeyefa Apr 21, 2025
f4f8d78
Update popup test file
iadeyefa Apr 21, 2025
3e00476
Merge branch 'dev' into 85-create-test-for-prompt-saving-and-searchin…
iadeyefa Apr 21, 2025
baf0b93
Merge pull request #99 from PromptManager/85-create-test-for-prompt-s…
iadeyefa Apr 21, 2025
a9b2b18
Merge branch 'dev' into barnesrj-patch-1
barnesrj Apr 22, 2025
8a9f399
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 25, 2025
ef0456f
Merge pull request #86 from PromptManager/32-store-timestamps-and-pla…
barnesrj Apr 25, 2025
dc47c12
Merge branch 'dev' into barnesrj-patch-1
panda Apr 25, 2025
edcd01e
Merge pull request #97 from PromptManager/barnesrj-patch-1
panda Apr 25, 2025
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
12 changes: 7 additions & 5 deletions prompt-manager/interface/Prompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface Prompt {
title: string;
prompt: string;
tags: string[];
category?: string;
}
title: string;
prompt: string;
tags: string[];
category?: string;
createdAt: Date;
website: string;
}
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
9 changes: 8 additions & 1 deletion prompt-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
{
"name": "Ife Adeyefa",
"email": "iadeyefa@ufl.edu"
},
{
"name": "Robert Barens",
"email": "rjbarnes@ufl.edu"
}
],
"scripts": {
Expand Down Expand Up @@ -45,7 +49,10 @@
},
"manifest": {
"host_permissions": [
"https://*/*"
"https://chatgpt.com/*",
"https://chat.chatgpt.com/*",
"https://deepseek.com/*",
"https://chat.deepseek.com/*"
],
"permissions": [
"storage",
Expand Down
35 changes: 24 additions & 11 deletions prompt-manager/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { usePrompts } from "~hooks/usePrompts"
import { ImportBtn } from "~components/ImportBtn";
import { ExportBtn } from "~components/ExportBtn";


function IndexPopup() {
const { prompts, setPrompts } = usePrompts();
const [userInput, setUserInput] = useState("")
Expand All @@ -25,19 +26,31 @@ function IndexPopup() {
}
}, [prompts])

const savePrompt = () => {
if (userInput.trim() !== "") {
const newPrompt: Prompt = {
title: "",
tags: [],
prompt: userInput,
category: currentCategory
}
const savePrompt = async () => {
if (userInput.trim() !== "") {
let website = ""

try {
website = await useCurrentTabUrl()
} catch (err) {
console.error("Could not get tab URL:", err)
website = "unknown"
}

setPrompts((existingPrompts) => [...existingPrompts, newPrompt])
setUserInput("")
const newPrompt: Prompt = {
title: "",
tags: [],
prompt: userInput,
category: currentCategory,
createdAt: new Date(),
website
}

setPrompts((existingPrompts) => [...existingPrompts, newPrompt])
setUserInput("")
}
}


const createNewCategory = () => {
if (newCategory.trim() !== "" && !categories.includes(newCategory)) {
Expand Down Expand Up @@ -171,4 +184,4 @@ function IndexPopup() {
)
}

export default IndexPopup
export default IndexPopup
12 changes: 9 additions & 3 deletions prompt-manager/tests/components/PromptList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ const mockPromptListData: Prompt[] = [
{
title: "Sample Prompt",
prompt: "This is a sample prompt description.",
tags: ["Test Tag"]
tags: ["Test Tag"],
createdAt: new Date(),
website: "https://chatgpt.com/"
},
{
title: "Another Prompt",
prompt: "This is another sample prompt description.",
tags: ["Another Tag"]
tags: ["Another Tag"],
createdAt: new Date(),
website: "https://chatgpt.com/"
},
{
title: "Searchable Prompt",
prompt: "This prompt is meant to be found.",
tags: ["Search Tag"]
tags: ["Search Tag"],
createdAt: new Date(),
website: "https://chatgpt.com/"
}
];

Expand Down
2 changes: 2 additions & 0 deletions prompt-manager/tests/components/PromptListItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const mockPrompt: Prompt = {
title: "Test Prompt",
prompt: "This is a test prompt description.",
tags: ["Tag1", "Tag2"],
createdAt: new Date(),
website: "https://chatgpt.com/"
};

describe("PromptListItem", () => {
Expand Down
9 changes: 7 additions & 2 deletions prompt-manager/tests/hooks/usePrompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jest.mock("@plasmohq/storage/hook", () => ({
useStorage: jest.fn()
}))

const newPrompt = { title: "Test Title", prompt: "Test Prompt", tags: [] }
const newPrompt = { title: "Test Title", prompt: "Test Prompt", tags: [], createdAt: new Date(),
website: "https://chatgpt.com/" }

describe("usePrompts", () => {
it("should return an empty array as the initial value for prompts", () => {
Expand All @@ -26,7 +27,11 @@ describe("usePrompts", () => {

it("should return the stored prompts from the list if they exist", () => {
const mockPrompts: Prompt[] = [
{ title: "Test Title", prompt: "Test Prompt", tags: [] }
{ title: "Test Title",
prompt: "Test Prompt",
tags: [],
createdAt: new Date(),
website: "https://chatgpt.com/" }
]
const mockUseStorage = jest.fn(() => [mockPrompts, jest.fn()])
;(useStorage as jest.Mock).mockImplementation(mockUseStorage)
Expand Down
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();
});
});
});
8 changes: 5 additions & 3 deletions prompt-manager/tests/utils/promptUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { Prompt } from "~interface/Prompt";

describe("promptUtils", () => {
const mockPrompts: Prompt[] = [
{ title: "Test Prompt", prompt: "This is a test prompt.", tags: ["Tag1"] },
{ title: "Another Prompt", prompt: "This is another test prompt.", tags: ["Tag2"] },
{ title: "Test Prompt", prompt: "This is a test prompt.", tags: ["Tag1"], createdAt: new Date(),
website: "https://chatgpt.com/" },
{ title: "Another Prompt", prompt: "This is another test prompt.", tags: ["Tag2"], createdAt: new Date(),
website: "https://chatgpt.com/" },
];

beforeEach(() => {
Expand Down Expand Up @@ -52,4 +54,4 @@ describe("promptUtils", () => {
expect(mockClick).toHaveBeenCalledTimes(1);
expect(mockRevokeObjectURL).toHaveBeenCalledWith(mockCreateObjectURL.mock.results[0].value);
});
});
});
8 changes: 6 additions & 2 deletions prompt-manager/utils/promptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export function importPrompts(file: File): Promise<Prompt[]> {
reader.onload = (event) => {
try {
const result = event.target?.result as string;
const importedPrompts: Prompt[] = JSON.parse(result);
const rawPrompts = JSON.parse(result);
const importedPrompts: Prompt[] = rawPrompts.map((p: any) => ({
...p,
createdAt: new Date(p.createdAt)
}));
resolve(importedPrompts);
} catch (error) {
reject(new Error("Invalid JSON file"));
Expand All @@ -43,4 +47,4 @@ export function importPrompts(file: File): Promise<Prompt[]> {

reader.readAsText(file);
});
}
}