-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test to summariseTimeOnline. Fix sleep and wake times.
- Loading branch information
Maigo Erit
committed
May 25, 2020
1 parent
fe7e3bb
commit 9103ea7
Showing
8 changed files
with
623 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
client/src/components/SummaryCalendar/SummaryCalendar.util.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { summariseTimeOnline } from './SummaryCalendar.util'; | ||
import { TEST_INPUT } from './SummaryCalendar.util.testdata'; | ||
import moment from 'moment'; | ||
|
||
describe('summariseTimeOnline', () => { | ||
it('parses online items', () => { | ||
const actual = summariseTimeOnline(TEST_INPUT, 'month'); | ||
const result = { | ||
'12': { beginDate: 1589311528755, endDate: 1589312113568, online: 358396 }, | ||
'14': { beginDate: 1589480558049, endDate: 1589483666850, online: 2707998 }, | ||
'24': { beginDate: 1590354279611, endDate: 1590357497348, online: 3085853 }, | ||
'25': { beginDate: 1590375522178, endDate: 1590388476539, online: 1527164 }, | ||
}; | ||
|
||
expect(actual).toEqual(result); | ||
}); | ||
|
||
it('online item over midnight - until 04:00 - it goes to previous day', () => { | ||
const input = [ | ||
{ | ||
app: 'ONLINE', | ||
beginDate: moment('2020-04-10 02:30').valueOf(), | ||
endDate: moment('2020-04-10 03:30').valueOf(), | ||
}, | ||
]; | ||
const actual = summariseTimeOnline(input, 'month'); | ||
const result = { | ||
'9': { | ||
beginDate: moment('2020-04-10 02:30').valueOf(), | ||
endDate: moment('2020-04-10 03:30').valueOf(), | ||
online: 3600000, | ||
}, | ||
}; | ||
|
||
expect(actual).toEqual(result); | ||
}); | ||
|
||
it('online item after 04:00 goes to correct day', () => { | ||
const input = [ | ||
{ | ||
app: 'ONLINE', | ||
beginDate: moment('2020-04-10 04:30').valueOf(), | ||
endDate: moment('2020-04-10 05:30').valueOf(), | ||
}, | ||
]; | ||
const actual = summariseTimeOnline(input, 'month'); | ||
const result = { | ||
'10': { | ||
beginDate: moment('2020-04-10 04:30').valueOf(), | ||
endDate: moment('2020-04-10 05:30').valueOf(), | ||
online: 3600000, | ||
}, | ||
}; | ||
|
||
expect(actual).toEqual(result); | ||
}); | ||
|
||
it('woke up 04:30 and went to sleep 03:30', () => { | ||
const input = [ | ||
{ | ||
app: 'ONLINE', | ||
beginDate: moment('2020-04-10 04:30').valueOf(), | ||
endDate: moment('2020-04-10 05:30').valueOf(), | ||
}, | ||
{ | ||
app: 'ONLINE', | ||
beginDate: moment('2020-04-10 11:30').valueOf(), | ||
endDate: moment('2020-04-10 15:30').valueOf(), | ||
}, | ||
{ | ||
app: 'ONLINE', | ||
beginDate: moment('2020-04-10 23:30').valueOf(), | ||
endDate: moment('2020-04-11 01:30').valueOf(), | ||
}, | ||
{ | ||
app: 'ONLINE', | ||
beginDate: moment('2020-04-11 02:30').valueOf(), | ||
endDate: moment('2020-04-11 03:30').valueOf(), | ||
}, | ||
]; | ||
const actual = summariseTimeOnline(input, 'month'); | ||
const result = { | ||
'10': { | ||
beginDate: moment('2020-04-10 04:30').valueOf(), | ||
endDate: moment('2020-04-11 03:30').valueOf(), | ||
online: 28800000, | ||
}, | ||
}; | ||
|
||
expect(actual).toEqual(result); | ||
}); | ||
}); | ||
|
||
export // Use an empty export to please Babel's single file emit. | ||
// https://github.com/Microsoft/TypeScript/issues/15230 | ||
{}; |
Oops, something went wrong.