Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekelund committed Jan 14, 2025
1 parent a86b645 commit be13399
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/ai-clear-history-reminder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Button from './button';
function shouldShowReminder( lastMessage?: MessageType ) {
return (
lastMessage?.role === 'assistant' &&
Date.now() - lastMessage?.createdAt > CLEAR_HISTORY_REMINDER_TIME
Date.now() - ( lastMessage?.createdAt ?? 0 ) > CLEAR_HISTORY_REMINDER_TIME
);
}

Expand Down
15 changes: 8 additions & 7 deletions src/components/tests/ai-clear-history-reminder.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
import { CLEAR_HISTORY_REMINDER_TIME } from '../../constants';
import { getIpcApi } from '../../lib/get-ipc-api';
import AIClearHistoryReminder from '../ai-clear-history-reminder';
import type { Message } from '../../hooks/use-assistant';
Expand All @@ -7,15 +8,15 @@ jest.mock( '../../lib/get-ipc-api' );

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

beforeEach( () => {
window.HTMLElement.prototype.scrollIntoView = jest.fn();
clearConversation = jest.fn();
jest.clearAllMocks();
jest.useFakeTimers();
jest.setSystemTime( MOCKED_TIME );
jest.setSystemTime( MOCKED_CURRENT_TIME );
} );

afterEach( () => {
Expand All @@ -25,7 +26,7 @@ describe( 'AIClearHistoryReminder', () => {
it( 'should display a reminder when the conversation is stale', () => {
const message: Message = {
id: 0,
createdAt: MOCKED_TIME - TWO_HOURS_DIFF,
createdAt: OLD_MESSAGE_TIME,
content: '',
role: 'assistant',
};
Expand All @@ -42,7 +43,7 @@ describe( 'AIClearHistoryReminder', () => {
} );
const message: Message = {
id: 0,
createdAt: MOCKED_TIME - TWO_HOURS_DIFF,
createdAt: OLD_MESSAGE_TIME,
content: '',
role: 'assistant',
};
Expand All @@ -65,7 +66,7 @@ describe( 'AIClearHistoryReminder', () => {
} );
const message: Message = {
id: 0,
createdAt: MOCKED_TIME - TWO_HOURS_DIFF,
createdAt: OLD_MESSAGE_TIME,
content: '',
role: 'assistant',
};
Expand Down

0 comments on commit be13399

Please sign in to comment.