Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
389a208
fix: stopOnError: word has no effect in nospace
Leonabcd123 Jun 23, 2026
d6343db
Return type
Leonabcd123 Jun 23, 2026
f8e377f
Remove
Leonabcd123 Jun 23, 2026
daf2ea8
🐬
Leonabcd123 Jun 23, 2026
a0d87c4
More
Leonabcd123 Jun 23, 2026
44c25f2
More
Leonabcd123 Jun 23, 2026
1456108
Comment
Leonabcd123 Jun 22, 2026
f08bc73
Comment
Leonabcd123 Jun 23, 2026
e51ec2b
More
Leonabcd123 Jun 23, 2026
cbd267d
Remove charIsSpace
Leonabcd123 Jun 23, 2026
3b6c7a5
Remove charIsNewline
Leonabcd123 Jun 23, 2026
5f5476d
Optional
Leonabcd123 Jun 23, 2026
0984844
Revert "Optional"
Leonabcd123 Jun 23, 2026
85fd611
Less
Leonabcd123 Jun 23, 2026
a8b2e7b
Fix tests
Leonabcd123 Jun 23, 2026
4a0cf88
Guard + comment
Leonabcd123 Jun 23, 2026
24f6f02
Refactor
Leonabcd123 Jun 23, 2026
332da71
Refactor
Leonabcd123 Jun 23, 2026
2895c0f
Comment
Leonabcd123 Jun 23, 2026
c8a8091
Rename
Leonabcd123 Jun 23, 2026
a2a8a57
Less calls
Leonabcd123 Jun 23, 2026
82d7361
Comment
Leonabcd123 Jun 23, 2026
1ea7034
Invert
Leonabcd123 Jun 23, 2026
68f9d70
Comment
Leonabcd123 Jun 23, 2026
a435967
Options
Leonabcd123 Jun 23, 2026
3ed2414
Type
Leonabcd123 Jun 23, 2026
3303c4d
Rename
Leonabcd123 Jun 23, 2026
ce8d723
Remove intersection
Leonabcd123 Jun 23, 2026
4fe8adf
Revert "Remove intersection"
Leonabcd123 Jun 23, 2026
b03d333
Revert "Rename"
Leonabcd123 Jun 23, 2026
722a61a
Revert "Type"
Leonabcd123 Jun 23, 2026
cc66762
Fix
Leonabcd123 Jun 23, 2026
7eac0dd
Remove
Leonabcd123 Jun 23, 2026
f75ebf6
Better
Leonabcd123 Jun 23, 2026
07d4dd9
Fix tests
Leonabcd123 Jun 23, 2026
c925cec
Ref
Leonabcd123 Jun 24, 2026
b8b3e44
Fix
Leonabcd123 Jun 24, 2026
87ec508
Better
Leonabcd123 Jun 24, 2026
1322d67
Remove comment
Leonabcd123 Jun 24, 2026
04e4033
Remove
Leonabcd123 Jun 24, 2026
1d22a19
Add back
Leonabcd123 Jun 24, 2026
a8c85b1
Tests
Leonabcd123 Jun 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions frontend/__tests__/input/helpers/fail-or-finish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ describe("checkIfFailedDueToDifficulty", () => {
desc: "zen mode, master - never fails",
config: { mode: "zen", difficulty: "master" },
correct: false,
spaceOrNewline: true,
isCommitChar: true,
input: "hello",
expected: false,
},
{
desc: "zen mode - never fails",
config: { mode: "zen", difficulty: "normal" },
correct: false,
spaceOrNewline: true,
isCommitChar: true,
input: "hello",
expected: false,
},
Expand All @@ -156,31 +156,31 @@ describe("checkIfFailedDueToDifficulty", () => {
desc: "normal typing incorrect- never fails",
config: { difficulty: "normal" },
correct: false,
spaceOrNewline: false,
isCommitChar: false,
input: "hello",
expected: false,
},
{
desc: "normal typing space incorrect - never fails",
config: { difficulty: "normal" },
correct: false,
spaceOrNewline: true,
isCommitChar: true,
input: "hello",
expected: false,
},
{
desc: "normal typing correct - never fails",
config: { difficulty: "normal" },
correct: true,
spaceOrNewline: false,
isCommitChar: false,
input: "hello",
expected: false,
},
{
desc: "normal typing space correct - never fails",
config: { difficulty: "normal" },
correct: true,
spaceOrNewline: true,
isCommitChar: true,
input: "hello",
expected: false,
},
Expand All @@ -189,31 +189,31 @@ describe("checkIfFailedDueToDifficulty", () => {
desc: "expert - fail if incorrect space",
config: { difficulty: "expert" },
correct: false,
spaceOrNewline: true,
isCommitChar: true,
input: "he",
expected: true,
},
{
desc: "expert - dont fail if space is the first character",
config: { difficulty: "expert" },
correct: false,
spaceOrNewline: true,
isCommitChar: true,
input: " ",
expected: false,
},
{
desc: "expert: - dont fail if just typing",
config: { difficulty: "expert" },
correct: false,
spaceOrNewline: false,
isCommitChar: false,
input: "h",
expected: false,
},
{
desc: "expert: - dont fail if just typing",
config: { difficulty: "expert" },
correct: true,
spaceOrNewline: false,
isCommitChar: false,
input: "h",
expected: false,
},
Expand All @@ -222,40 +222,40 @@ describe("checkIfFailedDueToDifficulty", () => {
desc: "master - fail if incorrect char",
config: { difficulty: "master" },
correct: false,
spaceOrNewline: false,
isCommitChar: false,
input: "h",
expected: true,
},
{
desc: "master - fail if incorrect first space",
config: { difficulty: "master" },
correct: true,
spaceOrNewline: true,
isCommitChar: true,
input: " ",
expected: false,
},
{
desc: "master - dont fail if correct char",
config: { difficulty: "master" },
correct: true,
spaceOrNewline: false,
isCommitChar: false,
input: "a",
expected: false,
},
{
desc: "master - dont fail if correct space",
config: { difficulty: "master" },
correct: true,
spaceOrNewline: true,
isCommitChar: true,
input: " ",
expected: false,
},
])("$desc", ({ config, correct, spaceOrNewline, input, expected }) => {
])("$desc", ({ config, correct, isCommitChar, input, expected }) => {
replaceConfig(config as any);
const result = checkIfFailedDueToDifficulty({
testInputWithData: input,
correct,
spaceOrNewline,
isCommitChar,
});
expect(result).toBe(expected);
});
Expand Down
43 changes: 17 additions & 26 deletions frontend/__tests__/input/helpers/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach, afterAll } from "vitest";
import {
isCharCorrect,
isWordCorrect,
shouldInsertSpaceCharacter,
shouldJumpToNextWord,
} from "../../../src/ts/input/helpers/validation";
import { __testing } from "../../../src/ts/config/testing";
import * as FunboxList from "../../../src/ts/test/funbox/list";
Expand All @@ -13,6 +13,7 @@ const { replaceConfig } = __testing;
// Mock dependencies
vi.mock("../../../src/ts/test/funbox/list", () => ({
findSingleActiveFunboxWithFunction: vi.fn(),
isFunboxActiveWithProperty: vi.fn(),
}));

vi.mock("../../../src/ts/utils/strings", async () => {
Expand Down Expand Up @@ -155,7 +156,7 @@ describe("isCharCorrect", () => {
});
});

describe("shouldInsertSpaceCharacter", () => {
describe("shouldJumpToNextWord", () => {
beforeEach(() => {
replaceConfig({
mode: "time",
Expand All @@ -169,20 +170,10 @@ describe("shouldInsertSpaceCharacter", () => {
replaceConfig({});
});

it("returns null if data is not a space", () => {
expect(
shouldInsertSpaceCharacter({
data: "a",
inputValue: "test",
targetWord: "test",
}),
).toBe(null);
});

it("returns false in zen mode", () => {
replaceConfig({ mode: "zen" });
expect(
shouldInsertSpaceCharacter({
shouldJumpToNextWord({
data: " ",
inputValue: "test",
targetWord: "test",
Expand All @@ -202,7 +193,7 @@ describe("shouldInsertSpaceCharacter", () => {
strictSpace: false,
difficulty: "normal",
},
expected: false,
expected: true,
},
{
desc: "submit incorrect word (stopOnError off)",
Expand All @@ -213,30 +204,30 @@ describe("shouldInsertSpaceCharacter", () => {
strictSpace: false,
difficulty: "normal",
},
expected: false,
expected: true,
},
// Stop on error
{
desc: "insert space if incorrect (stopOnError letter)",
desc: "not submit if incorrect (stopOnError letter)",
inputValue: "hel",
targetWord: "hello",
config: {
stopOnError: "letter",
strictSpace: false,
difficulty: "normal",
},
expected: true,
expected: false,
},
{
desc: "insert space if incorrect (stopOnError word)",
desc: "not submit if incorrect (stopOnError word)",
inputValue: "hel",
targetWord: "hello",
config: {
stopOnError: "word",
strictSpace: false,
difficulty: "normal",
},
expected: true,
expected: false,
},
{
desc: "submit if correct (stopOnError letter)",
Expand All @@ -247,30 +238,30 @@ describe("shouldInsertSpaceCharacter", () => {
strictSpace: false,
difficulty: "normal",
},
expected: false,
expected: true,
},
// Strict space / Difficulty
{
desc: "insert space if empty input (strictSpace on)",
desc: "not submit if empty input (strictSpace on)",
inputValue: "",
targetWord: "hello",
config: {
stopOnError: "off",
strictSpace: true,
difficulty: "normal",
},
expected: true,
expected: false,
},
{
desc: "insert space if empty input (difficulty not normal - expert or master)",
desc: "not submit if empty input (difficulty not normal - expert or master)",
inputValue: "",
targetWord: "hello",
config: {
stopOnError: "off",
strictSpace: false,
difficulty: "expert",
},
expected: true,
expected: false,
},
{
desc: "submit if not empty input (strictSpace on)",
Expand All @@ -281,12 +272,12 @@ describe("shouldInsertSpaceCharacter", () => {
strictSpace: true,
difficulty: "normal",
},
expected: false,
expected: true,
},
])("$desc", ({ inputValue, targetWord, config, expected }) => {
replaceConfig(config as any);
expect(
shouldInsertSpaceCharacter({
shouldJumpToNextWord({
data: " ",
inputValue,
targetWord,
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/ts/input/handlers/before-insert-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isFunboxActiveWithProperty } from "../../test/funbox/list";
import { isSpace } from "../../utils/strings";
import { getInputElementValue } from "../input-element";
import { isAwaitingNextWord } from "../state";
import { shouldInsertSpaceCharacter } from "../helpers/validation";
import { shouldJumpToNextWord } from "../helpers/validation";
import * as SlowTimer from "../../legacy-states/slow-timer";
import { wordsHaveNewline } from "../../states/test";

Expand All @@ -31,11 +31,6 @@ export function onBeforeInsertText(data: string): boolean {

const { inputValue } = getInputElementValue();
const dataIsSpace = isSpace(data);
const shouldInsertSpaceAsCharacter = shouldInsertSpaceCharacter({
data,
inputValue,
targetWord: TestWords.words.getCurrentText(),
});

//prevent space from being inserted if input is empty
//allow if strict space is enabled
Expand All @@ -58,11 +53,17 @@ export function onBeforeInsertText(data: string): boolean {
return true;
}

const shouldGoToNextWord = shouldJumpToNextWord({
data,
inputValue,
targetWord: TestWords.words.getCurrentText(),
});

// block input if the word is too long
const inputLimit =
Config.mode === "zen" ? 30 : TestWords.words.getCurrentText().length + 20;
const overLimit = getCurrentInput().length >= inputLimit;
if (overLimit && (shouldInsertSpaceAsCharacter === true || !dataIsSpace)) {
if (overLimit && !shouldGoToNextWord) {
console.error("Hitting word limit");
return true;
}
Expand All @@ -79,7 +80,7 @@ export function onBeforeInsertText(data: string): boolean {
!Config.blindMode &&
!Config.hideExtraLetters &&
inputIsLongerThanOrEqualToWord &&
(shouldInsertSpaceAsCharacter === true || !dataIsSpace) &&
!shouldGoToNextWord &&
Config.mode !== "zen"
) {
// make sure to only check this when really necessary
Expand Down
Loading
Loading