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
4 changes: 3 additions & 1 deletion src/components/workspace/ProjectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function close() { operation++; emit('close') }
watch(() => props.open, open => { operation++; if (open) { title.value = editor.figure.value.title; error.value = '' } })
function save() {
if (!title.value.trim()) { error.value = '请输入工程名称'; return }
editor.update(doc => { doc.title = title.value.trim() }); editor.save(); close()
editor.update(doc => { doc.title = title.value.trim() })
if (!editor.save()) { error.value = editor.storageError.value; return }
close()
}
function loadExample() {
operation++
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ export function createEditor() {
past.value.push(clone(figure.value)); figure.value = next; future.value = future.value.slice(0, -1); selectedId.value = 'stage'
}
function save() {
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(figure.value)); saved.value = true; storageError.value = ''; notice.value = '工程已保存到当前浏览器' }
catch { storageError.value = '本地保存失败,请导出工程文件保存。'; notice.value = storageError.value }
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(figure.value)); saved.value = true; storageError.value = ''; notice.value = '工程已保存到当前浏览器'; return true }
catch { saved.value = false; storageError.value = '本地保存失败,请导出工程文件保存。'; notice.value = storageError.value; return false }
}
function importProject(text: string) {
if (new TextEncoder().encode(text).length > maxProjectBytes) throw new Error('工程文件过大,限制为 8 MB')
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/project-save.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import assert from 'node:assert/strict';

export async function checkProjectSave({ page }) {
await page.getByRole('button', { name: '工程', exact: true }).click();
const dialog = page.getByRole('dialog', { name: '工程管理', exact: true });
const title = 'Retry after private browser storage failure';
await dialog.getByRole('textbox', { name: '工程名称', exact: true }).fill(title);
await page.evaluate(() => {
const setItem = Storage.prototype.setItem;
window.__restoreProjectStorage = () => { Storage.prototype.setItem = setItem; };
Storage.prototype.setItem = function(key, value) {
if (key === 'fastfigure.project.v2') throw new DOMException('Storage is full', 'QuotaExceededError');
return setItem.call(this, key, value);
};
});
try {
await dialog.getByRole('button', { name: '保存工程', exact: true }).click();
assert(await dialog.isVisible(), 'A failed save must leave the project dialog open');
await dialog.getByRole('alert').waitFor();
assert.equal(await dialog.getByRole('textbox', { name: '工程名称', exact: true }).inputValue(), title);
const [download] = await Promise.all([page.waitForEvent('download'), dialog.getByRole('button', { name: '备份 JSON', exact: true }).click()]);
const chunks = [];
for await (const chunk of await download.createReadStream()) chunks.push(chunk);
assert.equal(JSON.parse(Buffer.concat(chunks).toString()).title, title);
} finally {
await page.evaluate(() => { window.__restoreProjectStorage(); delete window.__restoreProjectStorage; });
}
await dialog.getByRole('button', { name: '保存工程', exact: true }).click();
await dialog.waitFor({ state: 'hidden' });
await page.reload();
assert.equal(await page.evaluate(() => JSON.parse(localStorage.getItem('fastfigure.project.v2')).title), title);
}
3 changes: 2 additions & 1 deletion tests/ui/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { checkAssistant } from './assistant.mjs';
import { checkReconstruction } from './reconstruction.mjs';
import { checkNotifications } from './notifications.mjs';
import { checkFastUi } from './fastui.mjs';
import { checkProjectSave } from './project-save.mjs';
// One supported desktop viewport. A private fixture service never uses the user's CLI/session.
process.env.FASTFIGURE_CODEX_COMMAND = process.env.FASTFIGURE_UI_CLI_FIXTURE ?? join(process.cwd(), 'server/harness/fixtures/cli.mjs');
process.env.FASTFIGURE_CLAUDE_COMMAND = process.env.FASTFIGURE_CODEX_COMMAND;
process.env.FASTFIGURE_TEST_SCENARIO = 'slow';
const libraryDirectory=mkdtempSync(join(tmpdir(),'fastfigure-ui-library-'));
process.env.FASTFIGURE_LIBRARY_DIR=libraryDirectory;
const checks = [['fastui', checkFastUi], ['editor', checkEditor], ['data', checkData], ['assistant', checkAssistant], ['reconstruction', checkReconstruction], ['notifications', checkNotifications], ['gallery-study', checkGalleryStudy]];
const checks = [['fastui', checkFastUi], ['project-save', checkProjectSave], ['editor', checkEditor], ['data', checkData], ['assistant', checkAssistant], ['reconstruction', checkReconstruction], ['notifications', checkNotifications], ['gallery-study', checkGalleryStudy]];
const selected = checks.find(([name]) => process.argv.includes(`--${name}`));
const scenarios = selected ? [selected] : checks.filter(([name]) => name !== 'gallery-study');
const results = join(process.cwd(), selected ? `test-results/ui-${selected[0]}` : 'test-results/ui');
Expand Down
Loading