Skip to content

Commit be13399

Browse files
Fix tests
1 parent a86b645 commit be13399

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/components/ai-clear-history-reminder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Button from './button';
99
function shouldShowReminder( lastMessage?: MessageType ) {
1010
return (
1111
lastMessage?.role === 'assistant' &&
12-
Date.now() - lastMessage?.createdAt > CLEAR_HISTORY_REMINDER_TIME
12+
Date.now() - ( lastMessage?.createdAt ?? 0 ) > CLEAR_HISTORY_REMINDER_TIME
1313
);
1414
}
1515

src/components/tests/ai-clear-history-reminder.test.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
1+
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
2+
import { CLEAR_HISTORY_REMINDER_TIME } from '../../constants';
23
import { getIpcApi } from '../../lib/get-ipc-api';
34
import AIClearHistoryReminder from '../ai-clear-history-reminder';
45
import type { Message } from '../../hooks/use-assistant';
@@ -7,15 +8,15 @@ jest.mock( '../../lib/get-ipc-api' );
78

89
describe( 'AIClearHistoryReminder', () => {
910
let clearConversation: jest.Mock;
10-
const MOCKED_TIME = 1718882159928;
11-
const TWO_HOURS_DIFF = 2 * 60 * 60 * 1000;
11+
const MOCKED_CURRENT_TIME = 1718882159928;
12+
const OLD_MESSAGE_TIME = MOCKED_CURRENT_TIME - CLEAR_HISTORY_REMINDER_TIME - 1;
1213

1314
beforeEach( () => {
1415
window.HTMLElement.prototype.scrollIntoView = jest.fn();
1516
clearConversation = jest.fn();
1617
jest.clearAllMocks();
1718
jest.useFakeTimers();
18-
jest.setSystemTime( MOCKED_TIME );
19+
jest.setSystemTime( MOCKED_CURRENT_TIME );
1920
} );
2021

2122
afterEach( () => {
@@ -25,7 +26,7 @@ describe( 'AIClearHistoryReminder', () => {
2526
it( 'should display a reminder when the conversation is stale', () => {
2627
const message: Message = {
2728
id: 0,
28-
createdAt: MOCKED_TIME - TWO_HOURS_DIFF,
29+
createdAt: OLD_MESSAGE_TIME,
2930
content: '',
3031
role: 'assistant',
3132
};
@@ -42,7 +43,7 @@ describe( 'AIClearHistoryReminder', () => {
4243
} );
4344
const message: Message = {
4445
id: 0,
45-
createdAt: MOCKED_TIME - TWO_HOURS_DIFF,
46+
createdAt: OLD_MESSAGE_TIME,
4647
content: '',
4748
role: 'assistant',
4849
};
@@ -65,7 +66,7 @@ describe( 'AIClearHistoryReminder', () => {
6566
} );
6667
const message: Message = {
6768
id: 0,
68-
createdAt: MOCKED_TIME - TWO_HOURS_DIFF,
69+
createdAt: OLD_MESSAGE_TIME,
6970
content: '',
7071
role: 'assistant',
7172
};

0 commit comments

Comments
 (0)