Skip to content

Commit 2a491f8

Browse files
parthdagia05Parth
andauthored
test: add flow and arg coverage for IntervalsBlocks (#5489)
Co-authored-by: Parth <dagia@Parths-MacBook-Pro.local>
1 parent 5e13ffa commit 2a491f8

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

js/blocks/__tests__/IntervalsBlocks.test.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,70 @@ describe("setupIntervalsBlocks", () => {
192192

193193
expect(createdBlocks.key.arg(logo, turtleIndex, blk)).toBe("C");
194194
});
195+
196+
// === NEW TESTS ===
197+
198+
it("SetTemperamentBlock calls setTemperament", () => {
199+
createdBlocks.settemperament.flow(["equal", "C", 4], logo, turtleIndex, "blk");
200+
expect(Singer.IntervalsActions.setTemperament).toHaveBeenCalledWith("equal", "C", 4);
201+
});
202+
203+
it("SemitoneIntervalBlock sets interval and returns child block", () => {
204+
const result = createdBlocks.semitoneinterval.flow([5, "childBlk"], logo, turtleIndex, "blk");
205+
expect(Singer.IntervalsActions.setSemitoneInterval).toHaveBeenCalledWith(5, turtleIndex, "blk");
206+
expect(result).toEqual(["childBlk", 1]);
207+
});
208+
209+
it("SemitoneIntervalBlock returns early when args[1] undefined", () => {
210+
const result = createdBlocks.semitoneinterval.flow([5, undefined], logo, turtleIndex, "blk");
211+
expect(result).toBeUndefined();
212+
});
213+
214+
it("DoublyBlock returns 0 and shows error on null connection", () => {
215+
activity.blocks.blockList.blk1 = { connections: [null, null] };
216+
const result = createdBlocks.doubly.arg(logo, turtleIndex, "blk1", null);
217+
expect(result).toBe(0);
218+
expect(activity.errorMsg).toHaveBeenCalledWith("No input", "blk1");
219+
});
220+
221+
it("DoublyBlock adds 1 for augmented intervalname", () => {
222+
activity.blocks.blockList.blk1 = { connections: [null, "conn1"] };
223+
activity.blocks.blockList.conn1 = { name: "intervalname", value: "augmented" };
224+
logo.parseArg = jest.fn(() => 5);
225+
const result = createdBlocks.doubly.arg(logo, turtleIndex, "blk1", null);
226+
expect(result).toBe(6); // 5 + 1
227+
});
228+
229+
it("DoublyBlock subtracts 1 for diminished intervalname", () => {
230+
activity.blocks.blockList.blk1 = { connections: [null, "conn1"] };
231+
activity.blocks.blockList.conn1 = { name: "intervalname", value: "diminished" };
232+
logo.parseArg = jest.fn(() => 5);
233+
const result = createdBlocks.doubly.arg(logo, turtleIndex, "blk1", null);
234+
expect(result).toBe(4); // 5 - 1
235+
});
236+
237+
it("DoublyBlock doubles number values", () => {
238+
activity.blocks.blockList.blk1 = { connections: [null, "conn1"] };
239+
activity.blocks.blockList.conn1 = { name: "number", connections: [null, null] };
240+
logo.parseArg = jest.fn(() => 3);
241+
const result = createdBlocks.doubly.arg(logo, turtleIndex, "blk1", null);
242+
expect(result).toBe(6); // 3 * 2
243+
});
244+
245+
it("IntervalNumberBlock pushes to statusFields when inStatusMatrix", () => {
246+
logo.inStatusMatrix = true;
247+
activity.blocks.blockList.blk1 = { connections: ["print1"] };
248+
activity.blocks.blockList.print1 = { name: "print" };
249+
createdBlocks.intervalnumber.arg(logo, turtleIndex, "blk1");
250+
expect(logo.statusFields).toContainEqual(["blk1", "intervalnumber"]);
251+
});
252+
253+
it("CurrentIntervalBlock pushes to statusFields when inStatusMatrix", () => {
254+
logo.inStatusMatrix = true;
255+
activity.blocks.blockList.blk1 = { connections: ["print1"] };
256+
activity.blocks.blockList.print1 = { name: "print" };
257+
createdBlocks.currentinterval.arg(logo, turtleIndex, "blk1");
258+
expect(logo.statusFields).toContainEqual(["blk1", "currentinterval"]);
259+
});
260+
195261
});

0 commit comments

Comments
 (0)