mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-11 22:00:41 -07:00
Fix tests to wrap all calls changing the UI with act. (#12268)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { render } from 'ink-testing-library';
|
||||
import { render } from '../../test-utils/render.js';
|
||||
import { PrepareLabel, MAX_WIDTH } from './PrepareLabel.js';
|
||||
|
||||
describe('PrepareLabel', () => {
|
||||
@@ -13,7 +13,7 @@ describe('PrepareLabel', () => {
|
||||
const flat = (s: string | undefined) => (s ?? '').replace(/\n/g, '');
|
||||
|
||||
it('renders plain label when no match (short label)', () => {
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, unmount } = render(
|
||||
<PrepareLabel
|
||||
label="simple command"
|
||||
userInput=""
|
||||
@@ -23,11 +23,12 @@ describe('PrepareLabel', () => {
|
||||
/>,
|
||||
);
|
||||
expect(lastFrame()).toMatchSnapshot();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('truncates long label when collapsed and no match', () => {
|
||||
const long = 'x'.repeat(MAX_WIDTH + 25);
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, unmount } = render(
|
||||
<PrepareLabel
|
||||
label={long}
|
||||
userInput=""
|
||||
@@ -40,11 +41,12 @@ describe('PrepareLabel', () => {
|
||||
expect(f.endsWith('...')).toBe(true);
|
||||
expect(f.length).toBe(MAX_WIDTH + 3);
|
||||
expect(out).toMatchSnapshot();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('shows full long label when expanded and no match', () => {
|
||||
const long = 'y'.repeat(MAX_WIDTH + 25);
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, unmount } = render(
|
||||
<PrepareLabel
|
||||
label={long}
|
||||
userInput=""
|
||||
@@ -56,13 +58,14 @@ describe('PrepareLabel', () => {
|
||||
const f = flat(out);
|
||||
expect(f.length).toBe(long.length);
|
||||
expect(out).toMatchSnapshot();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('highlights matched substring when expanded (text only visible)', () => {
|
||||
const label = 'run: git commit -m "feat: add search"';
|
||||
const userInput = 'commit';
|
||||
const matchedIndex = label.indexOf(userInput);
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, unmount } = render(
|
||||
<PrepareLabel
|
||||
label={label}
|
||||
userInput={userInput}
|
||||
@@ -72,6 +75,7 @@ describe('PrepareLabel', () => {
|
||||
/>,
|
||||
);
|
||||
expect(lastFrame()).toMatchSnapshot();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('creates centered window around match when collapsed', () => {
|
||||
@@ -80,7 +84,7 @@ describe('PrepareLabel', () => {
|
||||
const suffix = '/and/then/some/more/components/'.repeat(3);
|
||||
const label = prefix + core + suffix;
|
||||
const matchedIndex = prefix.length;
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, unmount } = render(
|
||||
<PrepareLabel
|
||||
label={label}
|
||||
userInput={core}
|
||||
@@ -95,6 +99,7 @@ describe('PrepareLabel', () => {
|
||||
expect(f.startsWith('...')).toBe(true);
|
||||
expect(f.endsWith('...')).toBe(true);
|
||||
expect(out).toMatchSnapshot();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('truncates match itself when match is very long', () => {
|
||||
@@ -103,7 +108,7 @@ describe('PrepareLabel', () => {
|
||||
const suffix = ' in this text';
|
||||
const label = prefix + core + suffix;
|
||||
const matchedIndex = prefix.length;
|
||||
const { lastFrame } = render(
|
||||
const { lastFrame, unmount } = render(
|
||||
<PrepareLabel
|
||||
label={label}
|
||||
userInput={core}
|
||||
@@ -119,5 +124,6 @@ describe('PrepareLabel', () => {
|
||||
expect(f.endsWith('...')).toBe(true);
|
||||
expect(f.length).toBe(MAX_WIDTH + 2);
|
||||
expect(out).toMatchSnapshot();
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user