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
24 changes: 24 additions & 0 deletions e2e/helpers/board-ui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ export async function renameBoard(currentName, nextName) {
await waitForBoardVisible(nextName);
}

export async function rememberEditorInstance() {
const editorFound = await browser.execute(() => {
const editor = document.querySelector('.excalidraw-frame .excalidraw');
window.__systemTestEditorInstance = editor;
return editor !== null;
});

if (!editorFound) {
throw new Error('Expected the Excalidraw editor to be mounted.');
}
}

export async function assertEditorInstancePreserved() {
const editorPreserved = await browser.execute(
() =>
window.__systemTestEditorInstance !== null &&
window.__systemTestEditorInstance === document.querySelector('.excalidraw-frame .excalidraw'),
);

if (!editorPreserved) {
throw new Error('Expected rename to preserve the mounted Excalidraw editor instance.');
}
}

export async function duplicateBoard(name) {
await openBoardMenu(name);

Expand Down
12 changes: 12 additions & 0 deletions e2e/specs/system.e2e.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
assertActiveBoard,
assertEditorInstancePreserved,
assertSidebarCollapsed,
assertExportRowHidden,
closeSettings,
Expand All @@ -10,6 +11,7 @@ import {
openBoardFromCommandPalette,
openSettings,
openSettingsFromCommandPalette,
rememberEditorInstance,
renameBoard,
restartAppSession,
selectBoard,
Expand Down Expand Up @@ -46,6 +48,16 @@ describe('System suite', () => {
await waitForBoardVisible(duplicatedName);
});

it('rename: preserves the mounted editor so pending content can still be saved', async () => {
const boardName = uniqueBoardName('Rename Content Board');
const renamedName = `${boardName} Renamed`;

await createBoard(boardName);
await rememberEditorInstance();
await renameBoard(boardName, renamedName);
await assertEditorInstancePreserved();
});

it('persistence: keeps created boards after app restart', async () => {
const boardName = uniqueBoardName('Persistence Board');
const editedName = `${boardName} Edited`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@fortawesome/fontawesome-svg-core": "^7.2.0",
"@fortawesome/free-solid-svg-icons": "^7.2.0",
"@fortawesome/react-fontawesome": "^3.3.0",
"@tauri-apps/api": "^2.10.1",
"@tauri-apps/api": "^2.11.1",
"@tauri-apps/plugin-dialog": "^2.7.0",
"@tauri-apps/plugin-fs": "^2.5.0",
"@tauri-apps/plugin-opener": "^2.5.3",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions src/hooks/useBoards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,30 @@ export function useBoards() {
};

const renameBoard = async (boardId: string, newName: string): Promise<boolean> => {
return runAndReload(async () => {
await invoke<Board>('rename_board', { boardId, newName });
try {
const renamedBoard = await invoke<Board>('rename_board', { boardId, newName });
setItems((currentItems) =>
currentItems.map((item) => {
if (item.type === 'board') {
return item.id === boardId ? { ...renamedBoard, type: 'board' } : item;
}

if (!item.items.some((board) => board.id === boardId)) {
return item;
}

return {
...item,
items: item.items.map((board) => (board.id === boardId ? renamedBoard : board)),
};
}),
);
setError(null);
return true;
}, false);
} catch (e) {
setError(String(e));
return false;
}
};

const deleteBoard = async (boardId: string): Promise<boolean> => {
Expand Down
Loading