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
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { getRegistry } from '@jackwener/opencli/registry';
|
|
|
|
const { gqlRequestMock } = vi.hoisted(() => ({ gqlRequestMock: vi.fn() }));
|
|
vi.mock('./_helpers.js', async () => {
|
|
const actual = await vi.importActual('./_helpers.js');
|
|
return { ...actual, gqlRequest: gqlRequestMock };
|
|
});
|
|
|
|
import './frontpage.js';
|
|
|
|
describe('lesswrong frontpage', () => {
|
|
beforeEach(() => {
|
|
gqlRequestMock.mockReset();
|
|
});
|
|
|
|
it('emits empty-string for missing user.displayName instead of a sentinel', async () => {
|
|
const command = getRegistry().get('lesswrong/frontpage');
|
|
expect(command?.func).toBeDefined();
|
|
gqlRequestMock.mockResolvedValueOnce({
|
|
posts: {
|
|
results: [
|
|
{ _id: 'a1', slug: 'post-a', title: 'Has author', user: { displayName: 'Real Person' }, baseScore: 10, commentCount: 3 },
|
|
{ _id: 'b2', slug: 'post-b', title: 'Deleted user', user: null, baseScore: 5, commentCount: 0 },
|
|
{ _id: 'c3', slug: 'post-c', title: 'Missing name', user: {}, baseScore: 7, commentCount: 1 },
|
|
],
|
|
},
|
|
});
|
|
const rows = await command.func({ limit: 3 });
|
|
expect(rows).toHaveLength(3);
|
|
expect(rows[0]).toMatchObject({ rank: 1, title: 'Has author', author: 'Real Person', karma: 10, comments: 3 });
|
|
expect(rows[1].author).toBe('');
|
|
expect(rows[1].title).toBe('Deleted user');
|
|
expect(rows[2].author).toBe('');
|
|
expect(rows[2].title).toBe('Missing name');
|
|
});
|
|
});
|