Skip to content

Commit 975da7e

Browse files
committed
test: fix failing logo, palette, and logoconstants tests due to recent master refactors
1 parent fea6ab5 commit 975da7e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

js/__tests__/logo.test.js

Lines changed: 13 additions & 4 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, callback) => callback());
60+
global.delayExecution = jest.fn(ms => Promise.resolve());
6161
global.getStatsFromNotation = jest.fn();
6262
global.Tone = {
6363
UserMedia: jest.fn().mockImplementation(() => ({
@@ -230,7 +230,8 @@ describe("Logo Class", () => {
230230
},
231231
stage: {
232232
removeEventListener: jest.fn(),
233-
addEventListener: jest.fn()
233+
addEventListener: jest.fn(),
234+
update: jest.fn()
234235
},
235236
onStopTurtle: jest.fn(),
236237
onRunTurtle: jest.fn(),
@@ -708,7 +709,8 @@ describe("Logo comprehensive method coverage", () => {
708709
stage: {
709710
addEventListener: jest.fn(),
710711
removeEventListener: jest.fn(),
711-
dispatchEvent: jest.fn()
712+
dispatchEvent: jest.fn(),
713+
update: jest.fn()
712714
},
713715
errorMsg: jest.fn(),
714716
textMsg: jest.fn(),
@@ -916,6 +918,7 @@ describe("Logo comprehensive method coverage", () => {
916918
const originalTone = global.Tone;
917919
const open = jest.fn();
918920
global.Tone = { UserMedia: jest.fn(() => ({ open })) };
921+
if (logo.deps) logo.deps.Tone = global.Tone;
919922

920923
logo.initMediaDevices();
921924
expect(open).toHaveBeenCalled();
@@ -929,11 +932,13 @@ describe("Logo comprehensive method coverage", () => {
929932
})
930933
}))
931934
};
935+
if (logo.deps) logo.deps.Tone = global.Tone;
932936
logo.initMediaDevices();
933937
expect(mockActivity.errorMsg).toHaveBeenCalledWith("The microphone is not available.");
934938
expect(logo.mic).toBeNull();
935939

936940
global.Tone = originalTone;
941+
if (logo.deps) logo.deps.Tone = global.Tone;
937942
});
938943

939944
test("processShow handles image/url/loadFile/default branches", () => {
@@ -957,6 +962,7 @@ describe("Logo comprehensive method coverage", () => {
957962
return 2;
958963
});
959964
global.delayExecution = jest.fn(() => Promise.resolve());
965+
if (logo.deps && logo.deps.utils) logo.deps.utils.delayExecution = global.delayExecution;
960966

961967
turtle0.singer.embeddedGraphics = {};
962968
await logo.dispatchTurtleSignals(0, 0.5, 3, 0);
@@ -1062,6 +1068,7 @@ describe("Logo comprehensive method coverage", () => {
10621068
test("doStopTurtles covers companion/camera/recorder/showBlocks branches", () => {
10631069
const clearIntervalSpy = jest.spyOn(global, "clearInterval").mockImplementation(() => {});
10641070
global.instruments = { 0: { flute: {} }, 1: { piano: {} } };
1071+
if (logo.deps && logo.deps.instruments) logo.deps.instruments = global.instruments;
10651072
turtle0.singer.killAllVoices = jest.fn();
10661073
turtle0.companionTurtle = 1;
10671074
turtle1.interval = 888;
@@ -1142,6 +1149,7 @@ describe("Logo comprehensive method coverage", () => {
11421149
logo.processShow = jest.fn();
11431150
logo.processSpeak = jest.fn();
11441151
global.delayExecution = jest.fn(() => Promise.resolve());
1152+
if (logo.deps && logo.deps.utils) logo.deps.utils.delayExecution = global.delayExecution;
11451153

11461154
turtle0.singer.suppressOutput = false;
11471155
turtle0.embeddedGraphicsFinished = false;
@@ -1217,7 +1225,8 @@ describe("Logo comprehensive method coverage", () => {
12171225
storage: { saveLocally: jest.fn() },
12181226
config: { showBlocksAfterRun: false },
12191227
callbacks: { onStopTurtle: jest.fn(), onRunTurtle: jest.fn() },
1220-
meSpeak: { speak: jest.fn() }
1228+
meSpeak: { speak: jest.fn() },
1229+
classes: { Notation: global.Notation, Synth: global.Synth }
12211230
};
12221231

12231232
const depLogo = new Logo(deps);

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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,13 +1294,9 @@ 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());
13001298

13011299
expect(result).toBeUndefined();
1302-
expect(consoleSpy).toHaveBeenCalled();
1303-
consoleSpy.mockRestore();
13041300
});
13051301

13061302
test("_makeBlockFromPalette uses namedbox default when undefined", () => {

0 commit comments

Comments
 (0)