mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 15:04:16 -07:00
fix(cli): enable typechecking for ui/components tests (#11419)
Co-authored-by: Jacob MacDonald <jakemac@google.com>
This commit is contained in:
@@ -9,7 +9,8 @@ import {
|
||||
createMockSettings,
|
||||
} from '../../test-utils/render.js';
|
||||
import { Footer } from './Footer.js';
|
||||
import { tildeifyPath } from '@google/gemini-cli-core';
|
||||
import { tildeifyPath, ToolCallDecision } from '@google/gemini-cli-core';
|
||||
import type { SessionStatsState } from '../contexts/SessionContext.js';
|
||||
|
||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
const original =
|
||||
@@ -32,15 +33,41 @@ const defaultProps = {
|
||||
branchName: 'main',
|
||||
};
|
||||
|
||||
const sessionStats = {
|
||||
sessionStats: { lastPromptTokenCount: 0, lastResponseTokenCount: 0 },
|
||||
const mockSessionStats: SessionStatsState = {
|
||||
sessionId: 'test-session',
|
||||
sessionStartTime: new Date(),
|
||||
lastPromptTokenCount: 0,
|
||||
promptCount: 0,
|
||||
metrics: {
|
||||
models: {},
|
||||
tools: {
|
||||
totalCalls: 0,
|
||||
totalSuccess: 0,
|
||||
totalFail: 0,
|
||||
totalDurationMs: 0,
|
||||
totalDecisions: {
|
||||
accept: 0,
|
||||
reject: 0,
|
||||
modify: 0,
|
||||
[ToolCallDecision.AUTO_ACCEPT]: 0,
|
||||
},
|
||||
byName: {},
|
||||
},
|
||||
files: {
|
||||
totalLinesAdded: 0,
|
||||
totalLinesRemoved: 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('<Footer />', () => {
|
||||
it('renders the component', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { branchName: defaultProps.branchName, ...sessionStats },
|
||||
uiState: {
|
||||
branchName: defaultProps.branchName,
|
||||
sessionStats: mockSessionStats,
|
||||
},
|
||||
});
|
||||
expect(lastFrame()).toBeDefined();
|
||||
});
|
||||
@@ -49,7 +76,7 @@ describe('<Footer />', () => {
|
||||
it('should display a shortened path on a narrow terminal', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 79,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
});
|
||||
const tildePath = tildeifyPath(defaultProps.targetDir);
|
||||
const pathLength = Math.max(20, Math.floor(79 * 0.25));
|
||||
@@ -61,7 +88,7 @@ describe('<Footer />', () => {
|
||||
it('should use wide layout at 80 columns', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 80,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
});
|
||||
const tildePath = tildeifyPath(defaultProps.targetDir);
|
||||
const expectedPath =
|
||||
@@ -73,7 +100,10 @@ describe('<Footer />', () => {
|
||||
it('displays the branch name when provided', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { branchName: defaultProps.branchName, ...sessionStats },
|
||||
uiState: {
|
||||
branchName: defaultProps.branchName,
|
||||
sessionStats: mockSessionStats,
|
||||
},
|
||||
});
|
||||
expect(lastFrame()).toContain(`(${defaultProps.branchName}*)`);
|
||||
});
|
||||
@@ -81,7 +111,7 @@ describe('<Footer />', () => {
|
||||
it('does not display the branch name when not provided', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { branchName: undefined, ...sessionStats },
|
||||
uiState: { branchName: undefined, sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).not.toContain(`(${defaultProps.branchName}*)`);
|
||||
});
|
||||
@@ -89,7 +119,7 @@ describe('<Footer />', () => {
|
||||
it('displays the model name and context percentage', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toContain(defaultProps.model);
|
||||
expect(lastFrame()).toMatch(/\(\d+% context left\)/);
|
||||
@@ -98,7 +128,7 @@ describe('<Footer />', () => {
|
||||
it('displays the model name and abbreviated context percentage', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 99,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toContain(defaultProps.model);
|
||||
expect(lastFrame()).toMatch(/\(\d+%\)/);
|
||||
@@ -108,7 +138,7 @@ describe('<Footer />', () => {
|
||||
it('should display untrusted when isTrustedFolder is false', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { isTrustedFolder: false, ...sessionStats },
|
||||
uiState: { isTrustedFolder: false, sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toContain('untrusted');
|
||||
});
|
||||
@@ -117,7 +147,7 @@ describe('<Footer />', () => {
|
||||
vi.stubEnv('SANDBOX', 'gemini-cli-test-sandbox');
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { isTrustedFolder: undefined, ...sessionStats },
|
||||
uiState: { isTrustedFolder: undefined, sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toContain('test');
|
||||
vi.unstubAllEnvs();
|
||||
@@ -128,7 +158,7 @@ describe('<Footer />', () => {
|
||||
vi.stubEnv('SEATBELT_PROFILE', 'test-profile');
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { isTrustedFolder: true, ...sessionStats },
|
||||
uiState: { isTrustedFolder: true, sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toMatch(/macOS Seatbelt.*\(test-profile\)/s);
|
||||
vi.unstubAllEnvs();
|
||||
@@ -139,7 +169,7 @@ describe('<Footer />', () => {
|
||||
vi.stubEnv('SANDBOX', '');
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { isTrustedFolder: true, ...sessionStats },
|
||||
uiState: { isTrustedFolder: true, sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toContain('no sandbox');
|
||||
vi.unstubAllEnvs();
|
||||
@@ -149,7 +179,7 @@ describe('<Footer />', () => {
|
||||
vi.stubEnv('SANDBOX', 'gemini-cli-test-sandbox');
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { isTrustedFolder: false, ...sessionStats },
|
||||
uiState: { isTrustedFolder: false, sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toContain('untrusted');
|
||||
expect(lastFrame()).not.toMatch(/test-sandbox/s);
|
||||
@@ -161,7 +191,7 @@ describe('<Footer />', () => {
|
||||
it('renders complete footer with all sections visible (baseline)', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toMatchSnapshot('complete-footer-wide');
|
||||
});
|
||||
@@ -169,7 +199,7 @@ describe('<Footer />', () => {
|
||||
it('renders footer with all optional sections hidden (minimal footer)', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
settings: createMockSettings({
|
||||
ui: {
|
||||
footer: {
|
||||
@@ -186,7 +216,7 @@ describe('<Footer />', () => {
|
||||
it('renders footer with only model info hidden (partial filtering)', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
settings: createMockSettings({
|
||||
ui: {
|
||||
footer: {
|
||||
@@ -203,7 +233,7 @@ describe('<Footer />', () => {
|
||||
it('renders footer with CWD and model info hidden to test alignment (only sandbox visible)', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 120,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
settings: createMockSettings({
|
||||
ui: {
|
||||
footer: {
|
||||
@@ -220,7 +250,7 @@ describe('<Footer />', () => {
|
||||
it('renders complete footer in narrow terminal (baseline narrow)', () => {
|
||||
const { lastFrame } = renderWithProviders(<Footer />, {
|
||||
width: 79,
|
||||
uiState: { ...sessionStats },
|
||||
uiState: { sessionStats: mockSessionStats },
|
||||
});
|
||||
expect(lastFrame()).toMatchSnapshot('complete-footer-narrow');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user