perf(cli): memoize btw message component

This commit is contained in:
yiliang114 2026-03-20 13:21:25 +08:00
parent bd77eef46f
commit 130d6888b4
2 changed files with 38 additions and 2 deletions

View file

@ -0,0 +1,34 @@
/**
* @license
* Copyright 2025 Qwen Code
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, expect, it } from 'vitest';
import { render } from 'ink-testing-library';
import { BtwMessage } from './BtwMessage.js';
describe('BtwMessage', () => {
it('is wrapped in React.memo to avoid unnecessary layout rerenders', () => {
expect((BtwMessage as unknown as { $$typeof?: symbol }).$$typeof).toBe(
Symbol.for('react.memo'),
);
});
it('renders the side question and answer', () => {
const { lastFrame } = render(
<BtwMessage
btw={{
question: 'side question',
answer: 'side answer',
isPending: false,
}}
/>,
);
const output = lastFrame() ?? '';
expect(output).toContain('/btw');
expect(output).toContain('side question');
expect(output).toContain('side answer');
});
});