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(desktop): cover market refresh during detail return (#3687)

qsoyqf5d05780caef
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/usePluginListScrollRestoration.test.tsx b/apps/desktop/src/renderer/features/plugin/__tests__/usePluginListScrollRestoration.test.tsx
index 5b12fe5167..85462408f8 100644
--- a/apps/desktop/src/renderer/features/plugin/__tests__/usePluginListScrollRestoration.test.tsx
+++ b/apps/desktop/src/renderer/features/plugin/__tests__/usePluginListScrollRestoration.test.tsx
@@ -14,10 +14,20 @@ import {
let restoration: PluginListScrollRestoration;
-function Harness({ listVisible }: { listVisible: boolean }) {
+function Harness({
+ listVisible,
+ items = ['plugin-a', 'plugin-b'],
+}: {
+ listVisible: boolean;
+ items?: string[];
+}) {
restoration = usePluginListScrollRestoration(listVisible);
return listVisible ? (
- <main data-testid="plugin-list" ref={restoration.listRef} onScroll={restoration.onListScroll} />
+ <main data-testid="plugin-list" ref={restoration.listRef} onScroll={restoration.onListScroll}>
+ {items.map((item) => (
+ <div key={item} data-testid={`plugin-${item}`} />
+ ))}
+ </main>
) : (
<div data-testid="plugin-detail" />
);
@@ -47,6 +57,30 @@ describe('usePluginListScrollRestoration', () => {
expect(screen.getByTestId('plugin-list').scrollTop).toBe(640);
});
+ it('keeps the captured pixel position when catalog items change during detail', () => {
+ const view = render(<Harness listVisible items={['plugin-a', 'plugin-b', 'plugin-c']} />);
+ const list = screen.getByTestId('plugin-list');
+ setScrollTop(list, 640);
+ fireEvent.scroll(list);
+
+ // Enter detail: the catalog list is unmounted while its data can still refresh.
+ act(() => {
+ restoration.capture();
+ restoration.requestRestore();
+ });
+ view.rerender(<Harness listVisible={false} items={['plugin-a', 'plugin-b', 'plugin-c']} />);
+ // Simulate a market refresh that inserts an item before the previous viewport.
+ view.rerender(
+ <Harness listVisible={false} items={['plugin-new', 'plugin-a', 'plugin-b', 'plugin-c']} />,
+ );
+ view.rerender(
+ <Harness listVisible items={['plugin-new', 'plugin-a', 'plugin-b', 'plugin-c']} />,
+ );
+
+ expect(screen.getByTestId('plugin-plugin-new')).toBeTruthy();
+ expect(screen.getByTestId('plugin-list').scrollTop).toBe(640);
+ });
+
it('does not restore a position unless the return path requests it', () => {
const view = render(<Harness listVisible />);
const list = screen.getByTestId('plugin-list');