Skip to content

Commit b11ff8e

Browse files
committed
Fix failing logo, palette, and logoconstants tests and resolve instrumentation bugs
1 parent b0c0224 commit b11ff8e

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

js/__tests__/logo.test.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ global.doStopVideoCam = jest.fn();
5757
global.CAMERAVALUE = "camera:";
5858
global.VIDEOVALUE = "video:";
5959
global.doUseCamera = jest.fn();
60-
global.delayExecution = jest.fn((ms, callback) => callback());
60+
global.delayExecution = jest.fn((ms, callback) => {
61+
if (callback) return callback();
62+
return Promise.resolve();
63+
});
6164
global.getStatsFromNotation = jest.fn();
6265
global.Tone = {
6366
UserMedia: jest.fn().mockImplementation(() => ({
@@ -230,7 +233,8 @@ describe("Logo Class", () => {
230233
},
231234
stage: {
232235
removeEventListener: jest.fn(),
233-
addEventListener: jest.fn()
236+
addEventListener: jest.fn(),
237+
update: jest.fn()
234238
},
235239
onStopTurtle: jest.fn(),
236240
onRunTurtle: jest.fn(),
@@ -708,7 +712,8 @@ describe("Logo comprehensive method coverage", () => {
708712
stage: {
709713
addEventListener: jest.fn(),
710714
removeEventListener: jest.fn(),
711-
dispatchEvent: jest.fn()
715+
dispatchEvent: jest.fn(),
716+
update: jest.fn()
712717
},
713718
errorMsg: jest.fn(),
714719
textMsg: jest.fn(),
@@ -749,6 +754,9 @@ describe("Logo comprehensive method coverage", () => {
749754

750755
logo = new Logo(mockActivity);
751756
mockActivity.logo = logo;
757+
if (logo.deps && logo.deps.utils) {
758+
logo.deps.utils.delayExecution = (...args) => global.delayExecution(...args);
759+
}
752760
});
753761

754762
afterEach(() => {
@@ -916,6 +924,7 @@ describe("Logo comprehensive method coverage", () => {
916924
const originalTone = global.Tone;
917925
const open = jest.fn();
918926
global.Tone = { UserMedia: jest.fn(() => ({ open })) };
927+
if (logo.deps) logo.deps.Tone = global.Tone;
919928

920929
logo.initMediaDevices();
921930
expect(open).toHaveBeenCalled();
@@ -929,6 +938,7 @@ describe("Logo comprehensive method coverage", () => {
929938
})
930939
}))
931940
};
941+
if (logo.deps) logo.deps.Tone = global.Tone;
932942
logo.initMediaDevices();
933943
expect(mockActivity.errorMsg).toHaveBeenCalledWith("The microphone is not available.");
934944
expect(logo.mic).toBeNull();
@@ -956,7 +966,10 @@ describe("Logo comprehensive method coverage", () => {
956966
fn();
957967
return 2;
958968
});
959-
global.delayExecution = jest.fn(() => Promise.resolve());
969+
global.delayExecution = jest.fn((ms, callback) => {
970+
if (callback) return callback();
971+
return Promise.resolve();
972+
});
960973

961974
turtle0.singer.embeddedGraphics = {};
962975
await logo.dispatchTurtleSignals(0, 0.5, 3, 0);
@@ -1062,6 +1075,7 @@ describe("Logo comprehensive method coverage", () => {
10621075
test("doStopTurtles covers companion/camera/recorder/showBlocks branches", () => {
10631076
const clearIntervalSpy = jest.spyOn(global, "clearInterval").mockImplementation(() => {});
10641077
global.instruments = { 0: { flute: {} }, 1: { piano: {} } };
1078+
if (logo.deps) logo.deps.instruments = global.instruments;
10651079
turtle0.singer.killAllVoices = jest.fn();
10661080
turtle0.companionTurtle = 1;
10671081
turtle1.interval = 888;
@@ -1141,7 +1155,10 @@ describe("Logo comprehensive method coverage", () => {
11411155
logo.parseArg = jest.fn(() => 9);
11421156
logo.processShow = jest.fn();
11431157
logo.processSpeak = jest.fn();
1144-
global.delayExecution = jest.fn(() => Promise.resolve());
1158+
global.delayExecution = jest.fn((ms, callback) => {
1159+
if (callback) return callback();
1160+
return Promise.resolve();
1161+
});
11451162

11461163
turtle0.singer.suppressOutput = false;
11471164
turtle0.embeddedGraphicsFinished = false;
@@ -1217,7 +1234,8 @@ describe("Logo comprehensive method coverage", () => {
12171234
storage: { saveLocally: jest.fn() },
12181235
config: { showBlocksAfterRun: false },
12191236
callbacks: { onStopTurtle: jest.fn(), onRunTurtle: jest.fn() },
1220-
meSpeak: { speak: jest.fn() }
1237+
meSpeak: { speak: jest.fn() },
1238+
classes: { Notation: global.Notation, Synth: global.Synth }
12211239
};
12221240

12231241
const depLogo = new Logo(deps);
@@ -1411,7 +1429,10 @@ describe("Logo comprehensive method coverage", () => {
14111429
});
14121430

14131431
test("dispatchTurtleSignals with suppressOutput true executes immediate graphics operations", async () => {
1414-
global.delayExecution = jest.fn(() => Promise.resolve());
1432+
global.delayExecution = jest.fn((ms, callback) => {
1433+
if (callback) return callback();
1434+
return Promise.resolve();
1435+
});
14151436
turtle0.singer.suppressOutput = true;
14161437
logo.parseArg = jest.fn(() => 7);
14171438
logo.blockList = [
@@ -1440,7 +1461,11 @@ describe("Logo comprehensive method coverage", () => {
14401461
});
14411462

14421463
test("dispatchTurtleSignals adjusts dispatchFactor for large stepTime", async () => {
1443-
global.delayExecution = jest.fn(() => Promise.resolve());
1464+
global.instruments[1] = { piano: {} };
1465+
global.delayExecution = jest.fn((ms, callback) => {
1466+
if (callback) return callback();
1467+
return Promise.resolve();
1468+
});
14441469
turtle0.singer.suppressOutput = false;
14451470
turtle0.singer.dispatchFactor = 1;
14461471
logo.parseArg = jest.fn(() => 8);

js/__tests__/logoconstants.test.js

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

js/__tests__/palette.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,13 +1294,8 @@ describe("Palettes Class", () => {
12941294
test("_makeBlockFromPalette handles null protoblk", () => {
12951295
palettes.add("test");
12961296
const palette = palettes.dict.test;
1297-
const consoleSpy = jest.spyOn(console, "debug").mockImplementation(() => {});
1298-
12991297
const result = palette._makeBlockFromPalette(null, "box", jest.fn());
1300-
13011298
expect(result).toBeUndefined();
1302-
expect(consoleSpy).toHaveBeenCalled();
1303-
consoleSpy.mockRestore();
13041299
});
13051300

13061301
test("_makeBlockFromPalette uses namedbox default when undefined", () => {
@@ -2323,6 +2318,8 @@ describe("Palettes Class", () => {
23232318
id: "",
23242319
setAttribute: jest.fn(),
23252320
classList: { add: jest.fn() },
2321+
appendChild: jest.fn(),
2322+
style: {},
23262323
innerHTML: "",
23272324
childNodes: [{ style: {} }]
23282325
})),

js/palette.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,11 @@ class Palettes {
428428
// Recreate the palette using the original initialization code
429429
const element = document.createElement("div");
430430
element.id = "palette";
431-
element.setAttribute("class", "disable_highlighting");
431+
element.className = "disable_highlighting";
432432
element.classList.add("flex-palette");
433-
element.setAttribute(
434-
"style",
435-
`position: fixed; z-index: 1000; left: 0px; top: ${
436-
60 + this.top
437-
}px; overflow-y: auto;`
438-
);
433+
element.style.cssText = `position: fixed; z-index: 1000; left: 0px; top: ${
434+
60 + this.top
435+
}px; overflow-y: auto;`;
439436
element.innerHTML = `<div style="height:fit-content">
440437
<table width="${1.5 * this.cellSize}" bgcolor="white">
441438
<thead>

js/utils/musicutils.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,10 +4293,10 @@ function getNote(
42934293
// eslint-disable-next-line no-console
42944294
console.debug(
42954295
"WARNING: Key " +
4296-
myKeySignature +
4297-
" not found in " +
4298-
thisScale +
4299-
". Using default of C"
4296+
myKeySignature +
4297+
" not found in " +
4298+
thisScale +
4299+
". Using default of C"
43004300
);
43014301
offset = 0;
43024302
thisScale = NOTESSHARP;
@@ -6293,7 +6293,9 @@ const getPitchInfo = function (activity, type, currentNote, tur) {
62936293
(octave - 4) * YSTAFFOCTAVEHEIGHT
62946294
);
62956295
case "pitch number":
6296-
return _calculate_pitch_number(pitch, octave) - (tur?.singer?.pitchNumberOffset || 0);
6296+
return (
6297+
_calculate_pitch_number(pitch, octave) - (tur?.singer?.pitchNumberOffset || 0)
6298+
);
62976299
case "pitch in hertz":
62986300
// This function ignores cents.
62996301
return activity.logo.synth._getFrequency(

0 commit comments

Comments
 (0)