File size: 2,602 Bytes
9332ccf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | /**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type React from 'react';
import { render } from '../../test-utils/render.js';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { ContextSummaryDisplay } from './ContextSummaryDisplay.js';
import * as useTerminalSize from '../hooks/useTerminalSize.js';
vi.mock('../hooks/useTerminalSize.js', () => ({
useTerminalSize: vi.fn(),
}));
const useTerminalSizeMock = vi.mocked(useTerminalSize.useTerminalSize);
afterEach(() => {
vi.restoreAllMocks();
vi.useRealTimers();
});
const renderWithWidth = async (
width: number,
props: React.ComponentProps<typeof ContextSummaryDisplay>,
) => {
useTerminalSizeMock.mockReturnValue({ columns: width, rows: 24 });
const result = await render(<ContextSummaryDisplay {...props} />);
return result;
};
describe('<ContextSummaryDisplay />', () => {
const baseProps = {
geminiMdFileCount: 0,
contextFileNames: [],
mcpServers: {},
ideContext: {
workspaceState: {
openFiles: [],
},
},
skillCount: 1,
};
it('should render on a single line on a wide screen', async () => {
const props = {
...baseProps,
geminiMdFileCount: 1,
contextFileNames: ['GEMINI.md'],
mcpServers: { 'test-server': { command: 'test' } },
ideContext: {
workspaceState: {
openFiles: [{ path: '/a/b/c', timestamp: Date.now() }],
},
},
};
const { lastFrame, unmount } = await renderWithWidth(120, props);
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('should render on multiple lines on a narrow screen', async () => {
const props = {
...baseProps,
geminiMdFileCount: 1,
contextFileNames: ['GEMINI.md'],
mcpServers: { 'test-server': { command: 'test' } },
ideContext: {
workspaceState: {
openFiles: [{ path: '/a/b/c', timestamp: Date.now() }],
},
},
};
const { lastFrame, unmount } = await renderWithWidth(60, props);
expect(lastFrame()).toMatchSnapshot();
unmount();
});
it('should not render empty parts', async () => {
const props = {
...baseProps,
geminiMdFileCount: 0,
contextFileNames: [],
mcpServers: {},
skillCount: 0,
ideContext: {
workspaceState: {
openFiles: [{ path: '/a/b/c', timestamp: Date.now() }],
},
},
};
const { lastFrame, unmount } = await renderWithWidth(60, props);
expect(lastFrame()).toMatchSnapshot();
unmount();
});
});
|