Skip to content

Commit f191ee2

Browse files
committed
chore: address review feedback on pitch helpers
1 parent 975da7e commit f191ee2

File tree

4 files changed

+37
-1849
lines changed

4 files changed

+37
-1849
lines changed

js/__tests__/logo.test.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ global.doStopVideoCam = jest.fn();
5757
global.CAMERAVALUE = "camera:";
5858
global.VIDEOVALUE = "video:";
5959
global.doUseCamera = jest.fn();
60-
global.delayExecution = jest.fn(ms => Promise.resolve());
60+
global.delayExecution = jest.fn((ms, callback) => callback());
6161
global.getStatsFromNotation = jest.fn();
6262
global.Tone = {
6363
UserMedia: jest.fn().mockImplementation(() => ({
@@ -230,12 +230,13 @@ describe("Logo Class", () => {
230230
},
231231
stage: {
232232
removeEventListener: jest.fn(),
233-
addEventListener: jest.fn(),
234-
update: jest.fn()
233+
addEventListener: jest.fn()
235234
},
236235
onStopTurtle: jest.fn(),
237236
onRunTurtle: jest.fn(),
238-
237+
meSpeak: {
238+
speak: jest.fn()
239+
},
239240
errorMsg: jest.fn(),
240241
saveLocally: jest.fn(),
241242
hideMsgs: jest.fn(),
@@ -370,6 +371,23 @@ describe("Logo Class", () => {
370371
});
371372
});
372373

374+
describe("processSpeak", () => {
375+
test("filters text to only valid characters", () => {
376+
// The code uses this._meSpeak
377+
logo._meSpeak = { speak: jest.fn() };
378+
logo.processSpeak("Hello, World! 123");
379+
380+
expect(logo._meSpeak.speak).toHaveBeenCalledWith("Hello, World ");
381+
});
382+
383+
test("handles empty string", () => {
384+
logo._meSpeak = { speak: jest.fn() };
385+
logo.processSpeak("");
386+
387+
expect(logo._meSpeak.speak).toHaveBeenCalledWith("");
388+
});
389+
});
390+
373391
describe("setTurtleListener", () => {
374392
test("adds event listener to stage", () => {
375393
const listener = jest.fn();
@@ -709,8 +727,7 @@ describe("Logo comprehensive method coverage", () => {
709727
stage: {
710728
addEventListener: jest.fn(),
711729
removeEventListener: jest.fn(),
712-
dispatchEvent: jest.fn(),
713-
update: jest.fn()
730+
dispatchEvent: jest.fn()
714731
},
715732
errorMsg: jest.fn(),
716733
textMsg: jest.fn(),
@@ -918,7 +935,6 @@ describe("Logo comprehensive method coverage", () => {
918935
const originalTone = global.Tone;
919936
const open = jest.fn();
920937
global.Tone = { UserMedia: jest.fn(() => ({ open })) };
921-
if (logo.deps) logo.deps.Tone = global.Tone;
922938

923939
logo.initMediaDevices();
924940
expect(open).toHaveBeenCalled();
@@ -932,13 +948,11 @@ describe("Logo comprehensive method coverage", () => {
932948
})
933949
}))
934950
};
935-
if (logo.deps) logo.deps.Tone = global.Tone;
936951
logo.initMediaDevices();
937952
expect(mockActivity.errorMsg).toHaveBeenCalledWith("The microphone is not available.");
938953
expect(logo.mic).toBeNull();
939954

940955
global.Tone = originalTone;
941-
if (logo.deps) logo.deps.Tone = global.Tone;
942956
});
943957

944958
test("processShow handles image/url/loadFile/default branches", () => {
@@ -962,7 +976,6 @@ describe("Logo comprehensive method coverage", () => {
962976
return 2;
963977
});
964978
global.delayExecution = jest.fn(() => Promise.resolve());
965-
if (logo.deps && logo.deps.utils) logo.deps.utils.delayExecution = global.delayExecution;
966979

967980
turtle0.singer.embeddedGraphics = {};
968981
await logo.dispatchTurtleSignals(0, 0.5, 3, 0);
@@ -1068,7 +1081,6 @@ describe("Logo comprehensive method coverage", () => {
10681081
test("doStopTurtles covers companion/camera/recorder/showBlocks branches", () => {
10691082
const clearIntervalSpy = jest.spyOn(global, "clearInterval").mockImplementation(() => {});
10701083
global.instruments = { 0: { flute: {} }, 1: { piano: {} } };
1071-
if (logo.deps && logo.deps.instruments) logo.deps.instruments = global.instruments;
10721084
turtle0.singer.killAllVoices = jest.fn();
10731085
turtle0.companionTurtle = 1;
10741086
turtle1.interval = 888;
@@ -1149,7 +1161,6 @@ describe("Logo comprehensive method coverage", () => {
11491161
logo.processShow = jest.fn();
11501162
logo.processSpeak = jest.fn();
11511163
global.delayExecution = jest.fn(() => Promise.resolve());
1152-
if (logo.deps && logo.deps.utils) logo.deps.utils.delayExecution = global.delayExecution;
11531164

11541165
turtle0.singer.suppressOutput = false;
11551166
turtle0.embeddedGraphicsFinished = false;
@@ -1225,8 +1236,7 @@ describe("Logo comprehensive method coverage", () => {
12251236
storage: { saveLocally: jest.fn() },
12261237
config: { showBlocksAfterRun: false },
12271238
callbacks: { onStopTurtle: jest.fn(), onRunTurtle: jest.fn() },
1228-
meSpeak: { speak: jest.fn() },
1229-
classes: { Notation: global.Notation, Synth: global.Synth }
1239+
meSpeak: { speak: jest.fn() }
12301240
};
12311241

12321242
const depLogo = new Logo(deps);

js/__tests__/logoconstants.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ describe("logoconstants", () => {
9898
"NOTATIONTUPLETVALUE",
9999
"NOTATIONROUNDDOWN",
100100
"NOTATIONINSIDECHORD",
101-
"NOTATIONSTACCATO",
102-
"MIN_HIGHLIGHT_DURATION_MS"
101+
"NOTATIONSTACCATO"
103102
];
104103
expect(Object.keys(constants).sort()).toEqual(expectedKeys.sort());
105104
});

0 commit comments

Comments
 (0)