Skip to content

Commit a70cb43

Browse files
committed
test(logo): reduce impl-detail coupling and remove setup duplication
- Remove dead-code spread in createMockTurtle - Add createTwoTurtleActivity helper; apply in synth-lifecycle, doStopTurtles, and runLogoCommands beforeEach blocks - Consolidate 8 single-assertion Logo Constants tests into 2 grouped tests - Fix runFromBlock beforeEach to use setupLogoEnv() instead of manual setup - Replace logo._notation private-field assertions with logo.notation getter - Remove turtle.delayTimeout state assertion after doStopTurtles (clearTimeout call is the observable behaviour) - Remove turtle0.listeners state assertion after runLogoCommands (stage removeEventListener is the observable behaviour) - Replace logo.blockTimings private-field assertions in profiling tests with performanceTracker.enterBlock call-count assertions - Drop redundant null assignments in clearTurtleRun and Transport scheduling tests (createMockTurtle already sets these to null) - Add jest.restoreAllMocks() to timerManager afterEach Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
1 parent 02d1299 commit a70cb43

1 file changed

Lines changed: 22 additions & 61 deletions

File tree

js/__tests__/logo.test.js

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ function createMockTurtle(overrides = {}) {
239239
doShowImage: jest.fn(),
240240
doShowURL: jest.fn(),
241241
doShowText: jest.fn(),
242-
...(overrides.queue !== undefined ? {} : {}),
243242
// Re-apply scalar overrides that would have been clobbered by the spread above
244243
...Object.fromEntries(
245244
Object.entries(overrides).filter(([k]) => k !== "singer" && k !== "painter")
@@ -302,6 +301,16 @@ function createMockActivity(turtle) {
302301
};
303302
}
304303

304+
function createTwoTurtleActivity(turtle0, turtle1) {
305+
const activity = createMockActivity(turtle0);
306+
activity.turtles.turtleList = [turtle0, turtle1];
307+
activity.turtles.ithTurtle = jest.fn(i => (String(i) === "1" ? turtle1 : turtle0));
308+
activity.turtles.getTurtle = jest.fn(i => (String(i) === "1" ? turtle1 : turtle0));
309+
activity.turtles.getTurtleCount = jest.fn(() => 2);
310+
activity.turtles.turtleCount = jest.fn(() => 2);
311+
return activity;
312+
}
313+
305314
// Centralised per-test environment reset – call at the top of every beforeEach.
306315
// Avoids repeating six identical lines in every describe block.
307316
function setupLogoEnv({ withFlute = false } = {}) {
@@ -371,35 +380,17 @@ describe("Queue Class", () => {
371380
// ─── Logo constants ───────────────────────────────────────────────────────────
372381

373382
describe("Logo Constants", () => {
374-
test("DEFAULTVOLUME is 50", () => {
383+
test("audio and timing constants have correct values", () => {
375384
expect(DEFAULTVOLUME).toBe(50);
376-
});
377-
378-
test("PREVIEWVOLUME is 80", () => {
379385
expect(PREVIEWVOLUME).toBe(80);
380-
});
381-
382-
test("DEFAULTDELAY is 500", () => {
383386
expect(DEFAULTDELAY).toBe(500);
384-
});
385-
386-
test("OSCVOLUMEADJUSTMENT is 1.5", () => {
387387
expect(OSCVOLUMEADJUSTMENT).toBe(1.5);
388388
});
389389

390-
test("TONEBPM is 240", () => {
390+
test("playback and execution constants have correct values", () => {
391391
expect(TONEBPM).toBe(240);
392-
});
393-
394-
test("TARGETBPM is 90", () => {
395392
expect(TARGETBPM).toBe(90);
396-
});
397-
398-
test("TURTLESTEP is -1", () => {
399393
expect(TURTLESTEP).toBe(-1);
400-
});
401-
402-
test("NOTEDIV is 8", () => {
403394
expect(NOTEDIV).toBe(8);
404395
});
405396

@@ -464,7 +455,7 @@ describe("Logo constructor", () => {
464455
});
465456

466457
test("initializes notation object", () => {
467-
expect(logo._notation).toBeDefined();
458+
expect(logo.notation).toBeDefined();
468459
});
469460

470461
test("initializes synth", () => {
@@ -554,7 +545,8 @@ describe("Logo getters and setters", () => {
554545
});
555546

556547
test("notation getter returns notation object", () => {
557-
expect(logo.notation).toBe(logo._notation);
548+
expect(logo.notation).toBeDefined();
549+
expect(logo.notation).not.toBeNull();
558550
});
559551

560552
test("setCameraID sets cameraID property", () => {
@@ -865,12 +857,7 @@ describe("Logo synth lifecycle", () => {
865857
setupLogoEnv({ withFlute: true });
866858
turtle0 = createMockTurtle();
867859
turtle1 = createMockTurtle();
868-
mockActivity = createMockActivity(turtle0);
869-
mockActivity.turtles.turtleList = [turtle0, turtle1];
870-
mockActivity.turtles.ithTurtle = jest.fn(i => (String(i) === "1" ? turtle1 : turtle0));
871-
mockActivity.turtles.getTurtle = jest.fn(i => (String(i) === "1" ? turtle1 : turtle0));
872-
mockActivity.turtles.getTurtleCount = jest.fn(() => 2);
873-
mockActivity.turtles.turtleCount = jest.fn(() => 2);
860+
mockActivity = createTwoTurtleActivity(turtle0, turtle1);
874861
logo = new Logo(mockActivity);
875862
});
876863

@@ -972,7 +959,6 @@ describe("Logo doStopTurtles", () => {
972959
logo.doStopTurtles();
973960

974961
expect(clearTimeoutSpy).toHaveBeenCalledWith(TIMER_ID);
975-
expect(turtle.delayTimeout).toBeNull();
976962
});
977963

978964
test("timerManager.clearAll is invoked during stop", () => {
@@ -996,16 +982,7 @@ describe("Logo doStopTurtles", () => {
996982
global.instrumentsEffects = { 0: {}, 1: {} };
997983
turtle0 = createMockTurtle();
998984
turtle1 = createMockTurtle();
999-
twoTurtleActivity = createMockActivity(turtle0);
1000-
twoTurtleActivity.turtles.turtleList = [turtle0, turtle1];
1001-
twoTurtleActivity.turtles.ithTurtle = jest.fn(i =>
1002-
String(i) === "1" ? turtle1 : turtle0
1003-
);
1004-
twoTurtleActivity.turtles.getTurtle = jest.fn(i =>
1005-
String(i) === "1" ? turtle1 : turtle0
1006-
);
1007-
twoTurtleActivity.turtles.getTurtleCount = jest.fn(() => 2);
1008-
twoTurtleActivity.turtles.turtleCount = jest.fn(() => 2);
985+
twoTurtleActivity = createTwoTurtleActivity(turtle0, turtle1);
1009986
twoTurtleActivity.showBlocksAfterRun = true;
1010987
logo = new Logo(twoTurtleActivity);
1011988
logo.deps.instruments = { 0: { flute: {} }, 1: { piano: {} } };
@@ -1105,12 +1082,7 @@ describe("Logo runLogoCommands", () => {
11051082
global.document.body.style.cursor = "pointer";
11061083
turtle0 = createMockTurtle();
11071084
turtle1 = createMockTurtle();
1108-
mockActivity = createMockActivity(turtle0);
1109-
mockActivity.turtles.turtleList = [turtle0, turtle1];
1110-
mockActivity.turtles.ithTurtle = jest.fn(i => (String(i) === "1" ? turtle1 : turtle0));
1111-
mockActivity.turtles.getTurtle = jest.fn(i => (String(i) === "1" ? turtle1 : turtle0));
1112-
mockActivity.turtles.getTurtleCount = jest.fn(() => 2);
1113-
mockActivity.turtles.turtleCount = jest.fn(() => 2);
1085+
mockActivity = createTwoTurtleActivity(turtle0, turtle1);
11141086
logo = new Logo(mockActivity);
11151087
mockActivity.logo = logo;
11161088
logo.prepSynths = jest.fn();
@@ -1195,7 +1167,6 @@ describe("Logo runLogoCommands", () => {
11951167
oldListener,
11961168
false
11971169
);
1198-
expect(turtle0.listeners).toEqual({});
11991170
});
12001171

12011172
test("drum block is included in startBlocks", () => {
@@ -1257,13 +1228,8 @@ describe("Logo runFromBlock", () => {
12571228
let savedTone;
12581229

12591230
beforeEach(() => {
1260-
jest.clearAllMocks();
1231+
setupLogoEnv({ withFlute: true });
12611232
savedTone = global.Tone;
1262-
global.instruments = { 0: { flute: {} } };
1263-
global.instrumentsFilters = { 0: { flute: ["lp"] } };
1264-
global.instrumentsEffects = { 0: { flute: { reverb: 0.5 } } };
1265-
global.window.widgetWindows = { isOpen: jest.fn(() => false) };
1266-
global.document.getElementById = jest.fn(() => ({ style: { color: "" } }));
12671233
turtle0 = createMockTurtle();
12681234
mockActivity = createMockActivity(turtle0);
12691235
logo = new Logo(mockActivity);
@@ -1336,8 +1302,6 @@ describe("Logo runFromBlock", () => {
13361302
logo.stopTurtle = false;
13371303
turtle0.waitTime = 200;
13381304
turtle0._transportTime = 10;
1339-
turtle0.delayParameters = null;
1340-
turtle0._transportEventId = null;
13411305

13421306
logo.runFromBlock(logo, 0, 3, 1, "x");
13431307

@@ -1483,7 +1447,7 @@ describe("Logo runFromBlockNow", () => {
14831447

14841448
logo.runFromBlockNow(logo, 0, 0, 0, null);
14851449

1486-
expect(logo.blockTimings).toBeUndefined();
1450+
expect(global.performanceTracker.enterBlock).not.toHaveBeenCalled();
14871451
});
14881452

14891453
test("profiling on increments call count", () => {
@@ -1517,7 +1481,7 @@ describe("Logo runFromBlockNow", () => {
15171481

15181482
logo.runFromBlockNow(logo, 0, 0, 0, null);
15191483

1520-
expect(logo.blockTimings.noop.calls).toBe(1);
1484+
expect(global.performanceTracker.enterBlock).toHaveBeenCalledTimes(1);
15211485
});
15221486
});
15231487

@@ -1695,7 +1659,6 @@ describe("Logo clearTurtleRun", () => {
16951659
set seconds(v) {}
16961660
}
16971661
};
1698-
turtle0.delayTimeout = null;
16991662
turtle0._transportEventId = "evt-3";
17001663
turtle0.delayParameters = { blk: 7, flow: 0, arg: null };
17011664
turtle0._transportTime = 50;
@@ -1708,9 +1671,6 @@ describe("Logo clearTurtleRun", () => {
17081671
});
17091672

17101673
test("is no-op when no pending delay or Transport event", () => {
1711-
turtle0.delayTimeout = null;
1712-
turtle0._transportEventId = null;
1713-
17141674
logo.clearTurtleRun(0);
17151675

17161676
expect(logo.runFromBlockNow).not.toHaveBeenCalled();
@@ -2115,6 +2075,7 @@ describe("Logo timerManager getter and shim", () => {
21152075

21162076
afterEach(() => {
21172077
jest.useRealTimers();
2078+
jest.restoreAllMocks();
21182079
});
21192080

21202081
test("timerManager exposes clearAll, getStats, and setGuardedTimeout", () => {

0 commit comments

Comments
 (0)