Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
165 changes: 116 additions & 49 deletions frontend/__tests__/input/helpers/fail-or-finish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from "../../../src/ts/input/helpers/fail-or-finish";
import { __testing } from "../../../src/ts/config/testing";
import * as Misc from "../../../src/ts/utils/misc";
import * as TestLogic from "../../../src/ts/test/test-logic";
import * as Strings from "../../../src/ts/utils/strings";

const { replaceConfig } = __testing;
Expand All @@ -20,10 +19,6 @@ vi.mock("../../../src/ts/utils/misc", async (importOriginal) => {
};
});

vi.mock("../../../src/ts/test/test-logic", () => ({
areAllTestWordsGenerated: vi.fn(),
}));

vi.mock("../../../src/ts/utils/strings", () => ({
isSpace: vi.fn(),
}));
Expand All @@ -38,8 +33,6 @@ describe("checkIfFailedDueToMinBurst", () => {
});
// oxlint-disable-next-line typescript/no-unsafe-call
(Misc.whorf as any).mockReturnValue(0);
// oxlint-disable-next-line typescript/no-unsafe-call
(TestLogic.areAllTestWordsGenerated as any).mockReturnValue(true);
});

afterAll(() => {
Expand Down Expand Up @@ -139,126 +132,202 @@ describe("checkIfFailedDueToDifficulty", () => {
desc: "zen mode, master - never fails",
config: { mode: "zen", difficulty: "master" },
correct: false,
spaceOrNewline: true,
input: "hello",
data: " ",
testInput: "hello",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
{
desc: "zen mode - never fails",
config: { mode: "zen", difficulty: "normal" },
correct: false,
spaceOrNewline: true,
input: "hello",
data: " ",
testInput: "hello",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
//
{
desc: "normal typing incorrect- never fails",
config: { difficulty: "normal" },
correct: false,
spaceOrNewline: false,
input: "hello",
data: "h",
testInput: "hell",
targetWord: "hello",
commitCharacterType: false,
expected: false,
},
{
desc: "normal typing space incorrect - never fails",
config: { difficulty: "normal" },
correct: false,
spaceOrNewline: true,
input: "hello",
data: " ",
testInput: "hell",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
{
desc: "normal typing correct - never fails",
config: { difficulty: "normal" },
correct: true,
spaceOrNewline: false,
input: "hello",
data: "o",
testInput: "hell",
targetWord: "hello",
commitCharacterType: false,
expected: false,
},
{
desc: "normal typing space correct - never fails",
config: { difficulty: "normal" },
correct: true,
spaceOrNewline: true,
input: "hello",
data: " ",
testInput: "hello",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
//
{
desc: "expert - fail if incorrect space",
config: { difficulty: "expert" },
correct: false,
spaceOrNewline: true,
input: "he",
data: " ",
testInput: "he",
targetWord: "hello ",
commitCharacterType: "separator",
expected: true,
},
{
desc: "expert - dont fail if space is the first character",
config: { difficulty: "expert" },
correct: false,
spaceOrNewline: true,
input: " ",
data: " ",
testInput: "",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
{
desc: "expert: - dont fail if just typing",
config: { difficulty: "expert" },
correct: false,
spaceOrNewline: false,
input: "h",
data: "h",
testInput: "hell",
targetWord: "hello",
commitCharacterType: false,
expected: false,
},
{
desc: "expert: - dont fail if just typing",
config: { difficulty: "expert" },
correct: true,
spaceOrNewline: false,
input: "h",
data: "o",
testInput: "hell",
targetWord: "hello",
commitCharacterType: false,
expected: false,
},
{
// nospace commits on the final letter (empty input for a 1-letter word);
// an incorrect commit must still fail expert
desc: "expert - fail on incorrect nospace 1-letter word on empty input",
config: { difficulty: "expert" },
correct: false,
data: "b",
testInput: "",
targetWord: "a",
commitCharacterType: "nospace",
expected: true,
},
{
desc: "expert - dont fail on correct nospace 1-letter word on empty input",
config: { difficulty: "expert" },
correct: true,
data: "a",
testInput: "",
targetWord: "a",
commitCharacterType: "nospace",
expected: false,
},
{
desc: "expert - fail on incorrect nospace multi-letter word commit",
config: { difficulty: "expert" },
correct: false,
data: "o",
testInput: "helx",
targetWord: "hello",
commitCharacterType: "nospace",
expected: true,
},
//
{
desc: "master - fail if incorrect char",
config: { difficulty: "master" },
correct: false,
spaceOrNewline: false,
input: "h",
data: "h",
testInput: "hell",
targetWord: "hello",
commitCharacterType: false,
expected: true,
},
{
desc: "master - fail if incorrect first space",
config: { difficulty: "master" },
correct: true,
spaceOrNewline: true,
input: " ",
data: " ",
testInput: "",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
{
desc: "master - dont fail if correct char",
config: { difficulty: "master" },
correct: true,
spaceOrNewline: false,
input: "a",
data: "a",
testInput: "te",
targetWord: "tea",
commitCharacterType: false,
expected: false,
},
{
desc: "master - dont fail if correct space",
config: { difficulty: "master" },
correct: true,
spaceOrNewline: true,
input: " ",
data: " ",
testInput: "hello",
targetWord: "hello ",
commitCharacterType: "separator",
expected: false,
},
])("$desc", ({ config, correct, spaceOrNewline, input, expected }) => {
replaceConfig(config as any);
const result = checkIfFailedDueToDifficulty({
testInputWithData: input,
])(
"$desc",
({
config,
correct,
spaceOrNewline,
});
expect(result).toBe(expected);
});
data,
testInput,
targetWord,
commitCharacterType,
expected,
}) => {
replaceConfig(config as any);
const result = checkIfFailedDueToDifficulty({
data,
testInput,
targetWord,
correct,
commitCharacterType: commitCharacterType as
| "separator"
| "nospace"
| false,
});
expect(result).toBe(expected);
},
);
});

describe("checkIfFinished", () => {
Expand All @@ -270,8 +339,6 @@ describe("checkIfFinished", () => {
});
// oxlint-disable-next-line typescript/no-unsafe-call
(Strings.isSpace as any).mockReturnValue(false);
// oxlint-disable-next-line typescript/no-unsafe-call
(TestLogic.areAllTestWordsGenerated as any).mockReturnValue(true);
});

afterAll(() => {
Expand Down Expand Up @@ -322,7 +389,7 @@ describe("checkIfFinished", () => {
allWordsTyped: true,
testInputWithData: "wo ",
currentWord: "word",
shouldGoToNextWord: true,
goingToNextWord: true,
expected: true,
},
{
Expand All @@ -336,7 +403,7 @@ describe("checkIfFinished", () => {
desc: string;
allWordsTyped: boolean;
allWordsGenerated?: boolean;
shouldGoToNextWord: boolean;
goingToNextWord: boolean;
testInputWithData: string;
currentWord: string;
config?: Record<string, any>;
Expand All @@ -347,7 +414,7 @@ describe("checkIfFinished", () => {
({
allWordsTyped,
allWordsGenerated,
shouldGoToNextWord,
goingToNextWord,
testInputWithData,
currentWord,
config,
Expand All @@ -356,7 +423,7 @@ describe("checkIfFinished", () => {
if (config) replaceConfig(config as any);

const result = checkIfFinished({
shouldGoToNextWord,
goingToNextWord,
testInputWithData,
currentWord,
allWordsTyped,
Expand Down
Loading
Loading