search.test.js
1 /** 2 * Regression test for issue #625. 3 * Facebook search must navigate in the pipeline before DOM extraction. 4 */ 5 import { describe, expect, it, vi } from 'vitest'; 6 import { getRegistry } from '@jackwener/opencli/registry'; 7 import { executePipeline } from '@jackwener/opencli/pipeline'; 8 // Import the adapter to register it 9 import './search.js'; 10 /** 11 * Minimal browser mock for pipeline execution tests. 12 * Only methods touched by this adapter path are implemented. 13 */ 14 function createMockPage() { 15 return { 16 goto: vi.fn(), 17 evaluate: vi.fn().mockResolvedValue([]), 18 getCookies: vi.fn().mockResolvedValue([]), 19 snapshot: vi.fn().mockResolvedValue(''), 20 click: vi.fn(), 21 typeText: vi.fn(), 22 pressKey: vi.fn(), 23 scrollTo: vi.fn(), 24 getFormState: vi.fn().mockResolvedValue({}), 25 wait: vi.fn(), 26 tabs: vi.fn().mockResolvedValue([]), 27 selectTab: vi.fn(), 28 networkRequests: vi.fn().mockResolvedValue([]), 29 consoleMessages: vi.fn().mockResolvedValue(''), 30 scroll: vi.fn(), 31 autoScroll: vi.fn(), 32 installInterceptor: vi.fn(), 33 getInterceptedRequests: vi.fn().mockResolvedValue([]), 34 waitForCapture: vi.fn().mockResolvedValue(undefined), 35 screenshot: vi.fn().mockResolvedValue(''), 36 }; 37 } 38 describe('facebook search pipeline', () => { 39 it('navigates to search results before extracting DOM data', async () => { 40 const cmd = getRegistry().get('facebook/search'); 41 expect(cmd).toBeDefined(); 42 const pipeline = cmd.pipeline ?? []; 43 const page = createMockPage(); 44 await executePipeline(page, pipeline, { 45 args: { query: 'AI agent', limit: 3 }, 46 }); 47 expect(page.goto).toHaveBeenNthCalledWith(1, 'https://www.facebook.com'); 48 expect(page.goto).toHaveBeenNthCalledWith(2, 'https://www.facebook.com/search/top?q=AI%20agent', { 49 waitUntil: undefined, 50 settleMs: 4000, 51 }); 52 expect(page.evaluate).toHaveBeenCalledTimes(1); 53 expect(String(page.evaluate.mock.calls[0]?.[0] ?? '')).not.toContain('window.location.href'); 54 }); 55 });