2025-11-22 08:17:29 +05:30
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-03-03 01:22:29 -08:00
|
|
|
import { renderWithProviders } from '../../test-utils/render.js';
|
2025-11-22 08:17:29 +05:30
|
|
|
import { ContextUsageDisplay } from './ContextUsageDisplay.js';
|
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
|
2026-01-23 20:32:35 -05:00
|
|
|
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
|
|
|
|
const actual =
|
|
|
|
|
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
|
|
|
|
return {
|
|
|
|
|
...actual,
|
|
|
|
|
tokenLimit: () => 10000,
|
|
|
|
|
};
|
|
|
|
|
});
|
2025-11-22 08:17:29 +05:30
|
|
|
|
|
|
|
|
describe('ContextUsageDisplay', () => {
|
2026-03-03 01:22:29 -08:00
|
|
|
it('renders correct percentage used', async () => {
|
|
|
|
|
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
2025-11-22 08:17:29 +05:30
|
|
|
<ContextUsageDisplay
|
|
|
|
|
promptTokenCount={5000}
|
|
|
|
|
model="gemini-pro"
|
|
|
|
|
terminalWidth={120}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2025-11-22 08:17:29 +05:30
|
|
|
const output = lastFrame();
|
2026-03-04 21:21:48 -05:00
|
|
|
expect(output).toContain('50% used');
|
2026-03-03 01:22:29 -08:00
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders correctly when usage is 0%', async () => {
|
|
|
|
|
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
|
|
|
|
<ContextUsageDisplay
|
|
|
|
|
promptTokenCount={0}
|
|
|
|
|
model="gemini-pro"
|
|
|
|
|
terminalWidth={120}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
|
|
|
|
const output = lastFrame();
|
2026-03-04 21:21:48 -05:00
|
|
|
expect(output).toContain('0% used');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
|
2026-03-03 01:22:29 -08:00
|
|
|
it('renders abbreviated label when terminal width is small', async () => {
|
|
|
|
|
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
2025-11-22 08:17:29 +05:30
|
|
|
<ContextUsageDisplay
|
|
|
|
|
promptTokenCount={2000}
|
|
|
|
|
model="gemini-pro"
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
/>,
|
2026-03-03 01:22:29 -08:00
|
|
|
{ width: 80 },
|
|
|
|
|
);
|
|
|
|
|
await waitUntilReady();
|
|
|
|
|
const output = lastFrame();
|
|
|
|
|
expect(output).toContain('20%');
|
|
|
|
|
expect(output).not.toContain('context used');
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders 80% correctly', async () => {
|
|
|
|
|
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
|
|
|
|
<ContextUsageDisplay
|
|
|
|
|
promptTokenCount={8000}
|
|
|
|
|
model="gemini-pro"
|
|
|
|
|
terminalWidth={120}
|
|
|
|
|
/>,
|
2025-11-22 08:17:29 +05:30
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2025-11-22 08:17:29 +05:30
|
|
|
const output = lastFrame();
|
2026-03-04 21:21:48 -05:00
|
|
|
expect(output).toContain('80% used');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
|
2026-03-03 01:22:29 -08:00
|
|
|
it('renders 100% when full', async () => {
|
|
|
|
|
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
|
2025-11-22 08:17:29 +05:30
|
|
|
<ContextUsageDisplay
|
|
|
|
|
promptTokenCount={10000}
|
|
|
|
|
model="gemini-pro"
|
|
|
|
|
terminalWidth={120}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2025-11-22 08:17:29 +05:30
|
|
|
const output = lastFrame();
|
2026-03-04 21:21:48 -05:00
|
|
|
expect(output).toContain('100% used');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
});
|