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
40 changes: 40 additions & 0 deletions frontend/__tests__/test/events/stats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,46 @@ describe("stats.ts", () => {
// word 1: "w" vs "world" → 1 correct, 4 missed (words mode counts partial last word missed)
expect(chars.missed).toBe(6);
});

it("credits a word committed with an IME full-width space", () => {
// Japanese IME commits words with the ideographic space U+3000, while the
// target word separator is a regular space — normalize so it still counts
TestWords.list.push("しり", "かこ");
(TestState as { activeWordIndex: number }).activeWordIndex = 1;

logTestEvent("timer", 1000, timer("start", 0));
logTestEvent(
"input",
1100,
input({ charIndex: 0, wordIndex: 0, data: "し" }),
);
logTestEvent(
"input",
1150,
input({ charIndex: 1, wordIndex: 0, data: "り" }),
);
logTestEvent(
"input",
1200,
input({
charIndex: 2,
wordIndex: 0,
data: " ",
commitsWord: true,
}),
);
logTestEvent(
"input",
1300,
input({ charIndex: 0, wordIndex: 1, data: "か" }),
);

const chars = getChars(buildEventLog());
// word 0 "しり " is fully correct (2 chars + separator)
expect(chars.correctWord).toBe(3);
expect(chars.incorrect).toBe(0);
expect(chars.extra).toBe(0);
});
});

describe("getWpmHistory", () => {
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/ts/test/events/stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CharCounts, countChars } from "../../utils/strings";
import { CharCounts, countChars, isSpace } from "../../utils/strings";
import { getEventsForWord, getEventsPerWord, getInputFromDom } from "./helpers";
import { calculateWpm } from "../../utils/numbers";
import { roundTo2 } from "@monkeytype/util/numbers";
Expand Down Expand Up @@ -453,6 +453,12 @@ function countCharsForWordIndex(
countPartial: boolean,
): CharCounts {
let simulatedInput = getInputFromDom(wordEvents);
// IME commit chars (e.g. the full-width ideographic space U+3000) differ from
// the regular space the target word uses as a separator. Normalize them so
// the comparison matches the live input path, which treats them via isSpace.
simulatedInput = [...simulatedInput]
.map((c) => (isSpace(c) ? " " : c))
.join("");
if (eventLog.context.koreanStatus) {
simulatedInput = Hangul.disassemble(simulatedInput).join("");
}
Expand Down
Loading