@@ -29,6 +29,13 @@ import { clearQuoteStats } from "../states/quote-rate";
2929import * as Result from "./result" ;
3030import { getActivePage , isAuthenticated } from "../states/core" ;
3131import {
32+ getIncompleteSeconds ,
33+ getIncompleteTests ,
34+ getRestartCount ,
35+ pushIncompleteTest ,
36+ resetIncompleteTests ,
37+ setIsTestInvalid ,
38+ setLastResult ,
3239 setResultVisible ,
3340 setWordsHaveNewline ,
3441 setWordsHaveTab ,
@@ -271,10 +278,8 @@ export function restart(options = {} as RestartOptions): void {
271278 const afkseconds = TestStats . calculateAfkSeconds ( testSeconds ) ;
272279 let tt = Numbers . roundTo2 ( testSeconds - afkseconds ) ;
273280 if ( tt < 0 ) tt = 0 ;
274- TestState . incrementIncompleteSeconds ( tt ) ;
275- TestState . incrementRestartCount ( ) ;
276281 const acc = Numbers . roundTo2 ( TestStats . calculateAccuracy ( ) ) ;
277- TestState . pushIncompleteTest ( acc , tt ) ;
282+ pushIncompleteTest ( { acc, seconds : tt } ) ;
278283 }
279284 }
280285
@@ -316,6 +321,7 @@ export function restart(options = {} as RestartOptions): void {
316321
317322 resetTestEvents ( ) ;
318323 TestTimer . clear ( ) ;
324+ setIsTestInvalid ( false ) ;
319325 TestStats . restart ( ) ;
320326 TestInput . restart ( ) ;
321327 TestInput . corrected . reset ( ) ;
@@ -865,12 +871,10 @@ function buildCompletedEvent(
865871 lazyMode : Config . lazyMode ,
866872 timestamp : Date . now ( ) ,
867873 language : language ,
868- restartCount : TestState . restartCount ,
869- incompleteTests : TestState . incompleteTests ,
874+ restartCount : getRestartCount ( ) ,
875+ incompleteTests : getIncompleteTests ( ) ,
870876 incompleteTestSeconds :
871- TestState . incompleteSeconds < 0
872- ? 0
873- : Numbers . roundTo2 ( TestState . incompleteSeconds ) ,
877+ getIncompleteSeconds ( ) < 0 ? 0 : Numbers . roundTo2 ( getIncompleteSeconds ( ) ) ,
874878 difficulty : Config . difficulty ,
875879 blindMode : Config . blindMode ,
876880 tags : activeTagsIds ,
@@ -1383,7 +1387,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
13831387
13841388 const completedEvent = structuredClone ( ce ) as CompletedEvent ;
13851389
1386- TestStats . setLastResult ( structuredClone ( completedEvent ) ) ;
1390+ setLastResult ( structuredClone ( completedEvent ) ) ;
13871391
13881392 ///////// completed event ready
13891393
@@ -1406,7 +1410,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
14061410 ) {
14071411 showNoticeNotification ( "Test invalid - inconsistent test duration" ) ;
14081412 console . error ( "Test duration inconsistent" , ce . testDuration , dateDur ) ;
1409- TestStats . setInvalid ( ) ;
1413+ setIsTestInvalid ( true ) ;
14101414 dontSave = true ;
14111415 } else if ( difficultyFailed ) {
14121416 showNoticeNotification ( `Test failed - ${ failReason } ` , {
@@ -1433,16 +1437,16 @@ export async function finish(difficultyFailed = false): Promise<void> {
14331437 ( Config . mode === "zen" && completedEvent . testDuration < 15 )
14341438 ) {
14351439 showNoticeNotification ( "Test invalid - too short" ) ;
1436- TestStats . setInvalid ( ) ;
1440+ setIsTestInvalid ( true ) ;
14371441 tooShort = true ;
14381442 dontSave = true ;
14391443 } else if ( afkDetected ) {
14401444 showNoticeNotification ( "Test invalid - AFK detected" ) ;
1441- TestStats . setInvalid ( ) ;
1445+ setIsTestInvalid ( true ) ;
14421446 dontSave = true ;
14431447 } else if ( TestState . isRepeated ) {
14441448 showNoticeNotification ( "Test invalid - repeated" ) ;
1445- TestStats . setInvalid ( ) ;
1449+ setIsTestInvalid ( true ) ;
14461450 dontSave = true ;
14471451 } else if (
14481452 completedEvent . wpm < 0 ||
@@ -1454,7 +1458,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
14541458 completedEvent . mode2 === "10" )
14551459 ) {
14561460 showNoticeNotification ( "Test invalid - wpm" ) ;
1457- TestStats . setInvalid ( ) ;
1461+ setIsTestInvalid ( true ) ;
14581462 dontSave = true ;
14591463 } else if (
14601464 completedEvent . rawWpm < 0 ||
@@ -1466,7 +1470,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
14661470 completedEvent . mode2 === "10" )
14671471 ) {
14681472 showNoticeNotification ( "Test invalid - raw" ) ;
1469- TestStats . setInvalid ( ) ;
1473+ setIsTestInvalid ( true ) ;
14701474 dontSave = true ;
14711475 } else if (
14721476 ( ! DB . getSnapshot ( ) ?. lbOptOut &&
@@ -1475,7 +1479,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
14751479 ( completedEvent . acc < 50 || completedEvent . acc > 100 ) )
14761480 ) {
14771481 showNoticeNotification ( "Test invalid - accuracy" ) ;
1478- TestStats . setInvalid ( ) ;
1482+ setIsTestInvalid ( true ) ;
14791483 dontSave = true ;
14801484 }
14811485
@@ -1488,9 +1492,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
14881492 let tt = Numbers . roundTo2 ( testSeconds - afkseconds ) ;
14891493 if ( tt < 0 ) tt = 0 ;
14901494 const acc = completedEvent . acc ;
1491- TestState . incrementIncompleteSeconds ( tt ) ;
1492- TestState . incrementRestartCount ( ) ;
1493- TestState . pushIncompleteTest ( acc , tt ) ;
1495+ pushIncompleteTest ( { acc, seconds : tt } ) ;
14941496 }
14951497 }
14961498
@@ -1550,7 +1552,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
15501552 if ( dontSave ) {
15511553 void AnalyticsController . log ( "testCompletedInvalid" ) ;
15521554 } else {
1553- TestState . resetIncomplete ( ) ;
1555+ resetIncompleteTests ( ) ;
15541556
15551557 if ( ! completedEvent . bailedOut ) {
15561558 const challenge = ChallengeContoller . verify ( completedEvent ) ;
0 commit comments