mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
fix(renderer): drop redundant ternary, add loadChildren idempotence test
This commit is contained in:
@@ -46,7 +46,7 @@ function entryToNode(entry: FileEntry): FileNode {
|
||||
name: entry.name,
|
||||
path: entry.path,
|
||||
isDirectory: entry.isDirectory,
|
||||
children: entry.isDirectory ? null : null,
|
||||
children: null, // lazy: start unloaded; loadChildren populates this
|
||||
};
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ export const useFileStore = create<FileState>()(
|
||||
|
||||
let found = false;
|
||||
updateNode(tree, dirPath, (node) => {
|
||||
if (node.loaded) return;
|
||||
if (node.loaded === true) return;
|
||||
found = true;
|
||||
});
|
||||
if (!found) return;
|
||||
|
||||
@@ -139,6 +139,28 @@ describe('useFileStore', () => {
|
||||
expect(fakeList).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('loadChildren is idempotent: does not re-fetch when already loaded', async () => {
|
||||
fakeList.mockResolvedValue({
|
||||
ok: true,
|
||||
data: [{ name: 'src', path: '/root/src', isDirectory: true }],
|
||||
});
|
||||
await useFileStore.getState().openFolder('/root');
|
||||
|
||||
fakeList.mockClear();
|
||||
fakeList.mockResolvedValue({
|
||||
ok: true,
|
||||
data: [{ name: 'foo.ts', path: '/root/src/foo.ts', isDirectory: false }],
|
||||
});
|
||||
|
||||
await useFileStore.getState().loadChildren('/root/src');
|
||||
const callsAfterFirst = fakeList.mock.calls.length;
|
||||
expect(callsAfterFirst).toBe(1);
|
||||
|
||||
// Second call should be a no-op (loaded is true)
|
||||
await useFileStore.getState().loadChildren('/root/src');
|
||||
expect(fakeList.mock.calls.length).toBe(callsAfterFirst);
|
||||
});
|
||||
|
||||
// --- toggleExpanded ---
|
||||
|
||||
it('toggleExpanded adds and removes paths from the expanded Set', () => {
|
||||
|
||||
Reference in New Issue
Block a user