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
3 changes: 3 additions & 0 deletions frontend/src/ts/input/handlers/before-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ export function onBeforeDelete(event: InputEvent): void {
return;
}
if (TestState.testRestarting) {
event.preventDefault();
return;
}
if (isAwaitingNextWord()) {
event.preventDefault();
return;
}
if (TestState.resultCalculating) {
event.preventDefault();
return;
}

Expand Down
92 changes: 63 additions & 29 deletions frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ import { qs } from "../utils/dom";
import { setAccountButtonSpinner } from "../states/header";
import { Config } from "../config/store";
import { setQuoteLengthAll, toggleFunbox, setConfig } from "../config/setters";
import { resetTestEvents, cleanupData } from "./events/data";
import {
resetTestEvents,
cleanupData,
logEventsDataToTheConsoleTable,
} from "./events/data";
import {
getKeypressDurations,
getChars,
Expand Down Expand Up @@ -901,6 +905,8 @@ function buildCompletedEvent(
return completedEvent;
}

const ALWAYSREPORT = false;

function compareCompletedEvents(
ce: Omit<CompletedEvent, "hash" | "uid">,
): void {
Expand Down Expand Up @@ -1057,25 +1063,6 @@ function compareCompletedEvents(
);
}
}

{
const a = TestInput.keypressCountHistory;
const b = getKeypressesPerSecond();
if (a.length === b.length && a.every((val, i) => val === b[i])) {
console.debug(
`Completed event match on key keypressCountHistory:`,
a,
);
} else {
notMatching.push(`keypressCountHistory (values differ)`);
mismatchedKeys.push("keypressCountHistory");
console.error(
`Completed event mismatch on key keypressCountHistory:`,
a,
b,
);
}
}
} else if (key === "wpmConsistency" || key === "keyConsistency") {
const a = val1 as number;
const b = val2 as number;
Expand Down Expand Up @@ -1114,13 +1101,55 @@ function compareCompletedEvents(
}
}

{
const a = TestInput.keypressCountHistory;
const b = getKeypressesPerSecond();
if (a.length === b.length && a.every((val, i) => val === b[i])) {
console.debug(`Completed event match on key keypressCountHistory:`, a);
} else {
notMatching.push(`keypressCountHistory (values differ)`);
mismatchedKeys.push("keypressCountHistory");
console.error(
`Completed event mismatch on key keypressCountHistory:`,
a,
b,
);
}
}

{
const a = TestInput.keypressCountHistory.reduce((acc, val) => {
if (val === undefined) return acc;
return acc + val;
}, 0);
const b = getKeypressesPerSecond().reduce((acc, val) => {
if (val === undefined) return acc;
return acc + val;
}, 0);
if (a === b) {
console.debug(`Completed event match on totalKeypressCountHistory:`, a);
} else {
notMatching.push(`totalKeypressCountHistory (${a} vs ${b})`);
mismatchedKeys.push("totalKeypressCountHistory");
console.error(
`Completed event mismatch on totalKeypressCountHistory:`,
a,
b,
);
}
}

if (notMatching.length === 0) {
// showSuccessNotification("Completed events match", { important: true });
if (ALWAYSREPORT) {
showSuccessNotification("Completed events match", { important: true });
}
} else {
// showErrorNotification(
// `Completed event mismatch: ${notMatching.join(", ")}`,
// { important: true },
// );
if (ALWAYSREPORT) {
showErrorNotification(
`Completed event mismatch: ${notMatching.join(", ")}`,
{ important: true },
);
}
mismatchedKeys.sort();
const groupKey = mismatchedKeys.join(",");
Ape.results
Expand Down Expand Up @@ -1499,11 +1528,16 @@ export async function finish(difficultyFailed = false): Promise<void> {

// test is valid

if (ALWAYSREPORT) {
logEventsDataToTheConsoleTable();
}

if (
getAuthenticatedUser() !== null &&
!dontSave &&
!difficultyFailed &&
Config.resultSaving
(getAuthenticatedUser() !== null &&
!dontSave &&
!difficultyFailed &&
Config.resultSaving) ||
ALWAYSREPORT
) {
compareCompletedEvents(ce);
}
Expand Down
Loading