Some checks failed
CI — Test & Build / Test & Build (push) Failing after 39s
- Added a new "Prompt Builder" tab in the Popup for generating AI prompts with customizable parameters. - Introduced new state variables for managing prompt styles, personas, formats, and models. - Enhanced the Options page to fetch and display models based on the provided API key. - Updated the actions and types to include the new 'prompt' action and its associated parameters. - Implemented migration logic for legacy plaintext API keys to encrypted storage. - Updated the getSystemPrompt function to incorporate prompt parameters for better instruction generation. - Added tests for the new functionality, including context menu entries and prompt generation logic.
53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
ACTIONS,
|
|
ACTION_LABELS,
|
|
WRITING_STYLES,
|
|
CONTEXT_MENU_STYLES,
|
|
CONTEXT_MENU_ENTRIES,
|
|
findContextMenuEntry,
|
|
} from '@lib/actions';
|
|
|
|
describe('context-menu registry', () => {
|
|
it('contains one parent per action + style children for all actions except prompt', () => {
|
|
const styledActions = ACTIONS.filter((a) => a !== 'prompt');
|
|
expect(CONTEXT_MENU_ENTRIES).toHaveLength(ACTIONS.length + styledActions.length * CONTEXT_MENU_STYLES.length);
|
|
expect(CONTEXT_MENU_ENTRIES.filter((e) => !e.parentId)).toHaveLength(ACTIONS.length);
|
|
// prompt is a single item — its parameters live in the Prompt Builder dialog
|
|
expect(CONTEXT_MENU_ENTRIES.filter((e) => e.parentId === 'lexai-prompt')).toHaveLength(0);
|
|
});
|
|
|
|
it('every parent precedes its children (contextMenus.create ordering)', () => {
|
|
CONTEXT_MENU_ENTRIES.forEach((entry, i) => {
|
|
if (entry.parentId) {
|
|
const parentIndex = CONTEXT_MENU_ENTRIES.findIndex((e) => e.id === entry.parentId);
|
|
expect(parentIndex).toBeGreaterThanOrEqual(0);
|
|
expect(parentIndex).toBeLessThan(i);
|
|
}
|
|
});
|
|
});
|
|
|
|
it('maps every previous menu id to the same action/style as the old split("-") parser', () => {
|
|
// The old parser: strip 'lexai-', split on '-', capitalize the style part.
|
|
for (const action of ACTIONS) {
|
|
const parent = findContextMenuEntry(`lexai-${action}`);
|
|
expect(parent).toMatchObject({ action, style: 'Default' });
|
|
expect(parent!.title).toBe(`⚡ LexAI: ${ACTION_LABELS[action]}`);
|
|
|
|
if (action === 'prompt') continue; // no style children — see registry comment
|
|
for (const style of CONTEXT_MENU_STYLES) {
|
|
const child = findContextMenuEntry(`lexai-${action}-${style.toLowerCase()}`);
|
|
expect(child).toMatchObject({ action, style, parentId: `lexai-${action}`, title: style });
|
|
}
|
|
}
|
|
});
|
|
|
|
it('returns undefined for foreign menu ids', () => {
|
|
expect(findContextMenuEntry('some-other-extension-item')).toBeUndefined();
|
|
});
|
|
|
|
it('style lists stay consistent', () => {
|
|
expect(CONTEXT_MENU_STYLES).toEqual(WRITING_STYLES.filter((s) => s !== 'Default'));
|
|
});
|
|
});
|