/ clis / notebooklm / summary.test.js
summary.test.js
 1  import { beforeEach, describe, expect, it, vi } from 'vitest';
 2  const { mockReadNotebooklmSummaryFromPage, mockGetNotebooklmSummaryViaRpc, mockGetNotebooklmPageState, mockRequireNotebooklmSession, } = vi.hoisted(() => ({
 3      mockReadNotebooklmSummaryFromPage: vi.fn(),
 4      mockGetNotebooklmSummaryViaRpc: vi.fn(),
 5      mockGetNotebooklmPageState: vi.fn(),
 6      mockRequireNotebooklmSession: vi.fn(),
 7  }));
 8  vi.mock('./utils.js', async () => {
 9      const actual = await vi.importActual('./utils.js');
10      return {
11          ...actual,
12          readNotebooklmSummaryFromPage: mockReadNotebooklmSummaryFromPage,
13          getNotebooklmSummaryViaRpc: mockGetNotebooklmSummaryViaRpc,
14          getNotebooklmPageState: mockGetNotebooklmPageState,
15          requireNotebooklmSession: mockRequireNotebooklmSession,
16      };
17  });
18  import { getRegistry } from '@jackwener/opencli/registry';
19  import './summary.js';
20  describe('notebooklm summary', () => {
21      const command = getRegistry().get('notebooklm/summary');
22      beforeEach(() => {
23          mockReadNotebooklmSummaryFromPage.mockReset();
24          mockGetNotebooklmSummaryViaRpc.mockReset();
25          mockGetNotebooklmPageState.mockReset();
26          mockRequireNotebooklmSession.mockReset();
27          mockRequireNotebooklmSession.mockResolvedValue(undefined);
28          mockGetNotebooklmPageState.mockResolvedValue({
29              url: 'https://notebooklm.google.com/notebook/nb-demo',
30              title: 'Browser Automation',
31              hostname: 'notebooklm.google.com',
32              kind: 'notebook',
33              notebookId: 'nb-demo',
34              loginRequired: false,
35              notebookCount: 1,
36          });
37      });
38      it('returns the current notebook summary from the visible page first', async () => {
39          mockReadNotebooklmSummaryFromPage.mockResolvedValue({
40              notebook_id: 'nb-demo',
41              title: 'Browser Automation',
42              summary: 'A concise notebook summary.',
43              url: 'https://notebooklm.google.com/notebook/nb-demo',
44              source: 'summary-dom',
45          });
46          const result = await command.func({}, {});
47          expect(result).toEqual([
48              {
49                  notebook_id: 'nb-demo',
50                  title: 'Browser Automation',
51                  summary: 'A concise notebook summary.',
52                  url: 'https://notebooklm.google.com/notebook/nb-demo',
53                  source: 'summary-dom',
54              },
55          ]);
56          expect(mockGetNotebooklmSummaryViaRpc).not.toHaveBeenCalled();
57      });
58      it('falls back to rpc summary extraction when no visible summary block is found', async () => {
59          mockReadNotebooklmSummaryFromPage.mockResolvedValue(null);
60          mockGetNotebooklmSummaryViaRpc.mockResolvedValue({
61              notebook_id: 'nb-demo',
62              title: 'Browser Automation',
63              summary: 'Summary recovered from rpc.',
64              url: 'https://notebooklm.google.com/notebook/nb-demo',
65              source: 'rpc',
66          });
67          const result = await command.func({}, {});
68          expect(result).toEqual([
69              {
70                  notebook_id: 'nb-demo',
71                  title: 'Browser Automation',
72                  summary: 'Summary recovered from rpc.',
73                  url: 'https://notebooklm.google.com/notebook/nb-demo',
74                  source: 'rpc',
75              },
76          ]);
77      });
78  });