Skip to content

Commit

Permalink
added tests for time util for renderSpan and renderEstimate
Browse files Browse the repository at this point in the history
  • Loading branch information
j-s-n committed Nov 26, 2024
1 parent 0f53c6b commit aa7f611
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion ironfish/src/utils/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ describe('TimeUtils', () => {
expect(TimeUtils.renderEstimate(50, 100, 60)).toEqual('soon')
expect(TimeUtils.renderEstimate(50, 100, 20)).toEqual('2s')
expect(TimeUtils.renderEstimate(50, 200, 1)).toEqual('2m 30s')
expect(TimeUtils.renderEstimate(10, 10000, 1)).toEqual('2h 46m 30s')
expect(TimeUtils.renderEstimate(10, 10000, 1)).toEqual('2h 46m')
expect(TimeUtils.renderEstimate(10, 198010, 1)).toEqual('2d 7h')
expect(TimeUtils.renderEstimate(10, 7689610, 1)).toEqual('2M 29d')
expect(TimeUtils.renderEstimate(10, 73699210, 1)).toEqual('2y 4M 3d')
})

it('should render time spans', () => {
Expand All @@ -21,6 +24,10 @@ describe('TimeUtils', () => {
expect(TimeUtils.renderSpan(1150)).toEqual('1s 150ms')
expect(TimeUtils.renderSpan(330000)).toEqual('5m 30s')
expect(TimeUtils.renderSpan(7530000)).toEqual('2h 5m')
expect(TimeUtils.renderSpan(90000000)).toEqual('1d 1h')
expect(TimeUtils.renderSpan(7775940000)).toEqual('2M 29d')
expect(TimeUtils.renderSpan(31622400000)).toEqual('1y')
expect(TimeUtils.renderSpan(71193600000)).toEqual('2y 3M')
})

it('should render negative times', () => {
Expand All @@ -31,6 +38,10 @@ describe('TimeUtils', () => {
expect(TimeUtils.renderSpan(-1150)).toEqual('-1s 150ms')
expect(TimeUtils.renderSpan(-330000)).toEqual('-5m 30s')
expect(TimeUtils.renderSpan(-7530000)).toEqual('-2h 5m')
expect(TimeUtils.renderSpan(-90000000)).toEqual('-1d 1h')
expect(TimeUtils.renderSpan(-7775940000)).toEqual('-2M 29d')
expect(TimeUtils.renderSpan(-31622400000)).toEqual('-1y')
expect(TimeUtils.renderSpan(-71193600000)).toEqual('-2y 3M')
})
})
})
6 changes: 3 additions & 3 deletions ironfish/src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const renderEstimate = (done: number, total: number, speed: number): string => {

return renderSpan(estimate, {
forceMillisecond: false,
forceSecond: true,
forceMinute: true,
forceHour: true,
forceSecond: false,
forceMinute: false,
forceHour: false,
forceDay: true,
forceMonth: true,
forceYear: true,
Expand Down

0 comments on commit aa7f611

Please sign in to comment.