@@ -22,9 +22,10 @@ import {
2222 serializeRRule ,
2323 convertHumanReadableFrequencyToMachineReadable ,
2424 convertMachineReadableFrequencyToHumanReadable ,
25- getUnsupportedRRuleReason ,
2625 prepareDataForHashing ,
27- generateCryptoHash
26+ generateCryptoHash ,
27+ getUnsupportedRRuleReason ,
28+ roundToInteger
2829} from './utils'
2930import { CoinTransaction , ParsedResultType , Settings , HabitsData , CoinsData , WishlistData , UserData } from './types'
3031import { DateTime } from "luxon" ;
@@ -42,6 +43,33 @@ describe('cn utility', () => {
4243 } )
4344} )
4445
46+ describe ( 'roundToInteger' , ( ) => {
47+ test ( 'should round positive numbers correctly' , ( ) => {
48+ expect ( roundToInteger ( 10.123 ) ) . toBe ( 10 ) ;
49+ expect ( roundToInteger ( 10.5 ) ) . toBe ( 11 ) ;
50+ expect ( roundToInteger ( 10.75 ) ) . toBe ( 11 ) ;
51+ expect ( roundToInteger ( 10.49 ) ) . toBe ( 10 ) ;
52+ } ) ;
53+
54+ test ( 'should round negative numbers correctly' , ( ) => {
55+ expect ( roundToInteger ( - 10.123 ) ) . toBe ( - 10 ) ;
56+ expect ( roundToInteger ( - 10.5 ) ) . toBe ( - 10 ) ; // Math.round rounds -x.5 to -(x-1) e.g. -10.5 to -10
57+ expect ( roundToInteger ( - 10.75 ) ) . toBe ( - 11 ) ;
58+ expect ( roundToInteger ( - 10.49 ) ) . toBe ( - 10 ) ;
59+ } ) ;
60+
61+ test ( 'should handle zero correctly' , ( ) => {
62+ expect ( roundToInteger ( 0 ) ) . toBe ( 0 ) ;
63+ expect ( roundToInteger ( 0.0 ) ) . toBe ( 0 ) ;
64+ expect ( roundToInteger ( - 0.0 ) ) . toBe ( - 0 ) ;
65+ } ) ;
66+
67+ test ( 'should handle integers correctly' , ( ) => {
68+ expect ( roundToInteger ( 15 ) ) . toBe ( 15 ) ;
69+ expect ( roundToInteger ( - 15 ) ) . toBe ( - 15 ) ;
70+ } ) ;
71+ } ) ;
72+
4573describe ( 'getUnsupportedRRuleReason' , ( ) => {
4674 test ( 'should return message for HOURLY frequency' , ( ) => {
4775 const rrule = new RRule ( { freq : RRule . HOURLY } ) ;
@@ -142,7 +170,7 @@ describe('isTaskOverdue', () => {
142170 // Create a task due "tomorrow" in UTC
143171 const tomorrow = DateTime . now ( ) . plus ( { days : 1 } ) . toUTC ( ) . toISO ( )
144172 const habit = createTestHabit ( tomorrow )
145-
173+
146174 // Test in various timezones
147175 expect ( isTaskOverdue ( habit , 'UTC' ) ) . toBe ( false )
148176 expect ( isTaskOverdue ( habit , 'America/New_York' ) ) . toBe ( false )
@@ -597,7 +625,7 @@ describe('isHabitDueToday', () => {
597625
598626 test ( 'should return false for invalid recurrence rule' , ( ) => {
599627 const habit = testHabit ( 'INVALID_RRULE' )
600- const consoleSpy = spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
628+ const consoleSpy = spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
601629 expect ( isHabitDueToday ( { habit, timezone : 'UTC' } ) ) . toBe ( false )
602630 } )
603631} )
@@ -710,7 +738,7 @@ describe('isHabitDue', () => {
710738 test ( 'should return false for invalid recurrence rule' , ( ) => {
711739 const habit = testHabit ( 'INVALID_RRULE' )
712740 const date = DateTime . fromISO ( '2024-01-01T00:00:00Z' )
713- const consoleSpy = spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
741+ const consoleSpy = spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
714742 expect ( isHabitDue ( { habit, timezone : 'UTC' , date } ) ) . toBe ( false )
715743 } )
716744} )
0 commit comments