test(08-02): add failing test for formatTimestamp utility
RED phase: Create test file with 6 test cases for timestamp formatting: - "Just now" for messages within last minute - "X minutes ago" for messages within last hour - "X hours ago" for messages within last day - "Yesterday" for previous day messages - Date format (MM/DD/YYYY) for older messages - Graceful handling of invalid dates Install dayjs for timestamp formatting utility. Tests fail as expected (utility not implemented yet). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
03e85e6356
commit
b4fe7aaaa0
|
|
@ -32,6 +32,7 @@
|
|||
"classnames": "^2.2.6",
|
||||
"creditcard.js": "^3.0.33",
|
||||
"custom-protocol-check": "^1.4.0",
|
||||
"dayjs": "^1.11.19",
|
||||
"echarts": "^4.9.0",
|
||||
"echarts-for-react": "^2.0.16",
|
||||
"element-resize-event": "^3.0.3",
|
||||
|
|
@ -9496,6 +9497,12 @@
|
|||
"webidl-conversions": "^4.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/dayjs": {
|
||||
"version": "1.11.19",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.19.tgz",
|
||||
"integrity": "sha512-t5EcLVS6QPBNqM2z8fakk/NKel+Xzshgt8FFKAn+qwlD1pzZWxh0nVCrvFK7ZDb6XucZeF9z8C7CBWTRIVApAw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/debounce": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.1.tgz",
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
"classnames": "^2.2.6",
|
||||
"creditcard.js": "^3.0.33",
|
||||
"custom-protocol-check": "^1.4.0",
|
||||
"dayjs": "^1.11.19",
|
||||
"echarts": "^4.9.0",
|
||||
"echarts-for-react": "^2.0.16",
|
||||
"element-resize-event": "^3.0.3",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
import { formatTimestamp } from '../formatTimestamp';
|
||||
|
||||
describe('formatTimestamp', () => {
|
||||
test('returns "Just now" for messages within last minute', () => {
|
||||
const now = new Date();
|
||||
expect(formatTimestamp(now.toISOString())).toBe('Just now');
|
||||
});
|
||||
|
||||
test('returns "X minutes ago" for messages within last hour', () => {
|
||||
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
|
||||
expect(formatTimestamp(fiveMinutesAgo.toISOString())).toBe('5 minutes ago');
|
||||
});
|
||||
|
||||
test('returns "X hours ago" for messages within last day', () => {
|
||||
const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);
|
||||
expect(formatTimestamp(twoHoursAgo.toISOString())).toBe('2 hours ago');
|
||||
});
|
||||
|
||||
test('returns "Yesterday" for messages from previous day', () => {
|
||||
const yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
expect(formatTimestamp(yesterday.toISOString())).toMatch(/Yesterday/);
|
||||
});
|
||||
|
||||
test('returns date for older messages', () => {
|
||||
const lastWeek = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
||||
const result = formatTimestamp(lastWeek.toISOString());
|
||||
expect(result).toMatch(/\d{1,2}\/\d{1,2}\/\d{4}/); // MM/DD/YYYY format
|
||||
});
|
||||
|
||||
test('handles invalid dates gracefully', () => {
|
||||
expect(formatTimestamp(null)).toBe('');
|
||||
expect(formatTimestamp(undefined)).toBe('');
|
||||
expect(formatTimestamp('invalid')).toBe('');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue