Skip to content

Commit eab8eef

Browse files
committed
refactor: extract code so that it can be used in other places
1 parent 2e78d9f commit eab8eef

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

frontend/src/ts/test/test-logic.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,8 @@ export async function init(): Promise<void> {
508508
);
509509
}
510510

511-
//add word during the test
512-
export async function addWord(): Promise<void> {
513-
let bound = 100; // how many extra words to aim for AFTER the current word
514-
const funboxToPush = FunboxList.get(Config.funbox)
515-
.find((f) => f.properties?.find((fp) => fp.startsWith("toPush")))
516-
?.properties?.find((fp) => fp.startsWith("toPush:"));
517-
const toPushCount = funboxToPush?.split(":")[1];
518-
if (toPushCount !== undefined) bound = +toPushCount - 1;
519-
if (
520-
TestWords.words.length - TestInput.input.history.length > bound ||
511+
export function areAllTestWordsGenerated(): boolean {
512+
return (
521513
(Config.mode === "words" &&
522514
TestWords.words.length >= Config.words &&
523515
Config.words > 0) ||
@@ -533,6 +525,20 @@ export async function addWord(): Promise<void> {
533525
WordsGenerator.sectionIndex >= CustomText.getLimitValue() &&
534526
WordsGenerator.currentSection.length === 0 &&
535527
CustomText.getLimitValue() !== 0)
528+
);
529+
}
530+
531+
//add word during the test
532+
export async function addWord(): Promise<void> {
533+
let bound = 100; // how many extra words to aim for AFTER the current word
534+
const funboxToPush = FunboxList.get(Config.funbox)
535+
.find((f) => f.properties?.find((fp) => fp.startsWith("toPush")))
536+
?.properties?.find((fp) => fp.startsWith("toPush:"));
537+
const toPushCount = funboxToPush?.split(":")[1];
538+
if (toPushCount !== undefined) bound = +toPushCount - 1;
539+
if (
540+
TestWords.words.length - TestInput.input.history.length > bound ||
541+
areAllTestWordsGenerated()
536542
) {
537543
return;
538544
}

0 commit comments

Comments
 (0)