Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(mobile): 验证目录刷新后的文件滚动位置

Dash80534d45b71e
diff --git a/apps/mobile/src/__tests__/filePreviewCacheRendering.test.tsx b/apps/mobile/src/__tests__/filePreviewCacheRendering.test.tsx
index fac6c7b909..bf15067f51 100644
--- a/apps/mobile/src/__tests__/filePreviewCacheRendering.test.tsx
+++ b/apps/mobile/src/__tests__/filePreviewCacheRendering.test.tsx
@@ -125,11 +125,25 @@ describe('cached file preview presentation', () => {
it('still opens without a listing and seeds subsequent opens from the successful background read', async () => {
await open(false);
expect(host.textContent).toContain('1 / 1');
+ state.scroll.mockClear();
await act(async () => { resolveListing({ entries }); });
expect(host.textContent).toContain('3 / 6 · 11.9 KB');
+ expect(state.scroll).toHaveBeenCalledExactlyOnceWith({ animated: false, offset: 2 * 390 });
act(() => root.unmount());
root = createRoot(host);
await open(false);
expect(host.textContent).toContain('3 / 6 · 11.9 KB');
});
+ it('keeps the file selected after a swipe when a directory refresh moves it to another index', async () => {
+ await open();
+ act(() => state.pager.onMomentumScrollEnd({ nativeEvent: { contentOffset: { x: 390 * 3 } } }));
+ expect(host.textContent).toContain('s.txt4 / 6 · 11.9 KB');
+ const selectedKey = state.pager.keyExtractor(state.pager.data[3]);
+ state.scroll.mockClear();
+ await act(async () => { resolveListing({ entries: entries.slice(1) }); });
+ expect(host.textContent).toContain('s.txt3 / 5 · 11.9 KB');
+ expect(state.pager.data[state.pager.initialScrollIndex].relPath).toBe('s.txt');
+ expect(state.pager.keyExtractor(state.pager.data[2])).toBe(selectedKey);
+ expect(state.scroll).toHaveBeenCalledExactlyOnceWith({ animated: false, offset: 2 * 390 });
+ });
});