Skip to content

Commit 94eec29

Browse files
test: Add tests for formatDateForServer
1 parent 7b765a1 commit 94eec29

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

specifyweb/frontend/js_src/lib/components/Notifications/__tests__/useNotificationsFetch.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { formatDateForBackEnd } from '../../../utils/parser/dateFormat';
99
import { formatUrl } from '../../Router/queryString';
1010
import { exportsForTests, useNotificationsFetch } from '../hooks';
1111

12-
const { INITIAL_INTERVAL, mergeAndSortNotifications } = exportsForTests;
12+
const { INITIAL_INTERVAL, mergeAndSortNotifications, formatDateForServer } = exportsForTests;
1313

1414
test.skip('Verify notifications are fetched when isOpen is true', async () => {
1515
const freezeFetchPromise: MutableRefObject<Promise<void> | undefined> = {
@@ -226,3 +226,12 @@ describe('fetch notifications', () => {
226226
});
227227
});
228228
});
229+
230+
test('formatDateForServer correctly formats ISO date strings for API requests', () => {
231+
expect(formatDateForServer('2023-09-19T01:22:00')).toBe('2023-09-19 01:22:00');
232+
expect(formatDateForServer('2023-09-19T01:22:00.123456')).toBe('2023-09-19 01:22:00');
233+
expect(formatDateForServer('2023-09-19T01:22:00Z')).toBe('2023-09-19 01:22:00');
234+
expect(formatDateForServer('2023-09-19T01:22:00.123456Z')).toBe('2023-09-19 01:22:00');
235+
const invalidString = 'not-a-date';
236+
expect(formatDateForServer(invalidString)).toBe(invalidString);
237+
});

specifyweb/frontend/js_src/lib/components/Notifications/hooks.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@ function formatDateForServer(isoString: string): string {
180180
export const exportsForTests = {
181181
INITIAL_INTERVAL,
182182
mergeAndSortNotifications,
183+
formatDateForServer,
183184
};

0 commit comments

Comments
 (0)