Skip to content

Commit aa2d89a

Browse files
committed
expanded tests for turtleactions
1 parent 33e9312 commit aa2d89a

17 files changed

+4020
-511
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
*~
3+
coverage/

jest.config.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
module.exports = {
2-
testMatch: ["**/__tests__/**/*.test.js", "**/?(*.)+(spec|test).[jt]s?(x)"],
3-
clearMocks: true,
4-
moduleFileExtensions: ["js", "json", "node"],
5-
testEnvironment: "jsdom",
2+
testMatch: ["**/__tests__/**/*.test.js", "**/?(*.)+(spec|test).[jt]s?(x)"],
3+
clearMocks: true,
4+
moduleFileExtensions: ["js", "json", "node"],
5+
testEnvironment: "jsdom",
6+
collectCoverage: true,
7+
coverageReporters: ["json", "lcov", "text", "clover"],
8+
coverageDirectory: "coverage",
9+
collectCoverageFrom: [
10+
"js/**/*.js",
11+
"!js/lib/**",
12+
"!js/external/**",
13+
"!**/node_modules/**"
14+
]
615
};

js/turtleactions/DictActions.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ function setupDictActions(activity) {
174174
this_dict["y"] = activity.turtles.screenY2turtleY(targetTur.container.y);
175175
this_dict["x"] = activity.turtles.screenX2turtleX(targetTur.container.x);
176176

177-
if (target in activity.logo.turtleDicts[turtle]) {
178-
for (const key in activity.logo.turtleDicts[turtle][target]) {
179-
this_dict[key] = activity.logo.turtleDicts[turtle][target][key];
177+
// Safely handle when no custom dicts have been set for this turtle
178+
const tdicts = activity.logo.turtleDicts[turtle] || {};
179+
if (target in tdicts) {
180+
for (const key in tdicts[target]) {
181+
this_dict[key] = tdicts[target][key];
180182
}
181183
}
182184
return JSON.stringify(this_dict);

js/turtleactions/IntervalsActions.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ function setupIntervalsActions(activity) {
192192
* @returns {String}
193193
*/
194194
static getCurrentMode(turtle) {
195-
return activity.turtles.ithTurtle(turtle).singer.keySignature.split(" ")[1];
195+
const keySignature = activity.turtles.ithTurtle(turtle).singer.keySignature;
196+
// guard against null/undefined/non‐string
197+
if (!keySignature || typeof keySignature !== "string") {
198+
return "";
199+
}
200+
const parts = keySignature.split(" ");
201+
return parts.slice(1).join(" ") || "";
196202
}
197203

198204
/**
@@ -457,3 +463,5 @@ function setupIntervalsActions(activity) {
457463
}
458464
};
459465
}
466+
467+
module.exports = setupIntervalsActions;

js/turtleactions/PitchActions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ function setupPitchActions(activity) {
322322
switch (accidental) {
323323
case _("sharp"):
324324
value = 1;
325-
return;
325+
break;
326326
case _("flat"):
327327
value = -1;
328-
return;
328+
break;
329329
default:
330330
value = 0;
331-
return;
331+
break;
332332
}
333333
} else {
334334
value = ACCIDENTALVALUES[i];

js/turtleactions/RhythmActions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,5 @@ function setupRhythmActions(activity) {
457457
}
458458
};
459459
}
460+
461+
module.exports = { setupRhythmActions };

0 commit comments

Comments
 (0)