2026-01-27 05:15:44 -08:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
import { renderWithProviders } from '../../../test-utils/render.js';
|
|
|
|
|
import { HalfLinePaddedBox } from './HalfLinePaddedBox.js';
|
2026-01-29 19:21:18 -08:00
|
|
|
import { Text, useIsScreenReaderEnabled } from 'ink';
|
2026-01-27 05:15:44 -08:00
|
|
|
import { describe, it, expect, vi, afterEach } from 'vitest';
|
2026-04-22 16:27:09 -04:00
|
|
|
import { supportsTrueColor } from '@google/gemini-cli-core';
|
2026-01-27 05:15:44 -08:00
|
|
|
|
2026-01-29 19:21:18 -08:00
|
|
|
vi.mock('ink', async () => {
|
|
|
|
|
const actual = await vi.importActual('ink');
|
|
|
|
|
return {
|
|
|
|
|
...actual,
|
|
|
|
|
useIsScreenReaderEnabled: vi.fn(() => false),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-22 16:27:09 -04:00
|
|
|
vi.mock('@google/gemini-cli-core', async () => {
|
|
|
|
|
const actual = await vi.importActual('@google/gemini-cli-core');
|
|
|
|
|
return {
|
|
|
|
|
...actual,
|
|
|
|
|
supportsTrueColor: vi.fn(() => true),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-27 05:15:44 -08:00
|
|
|
describe('<HalfLinePaddedBox />', () => {
|
2026-01-29 19:21:18 -08:00
|
|
|
const mockUseIsScreenReaderEnabled = vi.mocked(useIsScreenReaderEnabled);
|
2026-04-22 16:27:09 -04:00
|
|
|
const mockSupportsTrueColor = vi.mocked(supportsTrueColor);
|
2026-01-29 19:21:18 -08:00
|
|
|
|
2026-01-27 05:15:44 -08:00
|
|
|
afterEach(() => {
|
|
|
|
|
vi.restoreAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-22 16:27:09 -04:00
|
|
|
it('renders standard background and blocks when true color is supported', async () => {
|
|
|
|
|
mockSupportsTrueColor.mockReturnValue(true);
|
2026-01-27 05:15:44 -08:00
|
|
|
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await renderWithProviders(
|
2026-01-27 05:15:44 -08:00
|
|
|
<HalfLinePaddedBox backgroundBaseColor="blue" backgroundOpacity={0.5}>
|
|
|
|
|
<Text>Content</Text>
|
|
|
|
|
</HalfLinePaddedBox>,
|
|
|
|
|
{ width: 10 },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-22 16:27:09 -04:00
|
|
|
it('renders alternative blocks when true color is not supported', async () => {
|
|
|
|
|
mockSupportsTrueColor.mockReturnValue(false);
|
2026-01-27 05:15:44 -08:00
|
|
|
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await renderWithProviders(
|
2026-01-27 05:15:44 -08:00
|
|
|
<HalfLinePaddedBox backgroundBaseColor="blue" backgroundOpacity={0.5}>
|
|
|
|
|
<Text>Content</Text>
|
|
|
|
|
</HalfLinePaddedBox>,
|
|
|
|
|
{ width: 10 },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders nothing when useBackgroundColor is false', async () => {
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await renderWithProviders(
|
2026-01-27 05:15:44 -08:00
|
|
|
<HalfLinePaddedBox
|
|
|
|
|
backgroundBaseColor="blue"
|
|
|
|
|
backgroundOpacity={0.5}
|
|
|
|
|
useBackgroundColor={false}
|
|
|
|
|
>
|
|
|
|
|
<Text>Content</Text>
|
|
|
|
|
</HalfLinePaddedBox>,
|
|
|
|
|
{ width: 10 },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
2026-01-29 19:21:18 -08:00
|
|
|
|
|
|
|
|
it('renders nothing when screen reader is enabled', async () => {
|
|
|
|
|
mockUseIsScreenReaderEnabled.mockReturnValue(true);
|
|
|
|
|
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await renderWithProviders(
|
2026-01-29 19:21:18 -08:00
|
|
|
<HalfLinePaddedBox backgroundBaseColor="blue" backgroundOpacity={0.5}>
|
|
|
|
|
<Text>Content</Text>
|
|
|
|
|
</HalfLinePaddedBox>,
|
|
|
|
|
{ width: 10 },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
|
|
|
|
|
unmount();
|
|
|
|
|
});
|
2026-01-27 05:15:44 -08:00
|
|
|
});
|