test(cli): refactor tests for async render utilities (#23252)

This commit is contained in:
Tommaso Sciortino
2026-03-20 20:08:29 +00:00
committed by GitHub
parent 86a3a913b5
commit 6c78eb7a39
198 changed files with 3592 additions and 4802 deletions

View File

@@ -11,13 +11,13 @@ import { useHistory } from './useHistoryManager.js';
import type { HistoryItem } from '../types.js';
describe('useHistoryManager', () => {
it('should initialize with an empty history', () => {
const { result } = renderHook(() => useHistory());
it('should initialize with an empty history', async () => {
const { result } = await renderHook(() => useHistory());
expect(result.current.history).toEqual([]);
});
it('should add an item to history with a unique ID', () => {
const { result } = renderHook(() => useHistory());
it('should add an item to history with a unique ID', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const itemData: Omit<HistoryItem, 'id'> = {
type: 'user', // Replaced HistoryItemType.User
@@ -39,8 +39,8 @@ describe('useHistoryManager', () => {
expect(result.current.history[0].id).toBeGreaterThanOrEqual(timestamp);
});
it('should generate unique IDs for items added with the same base timestamp', () => {
const { result } = renderHook(() => useHistory());
it('should generate unique IDs for items added with the same base timestamp', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const itemData1: Omit<HistoryItem, 'id'> = {
type: 'user', // Replaced HistoryItemType.User
@@ -67,8 +67,8 @@ describe('useHistoryManager', () => {
expect(id2).toBeGreaterThan(id1);
});
it('should update an existing history item', () => {
const { result } = renderHook(() => useHistory());
it('should update an existing history item', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const initialItem: Omit<HistoryItem, 'id'> = {
type: 'gemini', // Replaced HistoryItemType.Gemini
@@ -93,8 +93,8 @@ describe('useHistoryManager', () => {
});
});
it('should not change history if updateHistoryItem is called with a nonexistent ID', () => {
const { result } = renderHook(() => useHistory());
it('should not change history if updateHistoryItem is called with a nonexistent ID', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const itemData: Omit<HistoryItem, 'id'> = {
type: 'user', // Replaced HistoryItemType.User
@@ -114,8 +114,8 @@ describe('useHistoryManager', () => {
expect(result.current.history).toEqual(originalHistory);
});
it('should clear the history', () => {
const { result } = renderHook(() => useHistory());
it('should clear the history', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const itemData1: Omit<HistoryItem, 'id'> = {
type: 'user', // Replaced HistoryItemType.User
@@ -140,8 +140,8 @@ describe('useHistoryManager', () => {
expect(result.current.history).toEqual([]);
});
it('should not add consecutive duplicate user messages', () => {
const { result } = renderHook(() => useHistory());
it('should not add consecutive duplicate user messages', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const itemData1: Omit<HistoryItem, 'id'> = {
type: 'user', // Replaced HistoryItemType.User
@@ -173,8 +173,8 @@ describe('useHistoryManager', () => {
expect(result.current.history[2].text).toBe('Another user message');
});
it('should add duplicate user messages if they are not consecutive', () => {
const { result } = renderHook(() => useHistory());
it('should add duplicate user messages if they are not consecutive', async () => {
const { result } = await renderHook(() => useHistory());
const timestamp = Date.now();
const itemData1: Omit<HistoryItem, 'id'> = {
type: 'user', // Replaced HistoryItemType.User
@@ -201,8 +201,8 @@ describe('useHistoryManager', () => {
expect(result.current.history[2].text).toBe('Message 1');
});
it('should use Date.now() as default baseTimestamp if not provided', () => {
const { result } = renderHook(() => useHistory());
it('should use Date.now() as default baseTimestamp if not provided', async () => {
const { result } = await renderHook(() => useHistory());
const before = Date.now();
const itemData: Omit<HistoryItem, 'id'> = {
type: 'user',
@@ -221,7 +221,7 @@ describe('useHistoryManager', () => {
});
describe('initialItems with auth information', () => {
it('should initialize with auth information', () => {
it('should initialize with auth information', async () => {
const email = 'user@example.com';
const tier = 'Pro';
const authMessage = `Authenticated as: ${email} (Plan: ${tier})`;
@@ -232,13 +232,13 @@ describe('useHistoryManager', () => {
text: authMessage,
},
];
const { result } = renderHook(() => useHistory({ initialItems }));
const { result } = await renderHook(() => useHistory({ initialItems }));
expect(result.current.history).toHaveLength(1);
expect(result.current.history[0].text).toBe(authMessage);
});
it('should add items with auth information via addItem', () => {
const { result } = renderHook(() => useHistory());
it('should add items with auth information via addItem', async () => {
const { result } = await renderHook(() => useHistory());
const email = 'user@example.com';
const tier = 'Pro';
const authMessage = `Authenticated as: ${email} (Plan: ${tier})`;