@@ -33,22 +33,38 @@ describe('Progress Store', () => {
3333 state . setProgress ( 150 ) ;
3434 expect ( useAppStore . getState ( ) . progress ) . toBe ( 100 ) ;
3535
36- // Test negative value (should not go backwards from current value)
37- const currentWholeProgress = useAppStore . getState ( ) . wholeProgress ;
36+ // Test negative value - should clamp to 0
3837 state . setWholeProgress ( - 10 ) ;
39- // Should maintain current value due to backward progress prevention
40- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( currentWholeProgress ) ;
38+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
4139
42- // Test null/undefined with backward progress prevention
43- // Progress is already at 100%, so null (treated as 0) won't decrease it
44- const currentProgress = useAppStore . getState ( ) . progress ;
40+ // Test null/undefined - should reset to 0
4541 state . setProgress ( null as any ) ;
46- expect ( useAppStore . getState ( ) . progress ) . toBe ( currentProgress ) ; // Should stay at 100%
42+ expect ( useAppStore . getState ( ) . progress ) . toBe ( 0 ) ;
4743
4844 // Same for wholeProgress
49- const currentWhole = useAppStore . getState ( ) . wholeProgress ;
5045 state . setWholeProgress ( undefined as any ) ;
51- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( currentWhole ) ;
46+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
47+ } ) ;
48+
49+ it ( 'should prevent backward progress during translation' , ( ) => {
50+ const state = useAppStore . getState ( ) ;
51+
52+ // Set initial progress and start translating
53+ state . setWholeProgress ( 50 ) ;
54+ state . setTranslating ( true ) ;
55+
56+ // Try to set progress backwards - should maintain current value
57+ state . setWholeProgress ( 30 ) ;
58+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 50 ) ;
59+
60+ // Allow setting to 0 even when translating
61+ state . setWholeProgress ( 0 ) ;
62+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
63+
64+ // Allow progress when not translating
65+ state . setTranslating ( false ) ;
66+ state . setWholeProgress ( 25 ) ;
67+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 25 ) ;
5268 } ) ;
5369
5470 it ( 'should manage translation state' , ( ) => {
@@ -92,19 +108,22 @@ describe('Progress Store', () => {
92108
93109 state . incrementCompletedChunks ( ) ;
94110 expect ( useAppStore . getState ( ) . completedChunks ) . toBe ( 1 ) ;
95- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 10 ) ; // 1/10 * 100
111+ // incrementCompletedChunks doesn't update wholeProgress
112+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
96113
97114 state . incrementCompletedChunks ( ) ;
98115 state . incrementCompletedChunks ( ) ;
99116 expect ( useAppStore . getState ( ) . completedChunks ) . toBe ( 3 ) ;
100- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 30 ) ; // 3/10 * 100
117+ // incrementCompletedChunks doesn't update wholeProgress
118+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
101119
102120 // Test bounds - shouldn't exceed totalChunks
103121 state . setCompletedChunks ( 9 ) ;
104122 state . incrementCompletedChunks ( ) ; // Should go to 10
105123 state . incrementCompletedChunks ( ) ; // Should stay at 10
106124 expect ( useAppStore . getState ( ) . completedChunks ) . toBe ( 10 ) ;
107- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 100 ) ;
125+ // incrementCompletedChunks doesn't update wholeProgress
126+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
108127 } ) ;
109128
110129 it ( 'should update progress tracking correctly' , ( ) => {
@@ -114,14 +133,16 @@ describe('Progress Store', () => {
114133 const currentState = useAppStore . getState ( ) ;
115134 expect ( currentState . completedChunks ) . toBe ( 7 ) ;
116135 expect ( currentState . totalChunks ) . toBe ( 20 ) ;
117- expect ( currentState . wholeProgress ) . toBe ( 35 ) ; // 7/20 * 100
136+ // updateProgressTracking doesn't update wholeProgress anymore
137+ expect ( currentState . wholeProgress ) . toBe ( 0 ) ;
118138
119139 // Test with completed > total
120140 state . updateProgressTracking ( 15 , 10 ) ;
121141 const updatedState = useAppStore . getState ( ) ;
122142 expect ( updatedState . completedChunks ) . toBe ( 10 ) ; // Capped at total
123143 expect ( updatedState . totalChunks ) . toBe ( 10 ) ;
124- expect ( updatedState . wholeProgress ) . toBe ( 100 ) ;
144+ // updateProgressTracking doesn't update wholeProgress anymore
145+ expect ( updatedState . wholeProgress ) . toBe ( 0 ) ;
125146 } ) ;
126147 } ) ;
127148
@@ -196,12 +217,12 @@ describe('Progress Store', () => {
196217 it ( 'should round progress values correctly' , ( ) => {
197218 const state = useAppStore . getState ( ) ;
198219
199- // Test chunk progress rounding
220+ // Test chunk progress rounding - updateProgressTracking doesn't update wholeProgress
200221 state . updateProgressTracking ( 1 , 3 ) ; // 33.333...%
201- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 33 ) ;
222+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
202223
203224 state . updateProgressTracking ( 2 , 3 ) ; // 66.666...%
204- expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 67 ) ;
225+ expect ( useAppStore . getState ( ) . wholeProgress ) . toBe ( 0 ) ;
205226
206227 // Test mod progress rounding
207228 state . updateModProgress ( 1 , 7 ) ; // 14.285...%
0 commit comments