feat: phase 1 of python scripting
This commit is contained in:
137
tests/engine/ScriptEngine.test.ts
Normal file
137
tests/engine/ScriptEngine.test.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import * as fs from 'fs/promises';
|
||||
import { ScriptEngine } from '../../src/main/engine/ScriptEngine';
|
||||
|
||||
const mockScripts = new Map<string, any>();
|
||||
const mockFiles = new Map<string, string>();
|
||||
|
||||
function createSelectChain() {
|
||||
return {
|
||||
from: vi.fn().mockReturnThis(),
|
||||
where: vi.fn().mockReturnThis(),
|
||||
orderBy: vi.fn().mockReturnThis(),
|
||||
all: vi.fn().mockImplementation(() => Promise.resolve(Array.from(mockScripts.values()))),
|
||||
get: vi.fn().mockImplementation(() => Promise.resolve(undefined)),
|
||||
};
|
||||
}
|
||||
|
||||
function createDrizzleMock() {
|
||||
return {
|
||||
select: vi.fn(() => createSelectChain()),
|
||||
insert: vi.fn(() => ({
|
||||
values: vi.fn((data: any) => {
|
||||
mockScripts.set(data.id, data);
|
||||
return Promise.resolve();
|
||||
}),
|
||||
})),
|
||||
update: vi.fn(() => ({
|
||||
set: vi.fn((updates: any) => ({
|
||||
where: vi.fn(async () => {
|
||||
for (const [scriptId, existing] of mockScripts.entries()) {
|
||||
mockScripts.set(scriptId, { ...existing, ...updates });
|
||||
}
|
||||
}),
|
||||
})),
|
||||
})),
|
||||
delete: vi.fn(() => ({
|
||||
where: vi.fn(async () => {
|
||||
mockScripts.clear();
|
||||
return Promise.resolve();
|
||||
}),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
const mockLocalDb = createDrizzleMock();
|
||||
|
||||
vi.mock('../../src/main/database', () => ({
|
||||
getDatabase: vi.fn(() => ({
|
||||
getLocal: vi.fn(() => mockLocalDb),
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock('uuid', () => ({
|
||||
v4: vi.fn(() => 'mock-script-id'),
|
||||
}));
|
||||
|
||||
vi.mock('fs/promises', () => ({
|
||||
readFile: vi.fn(async (filePath: string) => {
|
||||
const value = (globalThis as any).__mockScriptFiles.get(filePath);
|
||||
if (typeof value !== 'string') {
|
||||
const error = new Error('ENOENT');
|
||||
(error as any).code = 'ENOENT';
|
||||
throw error;
|
||||
}
|
||||
return value;
|
||||
}),
|
||||
writeFile: vi.fn(async (filePath: string, content: string) => {
|
||||
(globalThis as any).__mockScriptFiles.set(filePath, content);
|
||||
}),
|
||||
unlink: vi.fn(async (filePath: string) => {
|
||||
(globalThis as any).__mockScriptFiles.delete(filePath);
|
||||
}),
|
||||
rename: vi.fn(async (fromPath: string, toPath: string) => {
|
||||
const files = (globalThis as any).__mockScriptFiles;
|
||||
const content = files.get(fromPath);
|
||||
files.delete(fromPath);
|
||||
files.set(toPath, content);
|
||||
}),
|
||||
mkdir: vi.fn(async () => {}),
|
||||
}));
|
||||
|
||||
describe('ScriptEngine', () => {
|
||||
let scriptEngine: ScriptEngine;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockScripts.clear();
|
||||
mockFiles.clear();
|
||||
(globalThis as any).__mockScriptFiles = mockFiles;
|
||||
vi.mocked(mockLocalDb.select).mockImplementation(() => createSelectChain());
|
||||
|
||||
scriptEngine = new ScriptEngine();
|
||||
scriptEngine.setProjectContext('default', '/mock/userData/projects/default');
|
||||
});
|
||||
|
||||
it('creates script metadata and source file', async () => {
|
||||
const created = await scriptEngine.createScript({
|
||||
title: 'Render Hero',
|
||||
kind: 'macro',
|
||||
content: 'def render(context):\n return {"html": "<h1>Hi</h1>"}',
|
||||
});
|
||||
|
||||
expect(created.slug).toBe('render-hero');
|
||||
expect(mockScripts.has(created.id)).toBe(true);
|
||||
expect(mockFiles.get('/mock/userData/projects/default/scripts/render-hero.py')).toContain('def render');
|
||||
});
|
||||
|
||||
it('updates script metadata and file content', async () => {
|
||||
const created = await scriptEngine.createScript({
|
||||
title: 'Render Hero',
|
||||
kind: 'macro',
|
||||
content: 'def render(context):\n return {"html": "<h1>Hi</h1>"}',
|
||||
});
|
||||
|
||||
const updated = await scriptEngine.updateScript(created.id, {
|
||||
title: 'Render Hero Banner',
|
||||
content: 'def render(context):\n return {"html": "<h1>Banner</h1>"}',
|
||||
});
|
||||
|
||||
expect(updated?.slug).toBe('render-hero-banner');
|
||||
expect(mockFiles.get('/mock/userData/projects/default/scripts/render-hero-banner.py')).toContain('Banner');
|
||||
});
|
||||
|
||||
it('deletes script metadata and source file', async () => {
|
||||
const created = await scriptEngine.createScript({
|
||||
title: 'Delete Me',
|
||||
kind: 'utility',
|
||||
content: 'print("bye")',
|
||||
});
|
||||
|
||||
const deleted = await scriptEngine.deleteScript(created.id);
|
||||
|
||||
expect(deleted).toBe(true);
|
||||
expect(mockScripts.has(created.id)).toBe(false);
|
||||
expect(mockFiles.has('/mock/userData/projects/default/scripts/delete-me.py')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -158,6 +158,16 @@ const mockPostMediaEngine = {
|
||||
rebuildFromSidecars: vi.fn(),
|
||||
};
|
||||
|
||||
const mockScriptEngine = {
|
||||
on: vi.fn(),
|
||||
setProjectContext: vi.fn(),
|
||||
createScript: vi.fn(),
|
||||
updateScript: vi.fn(),
|
||||
deleteScript: vi.fn(),
|
||||
getScript: vi.fn(),
|
||||
getAllScripts: vi.fn(),
|
||||
};
|
||||
|
||||
const mockGitEngine = {
|
||||
checkAvailability: vi.fn(),
|
||||
getHeadCommit: vi.fn(),
|
||||
@@ -263,6 +273,10 @@ vi.mock('../../src/main/engine/PostMediaEngine', () => ({
|
||||
getPostMediaEngine: vi.fn(() => mockPostMediaEngine),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/main/engine/ScriptEngine', () => ({
|
||||
getScriptEngine: vi.fn(() => mockScriptEngine),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/main/engine/GitEngine', () => ({
|
||||
getGitEngine: vi.fn(() => mockGitEngine),
|
||||
}));
|
||||
@@ -2593,6 +2607,113 @@ describe('IPC Handlers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ============ Script Handlers ============
|
||||
describe('Script Handlers', () => {
|
||||
describe('scripts:create', () => {
|
||||
it('should call ScriptEngine.createScript with payload', async () => {
|
||||
const payload = {
|
||||
title: 'Render Hero',
|
||||
kind: 'macro',
|
||||
content: 'def render(context):\n return {"html":"<h1>Hi</h1>"}',
|
||||
};
|
||||
const expected = {
|
||||
id: 'script-1',
|
||||
projectId: 'default',
|
||||
...payload,
|
||||
slug: 'render-hero',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
version: 1,
|
||||
filePath: '/mock/userData/projects/default/scripts/render-hero.py',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
mockScriptEngine.createScript.mockResolvedValue(expected);
|
||||
|
||||
const result = await invokeHandler('scripts:create', payload);
|
||||
|
||||
expect(mockScriptEngine.createScript).toHaveBeenCalledWith(payload);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('scripts:update', () => {
|
||||
it('should call ScriptEngine.updateScript with id and updates', async () => {
|
||||
const updates = { title: 'Updated Script', content: 'print("updated")' };
|
||||
const expected = {
|
||||
id: 'script-1',
|
||||
projectId: 'default',
|
||||
slug: 'updated-script',
|
||||
title: 'Updated Script',
|
||||
kind: 'utility',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
version: 2,
|
||||
filePath: '/mock/userData/projects/default/scripts/updated-script.py',
|
||||
content: 'print("updated")',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
mockScriptEngine.updateScript.mockResolvedValue(expected);
|
||||
|
||||
const result = await invokeHandler('scripts:update', 'script-1', updates);
|
||||
|
||||
expect(mockScriptEngine.updateScript).toHaveBeenCalledWith('script-1', updates);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('scripts:delete', () => {
|
||||
it('should call ScriptEngine.deleteScript with id', async () => {
|
||||
mockScriptEngine.deleteScript.mockResolvedValue(true);
|
||||
|
||||
const result = await invokeHandler('scripts:delete', 'script-1');
|
||||
|
||||
expect(mockScriptEngine.deleteScript).toHaveBeenCalledWith('script-1');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('scripts:get', () => {
|
||||
it('should call ScriptEngine.getScript with id', async () => {
|
||||
const expected = {
|
||||
id: 'script-1',
|
||||
projectId: 'default',
|
||||
slug: 'render-hero',
|
||||
title: 'Render Hero',
|
||||
kind: 'macro',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
version: 1,
|
||||
filePath: '/mock/userData/projects/default/scripts/render-hero.py',
|
||||
content: 'def render(context):\n return {"html":"<h1>Hi</h1>"}',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
mockScriptEngine.getScript.mockResolvedValue(expected);
|
||||
|
||||
const result = await invokeHandler('scripts:get', 'script-1');
|
||||
|
||||
expect(mockScriptEngine.getScript).toHaveBeenCalledWith('script-1');
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('scripts:getAll', () => {
|
||||
it('should call ScriptEngine.getAllScripts', async () => {
|
||||
const expected = [{ id: 'script-1' }, { id: 'script-2' }];
|
||||
mockScriptEngine.getAllScripts.mockResolvedValue(expected);
|
||||
|
||||
const result = await invokeHandler('scripts:getAll');
|
||||
|
||||
expect(mockScriptEngine.getAllScripts).toHaveBeenCalled();
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// ============ Error Handling ============
|
||||
describe('Error Handling', () => {
|
||||
it('should silently handle "Database is closing" errors', async () => {
|
||||
|
||||
@@ -235,6 +235,24 @@ describe('Panel', () => {
|
||||
expect(screen.getByRole('tab', { name: 'Output' })).toHaveAttribute('aria-selected', 'true');
|
||||
});
|
||||
|
||||
it('renders output entries when output tab is active', () => {
|
||||
useAppStore.setState({
|
||||
panelActiveTab: 'output',
|
||||
panelOutputEntries: [
|
||||
{
|
||||
id: 'output-1',
|
||||
message: 'hello from script',
|
||||
createdAt: '2026-02-22T00:00:00.000Z',
|
||||
kind: 'stdout',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(<Panel />);
|
||||
|
||||
expect(screen.getByText('hello from script')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders grouped tasks as expandable parent rows with child task names in tasks tab', async () => {
|
||||
useAppStore.setState({
|
||||
tasks: [
|
||||
|
||||
23
tests/renderer/components/ScriptsView.styles.test.ts
Normal file
23
tests/renderer/components/ScriptsView.styles.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
describe('ScriptsView styles', () => {
|
||||
const cssPath = path.resolve(
|
||||
__dirname,
|
||||
'../../../src/renderer/components/ScriptsView/ScriptsView.css'
|
||||
);
|
||||
|
||||
it('uses full editor area layout for the scripts container', () => {
|
||||
const css = fs.readFileSync(cssPath, 'utf8');
|
||||
|
||||
expect(css).toMatch(/\.scripts-view\s*\{[^}]*flex:\s*1;[^}]*min-height:\s*0;[^}]*\}/s);
|
||||
});
|
||||
|
||||
it('keeps editor and textarea stretched to fill available space', () => {
|
||||
const css = fs.readFileSync(cssPath, 'utf8');
|
||||
|
||||
expect(css).toMatch(/\.scripts-editor\s*\{[^}]*flex:\s*1;[^}]*min-height:\s*0;[^}]*\}/s);
|
||||
expect(css).toMatch(/\.scripts-textarea\s*\{[^}]*flex:\s*1;[^}]*min-height:\s*0;[^}]*\}/s);
|
||||
});
|
||||
});
|
||||
80
tests/renderer/components/ScriptsView.test.tsx
Normal file
80
tests/renderer/components/ScriptsView.test.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { ScriptsView } from '../../../src/renderer/components/ScriptsView/ScriptsView';
|
||||
import { useAppStore } from '../../../src/renderer/store';
|
||||
|
||||
const executeMock = vi.fn();
|
||||
|
||||
vi.mock('../../../src/renderer/python/runtimeManagerInstance', () => ({
|
||||
getPythonRuntimeManager: () => ({
|
||||
execute: executeMock,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('ScriptsView', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
executeMock.mockResolvedValue({ result: '2', stdout: 'hello\n' });
|
||||
|
||||
(window as any).electronAPI = {
|
||||
...(window as any).electronAPI,
|
||||
scripts: {
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
get: vi.fn().mockResolvedValue({
|
||||
id: 'script-1',
|
||||
projectId: 'default',
|
||||
slug: 'hello-script',
|
||||
title: 'Hello Script',
|
||||
kind: 'utility',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
version: 1,
|
||||
filePath: '/tmp/hello-script.py',
|
||||
content: 'print("hello")',
|
||||
createdAt: '2026-02-22T00:00:00.000Z',
|
||||
updatedAt: '2026-02-22T00:00:00.000Z',
|
||||
}),
|
||||
getAll: vi.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
useAppStore.setState({
|
||||
panelVisible: false,
|
||||
panelActiveTab: 'tasks',
|
||||
panelOutputEntries: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('loads scripts and allows editing content', async () => {
|
||||
render(<ScriptsView scriptId="script-1" />);
|
||||
|
||||
const textarea = screen.getByLabelText('Script Content') as HTMLTextAreaElement;
|
||||
await vi.waitFor(() => {
|
||||
expect(textarea.value).toContain('print("hello")');
|
||||
});
|
||||
|
||||
fireEvent.change(textarea, { target: { value: 'print("updated")' } });
|
||||
expect(textarea.value).toContain('updated');
|
||||
});
|
||||
|
||||
it('runs selected script and writes output into panel output log', async () => {
|
||||
render(<ScriptsView scriptId="script-1" />);
|
||||
|
||||
await screen.findByLabelText('Script Content');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Run Script' }));
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(executeMock).toHaveBeenCalledWith('print("hello")');
|
||||
});
|
||||
|
||||
const state = useAppStore.getState();
|
||||
expect(state.panelVisible).toBe(true);
|
||||
expect(state.panelActiveTab).toBe('output');
|
||||
expect(state.panelOutputEntries.length).toBeGreaterThan(0);
|
||||
expect(state.panelOutputEntries[state.panelOutputEntries.length - 1].message).toContain('hello');
|
||||
});
|
||||
});
|
||||
147
tests/renderer/components/SidebarScripts.test.tsx
Normal file
147
tests/renderer/components/SidebarScripts.test.tsx
Normal file
@@ -0,0 +1,147 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { Sidebar } from '../../../src/renderer/components/Sidebar/Sidebar';
|
||||
import { useAppStore } from '../../../src/renderer/store';
|
||||
|
||||
describe('Sidebar scripts list behavior', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
(window as any).electronAPI = {
|
||||
...(window as any).electronAPI,
|
||||
scripts: {
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
get: vi.fn(),
|
||||
getAll: vi.fn().mockResolvedValue([
|
||||
{
|
||||
id: 'script-1',
|
||||
projectId: 'default',
|
||||
slug: 'hello-script',
|
||||
title: 'Hello Script',
|
||||
kind: 'utility',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
version: 1,
|
||||
filePath: '/tmp/hello-script.py',
|
||||
content: 'print("hello")',
|
||||
createdAt: '2026-02-22T00:00:00.000Z',
|
||||
updatedAt: '2026-02-22T00:00:00.000Z',
|
||||
},
|
||||
]),
|
||||
},
|
||||
};
|
||||
|
||||
useAppStore.setState({
|
||||
activeView: 'scripts',
|
||||
sidebarVisible: true,
|
||||
tabs: [],
|
||||
activeTabId: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('opens a transient script tab on single click', async () => {
|
||||
render(<Sidebar />);
|
||||
|
||||
const scriptRow = await screen.findByRole('button', { name: 'Hello Script' });
|
||||
fireEvent.click(scriptRow);
|
||||
|
||||
expect(useAppStore.getState().tabs).toEqual([
|
||||
{
|
||||
type: 'scripts',
|
||||
id: 'script-1',
|
||||
isTransient: true,
|
||||
},
|
||||
]);
|
||||
expect(useAppStore.getState().activeTabId).toBe('script-1');
|
||||
});
|
||||
|
||||
it('renders scripts section title and create button', async () => {
|
||||
render(<Sidebar />);
|
||||
|
||||
expect(screen.getByText('SCRIPTS')).toBeInTheDocument();
|
||||
expect(await screen.findByRole('button', { name: 'New Script' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows loading state while scripts are being fetched', () => {
|
||||
(window as any).electronAPI.scripts.getAll = vi.fn().mockImplementation(
|
||||
() => new Promise(() => {}),
|
||||
);
|
||||
|
||||
render(<Sidebar />);
|
||||
|
||||
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows empty state with create action when no scripts exist', async () => {
|
||||
(window as any).electronAPI.scripts.getAll = vi.fn().mockResolvedValue([]);
|
||||
|
||||
render(<Sidebar />);
|
||||
|
||||
expect(await screen.findByText('No scripts yet')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Create a script' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('creates a new script from the create button and opens it pinned', async () => {
|
||||
const createMock = vi.fn().mockResolvedValue({
|
||||
id: 'script-new',
|
||||
projectId: 'default',
|
||||
slug: 'new-script',
|
||||
title: 'New Script',
|
||||
kind: 'utility',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
version: 1,
|
||||
filePath: '/tmp/new-script.py',
|
||||
content: 'print("new script")',
|
||||
createdAt: '2026-02-22T00:00:00.000Z',
|
||||
updatedAt: '2026-02-22T00:00:00.000Z',
|
||||
});
|
||||
|
||||
(window as any).electronAPI.scripts.create = createMock;
|
||||
|
||||
render(<Sidebar />);
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'New Script' }));
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(createMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
title: 'New Script',
|
||||
kind: 'utility',
|
||||
entrypoint: 'render',
|
||||
enabled: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(useAppStore.getState().tabs).toEqual([
|
||||
{
|
||||
type: 'scripts',
|
||||
id: 'script-new',
|
||||
isTransient: false,
|
||||
},
|
||||
]);
|
||||
expect(useAppStore.getState().activeTabId).toBe('script-new');
|
||||
});
|
||||
});
|
||||
|
||||
it('opens a pinned script tab on double click', async () => {
|
||||
render(<Sidebar />);
|
||||
|
||||
const scriptRow = await screen.findByRole('button', { name: 'Hello Script' });
|
||||
fireEvent.doubleClick(scriptRow);
|
||||
|
||||
expect(useAppStore.getState().tabs).toEqual([
|
||||
{
|
||||
type: 'scripts',
|
||||
id: 'script-1',
|
||||
isTransient: false,
|
||||
},
|
||||
]);
|
||||
expect(useAppStore.getState().activeTabId).toBe('script-1');
|
||||
});
|
||||
});
|
||||
@@ -87,7 +87,20 @@ describe('activityBehavior', () => {
|
||||
});
|
||||
|
||||
it('supports all expected activity ids', () => {
|
||||
const ids: ActivityId[] = ['posts', 'pages', 'media', 'tags', 'chat', 'import', 'git', 'settings'];
|
||||
expect(ids).toHaveLength(8);
|
||||
const ids: ActivityId[] = ['posts', 'pages', 'media', 'scripts', 'tags', 'chat', 'import', 'git', 'settings'];
|
||||
expect(ids).toHaveLength(9);
|
||||
});
|
||||
|
||||
it('returns posts-style sidebar actions for scripts', () => {
|
||||
const hiddenSidebarSnapshot = createSnapshot({ activeView: 'posts', sidebarVisible: false });
|
||||
expect(getActivityClickActions(hiddenSidebarSnapshot, 'scripts')).toEqual([
|
||||
{ type: 'setActiveView', view: 'scripts' },
|
||||
{ type: 'toggleSidebar' },
|
||||
]);
|
||||
|
||||
const visibleSidebarSnapshot = createSnapshot({ activeView: 'posts', sidebarVisible: true });
|
||||
expect(getActivityClickActions(visibleSidebarSnapshot, 'scripts')).toEqual([
|
||||
{ type: 'setActiveView', view: 'scripts' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ describe('editorRouting', () => {
|
||||
'git-diff': 'git-diff',
|
||||
documentation: 'documentation',
|
||||
'site-validation': 'site-validation',
|
||||
scripts: 'scripts',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ describe('sidebarViewRegistry', () => {
|
||||
'posts',
|
||||
'pages',
|
||||
'media',
|
||||
'scripts',
|
||||
'settings',
|
||||
'tags',
|
||||
'chat',
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
getGitDiffCommitTabSpec,
|
||||
getGitDiffFileTabSpec,
|
||||
getImportTabSpec,
|
||||
getScriptTabSpec,
|
||||
parseGitDiffTabId,
|
||||
openChatTab,
|
||||
getSingletonToolTabSpec,
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
openGitDiffCommitTab,
|
||||
openGitDiffFileTab,
|
||||
openImportTab,
|
||||
openScriptTab,
|
||||
openSingletonToolTab,
|
||||
} from '../../../src/renderer/navigation/tabPolicy';
|
||||
|
||||
@@ -20,6 +22,7 @@ describe('tabPolicy', () => {
|
||||
expect(getSingletonToolTabSpec('settings')).toEqual({ type: 'settings', id: 'settings', isTransient: false });
|
||||
expect(getSingletonToolTabSpec('tags')).toEqual({ type: 'tags', id: 'tags', isTransient: false });
|
||||
expect(getSingletonToolTabSpec('style')).toEqual({ type: 'style', id: 'style', isTransient: false });
|
||||
expect(getSingletonToolTabSpec('scripts')).toEqual({ type: 'scripts', id: 'scripts', isTransient: false });
|
||||
expect(getSingletonToolTabSpec('menu-editor')).toEqual({ type: 'menu-editor', id: 'menu-editor', isTransient: false });
|
||||
expect(getSingletonToolTabSpec('documentation')).toEqual({ type: 'documentation', id: 'documentation', isTransient: false });
|
||||
expect(getSingletonToolTabSpec('metadata-diff')).toEqual({ type: 'metadata-diff', id: 'metadata-diff', isTransient: false });
|
||||
@@ -93,6 +96,35 @@ describe('tabPolicy', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('provides canonical script tab spec for preview and pin intents', () => {
|
||||
expect(getScriptTabSpec('script-1', 'preview')).toEqual({
|
||||
type: 'scripts',
|
||||
id: 'script-1',
|
||||
isTransient: true,
|
||||
});
|
||||
|
||||
expect(getScriptTabSpec('script-1', 'pin')).toEqual({
|
||||
type: 'scripts',
|
||||
id: 'script-1',
|
||||
isTransient: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('opens script tabs from shared policy', () => {
|
||||
const opened: Array<{ type: string; id: string; isTransient: boolean }> = [];
|
||||
const openTab = (tab: { type: string; id: string; isTransient: boolean }) => {
|
||||
opened.push(tab);
|
||||
};
|
||||
|
||||
openScriptTab(openTab, 'script-preview', 'preview');
|
||||
openScriptTab(openTab, 'script-pin', 'pin');
|
||||
|
||||
expect(opened).toEqual([
|
||||
{ type: 'scripts', id: 'script-preview', isTransient: true },
|
||||
{ type: 'scripts', id: 'script-pin', isTransient: false },
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds and parses git-diff file and commit tab specs', () => {
|
||||
expect(getGitDiffFileTabSpec('posts/first.md', 'preview')).toEqual({
|
||||
type: 'git-diff',
|
||||
|
||||
@@ -22,4 +22,10 @@ describe('vite renderer chunking', () => {
|
||||
const resolved = typeof viteConfig === 'function' ? viteConfig({ command: 'build', mode: 'production', isSsrBuild: false, isPreview: false }) : viteConfig;
|
||||
expect(resolved.build?.chunkSizeWarningLimit).toBe(8000);
|
||||
});
|
||||
|
||||
it('excludes pyodide from optimizeDeps pre-bundling', () => {
|
||||
const resolved = typeof viteConfig === 'function' ? viteConfig({ command: 'serve', mode: 'development', isSsrBuild: false, isPreview: false }) : viteConfig;
|
||||
const excluded = resolved.optimizeDeps?.exclude ?? [];
|
||||
expect(excluded).toContain('pyodide');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user