Files
wehub-resource-sync 9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

48 lines
2.1 KiB
JavaScript

import { describe, expect, it, vi } from 'vitest';
import { CommandExecutionError } from '@jackwener/opencli/errors';
import { getRegistry } from '@jackwener/opencli/registry';
import './cite.js';
describe('google-scholar cite command', () => {
const command = getRegistry().get('google-scholar/cite');
it('registers as a public browser command', () => {
expect(command).toBeDefined();
expect(command.site).toBe('google-scholar');
expect(command.strategy).toBe('public');
expect(command.browser).toBe(true);
});
it('rejects empty queries before browser navigation', async () => {
const page = { goto: vi.fn() };
await expect(command.func(page, { query: ' ' })).rejects.toMatchObject({
name: 'ArgumentError',
code: 'ARGUMENT',
});
expect(page.goto).not.toHaveBeenCalled();
});
it('throws when the requested search result index does not exist', async () => {
const page = {
goto: vi.fn().mockResolvedValue(undefined),
wait: vi.fn().mockResolvedValue(undefined),
evaluate: vi.fn().mockResolvedValueOnce({ ok: false, reason: 'result not found at index 2' }),
};
await expect(command.func(page, { query: 'test', index: 2 })).rejects.toThrow(CommandExecutionError);
});
it('looks up the requested citation style instead of only locking BibTeX', async () => {
const page = {
goto: vi.fn().mockResolvedValue(undefined),
wait: vi.fn().mockResolvedValue(undefined),
evaluate: vi.fn()
.mockResolvedValueOnce({ ok: true, title: 'Paper Title' })
.mockResolvedValueOnce('https://example.com/refworks')
.mockResolvedValueOnce('RefWorks citation body'),
};
const result = await command.func(page, { query: 'test', style: 'refworks' });
expect(result).toEqual([{ title: 'Paper Title', format: 'refworks', citation: 'RefWorks citation body' }]);
expect(page.evaluate.mock.calls[1][0]).toContain('RefWorks');
});
});