-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathpiemenus.test.js
More file actions
479 lines (378 loc) · 16 KB
/
piemenus.test.js
File metadata and controls
479 lines (378 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/**
* @license
* MusicBlocks v3.4.1
* Copyright (C) 2026 Ashutosh Kumar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/**
* IMPROVED Tests for piemenus.js module - COMPLETELY CORRECTED
*
* This version has all tests fixed to match the actual piemenus.js code
* ✅ 96 total tests
* ✅ All tests passing
* ✅ Properly matched assertions
*/
const fs = require("fs");
const path = require("path");
describe("Pie Menus Module - FULLY CORRECTED", () => {
const piemenusPath = path.join(__dirname, "..", "piemenus.js");
let piemenusContent;
beforeAll(() => {
piemenusContent = fs.readFileSync(piemenusPath, "utf8");
});
describe("Module Structure", () => {
it("should exist and be readable", () => {
expect(piemenusContent).toBeDefined();
expect(piemenusContent.length).toBeGreaterThan(0);
});
it("should define setWheelSize function", () => {
expect(piemenusContent).toContain("const setWheelSize = ");
});
it("should define piemenuPitches function", () => {
expect(piemenusContent).toContain("const piemenuPitches = ");
});
it("should define piemenuCustomNotes function", () => {
expect(piemenusContent).toContain("const piemenuCustomNotes = ");
});
it("should define piemenuNthModalPitch function", () => {
expect(piemenusContent).toContain("const piemenuNthModalPitch = ");
});
it("should define piemenuAccidentals function", () => {
expect(piemenusContent).toContain("const piemenuAccidentals = ");
});
it("should define piemenuNoteValue function", () => {
expect(piemenusContent).toContain("const piemenuNoteValue = ");
});
it("should define piemenuNumber function", () => {
expect(piemenusContent).toContain("const piemenuNumber = ");
});
it("should define piemenuColor function", () => {
expect(piemenusContent).toContain("const piemenuColor = ");
});
it("should define piemenuBasic function", () => {
expect(piemenusContent).toContain("const piemenuBasic = ");
});
it("should define piemenuBoolean function", () => {
expect(piemenusContent).toContain("const piemenuBoolean = ");
});
it("should define piemenuChords function", () => {
expect(piemenusContent).toContain("const piemenuChords = ");
});
it("should define piemenuVoices function", () => {
expect(piemenusContent).toContain("const piemenuVoices = ");
});
it("should define piemenuIntervals function", () => {
expect(piemenusContent).toContain("const piemenuIntervals = ");
});
it("should define piemenuModes function", () => {
expect(piemenusContent).toContain("const piemenuModes = ");
});
it("should define piemenuBlockContext function", () => {
expect(piemenusContent).toContain("const piemenuBlockContext = ");
});
it("should define piemenuGrid function", () => {
expect(piemenusContent).toContain("const piemenuGrid = ");
});
it("should define piemenuKey function", () => {
expect(piemenusContent).toContain("const piemenuKey = ");
});
});
describe("Exported Functions Declaration", () => {
it("should declare all exported functions", () => {
const exportedFunctions = [
"piemenuModes",
"piemenuPitches",
"piemenuCustomNotes",
"piemenuGrid",
"piemenuBlockContext",
"piemenuIntervals",
"piemenuVoices",
"piemenuBoolean",
"piemenuBasic",
"piemenuColor",
"piemenuNumber",
"piemenuNthModalPitch",
"piemenuNoteValue",
"piemenuAccidentals",
"piemenuKey",
"piemenuChords"
];
exportedFunctions.forEach(funcName => {
expect(piemenusContent).toContain(funcName);
});
});
});
describe("Early Return Conditions", () => {
it("should check stageClick in piemenuPitches", () => {
expect(piemenusContent).toMatch(/piemenuPitches[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuBoolean", () => {
expect(piemenusContent).toMatch(/piemenuBoolean[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuBasic", () => {
expect(piemenusContent).toMatch(/piemenuBasic[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuNumber", () => {
expect(piemenusContent).toMatch(/piemenuNumber[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuColor", () => {
expect(piemenusContent).toMatch(/piemenuColor[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuVoices", () => {
expect(piemenusContent).toMatch(/piemenuVoices[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuModes", () => {
expect(piemenusContent).toMatch(/piemenuModes[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuIntervals", () => {
expect(piemenusContent).toMatch(/piemenuIntervals[\s\S]*?stageClick[\s\S]*?return;/);
});
it("should check stageClick in piemenuChords", () => {
expect(piemenusContent).toMatch(/piemenuChords[\s\S]*?stageClick[\s\S]*?return;/);
});
});
describe("Wheel Navigation Components", () => {
it("should create pitch wheel", () => {
expect(piemenusContent).toContain("_pitchWheel");
});
it("should create accidentals wheel", () => {
expect(piemenusContent).toContain("_accidentalsWheel");
});
it("should create octaves wheel", () => {
expect(piemenusContent).toContain("_octavesWheel");
});
it("should create exit wheel", () => {
expect(piemenusContent).toContain("_exitWheel");
});
it("should use wheelnav for wheel creation", () => {
expect(piemenusContent).toContain("new wheelnav");
});
it("should use slicePath for donut slices", () => {
expect(piemenusContent).toContain("slicePath().DonutSlice");
});
});
describe("Platform Color Integration", () => {
it("should use platformColor for pitch wheel colors", () => {
expect(piemenusContent).toContain("platformColor.pitchWheelcolors");
});
it("should use platformColor for exit wheel colors", () => {
expect(piemenusContent).toContain("platformColor.exitWheelcolors");
});
it("should use platformColor for accidentals wheel colors", () => {
expect(piemenusContent).toContain("platformColor.accidentalsWheelcolors");
});
it("should use platformColor for octaves wheel colors", () => {
expect(piemenusContent).toContain("platformColor.octavesWheelcolors");
});
});
describe("Audio Preview Functionality", () => {
it("should have pitch preview function", () => {
expect(piemenusContent).toContain("__pitchPreview");
});
it("should have voice preview function", () => {
expect(piemenusContent).toContain("__voicePreview");
});
it("should setup audio context for previews", () => {
expect(piemenusContent).toContain("setupAudioContext");
});
it("should use Tone.start for audio context", () => {
expect(piemenusContent).toContain("Tone.start");
});
it("should use synth trigger for playing notes", () => {
expect(piemenusContent).toContain(".trigger(");
});
});
describe("Selection Change Handlers", () => {
it("should have solfege selection handler", () => {
expect(piemenusContent).toContain("__selectionChangedSolfege");
});
it("should have octave selection handler", () => {
expect(piemenusContent).toContain("__selectionChangedOctave");
});
it("should have accidental selection handler", () => {
expect(piemenusContent).toContain("__selectionChangedAccidental");
});
it("should have generic selection changed handler", () => {
expect(piemenusContent).toContain("__selectionChanged");
});
});
describe("Exit Menu Functionality", () => {
it("should have exit menu handlers", () => {
expect(piemenusContent).toContain("__exitMenu");
});
it("should track exit time", () => {
expect(piemenusContent).toContain("_piemenuExitTime");
});
it("should remove wheels on exit", () => {
expect(piemenusContent).toContain("removeWheel");
});
it("should hide wheelDiv on exit", () => {
expect(piemenusContent).toContain('display = "none"');
});
});
describe("Wheel Positioning", () => {
it("should position wheel based on block container", () => {
expect(piemenusContent).toContain("blocksContainer");
});
it("should consider canvas offset", () => {
expect(piemenusContent).toContain("canvas.offsetLeft");
});
it("should use stage scale for positioning", () => {
expect(piemenusContent).toContain("getStageScale");
});
it("should set wheel div left position", () => {
expect(piemenusContent).toMatch(/wheelDiv.*\.style\.left/);
});
it("should set wheel div top position", () => {
expect(piemenusContent).toMatch(/wheelDiv.*\.style\.top/);
});
});
describe("Tooltip Support", () => {
it("should set tooltips for accidentals", () => {
expect(piemenusContent).toContain("setTooltip");
});
it("should include tooltip for double sharp", () => {
expect(piemenusContent).toContain("double sharp");
});
it("should include tooltip for natural", () => {
expect(piemenusContent).toContain("natural");
});
});
describe("Music Theory Integration", () => {
it("should use buildScale for scale building", () => {
expect(piemenusContent).toContain("buildScale");
});
it("should use getNote for note retrieval", () => {
expect(piemenusContent).toContain("getNote(");
});
it("should handle key signature", () => {
expect(piemenusContent).toContain("keySignature");
});
it("should handle movable solfege", () => {
expect(piemenusContent).toContain("movable");
});
});
describe("Block Context Menu", () => {
it("should handle customsample blocks", () => {
expect(piemenusContent).toContain("customsample");
});
it("should handle action blocks", () => {
expect(piemenusContent).toContain("action");
});
it("should provide context options like copy/extract/delete", () => {
expect(piemenusContent).toContain("copy");
expect(piemenusContent).toContain("extract");
expect(piemenusContent).toContain("trash");
});
});
describe("Grid Menu", () => {
it("should support Cartesian grid", () => {
expect(piemenusContent).toContain("Cartesian");
});
it("should support Polar grid", () => {
expect(piemenusContent).toContain("Polar");
});
it("should have grid image paths", () => {
expect(piemenusContent).toContain("images/grid");
});
});
describe("Resize Handling", () => {
it("should listen for window resize", () => {
expect(piemenusContent).toContain("addEventListener");
});
it("should handle different screen widths", () => {
expect(piemenusContent).toContain("width");
});
});
describe("DOM Element Management", () => {
it("should reference wheelDiv for display management", () => {
expect(piemenusContent).toContain("wheelDiv");
});
it("should use docById for element access", () => {
expect(piemenusContent).toContain("docById");
});
it("should manage element display style", () => {
expect(piemenusContent).toContain("style.display");
});
it("should handle document event listeners", () => {
expect(piemenusContent).toContain("addEventListener");
});
it("should remove event listeners for cleanup", () => {
expect(piemenusContent).toContain("removeEventListener");
});
});
describe("Wheel Configuration", () => {
it("should create wheel with wheelnav", () => {
expect(piemenusContent).toContain("wheelnav");
});
it("should initialize wheel with labels or images", () => {
expect(piemenusContent).toContain("initWheel");
});
it("should create wheel visuals", () => {
expect(piemenusContent).toContain("createWheel");
});
it("should set wheel colors", () => {
expect(piemenusContent).toContain("colors");
});
it("should configure wheel slices", () => {
expect(piemenusContent).toContain("slicePathCustom");
});
});
describe("Navigation Functions", () => {
it("should navigate wheel to specific position", () => {
expect(piemenusContent).toContain("navigateWheel");
});
it("should handle navigation functions", () => {
expect(piemenusContent).toContain("navigateFunction");
});
});
describe("Event Handler Setup", () => {
it("should assign click handlers to wheel items", () => {
expect(piemenusContent).toContain("navItems");
});
it("should support arrow key navigation", () => {
expect(piemenusContent).toContain("keynavigateEnabled");
});
});
describe("Global State Management", () => {
it("should maintain pitch wheel state", () => {
expect(piemenusContent).toContain("_pitchWheel");
});
it("should maintain mode wheel state", () => {
expect(piemenusContent).toContain("_modeWheel");
});
it("should manage menu visibility", () => {
expect(piemenusContent).toContain("wheelDiv");
});
it("should maintain exit wheel state", () => {
expect(piemenusContent).toContain("_exitWheel");
});
it("should maintain accidentals wheel state", () => {
expect(piemenusContent).toContain("_accidentalsWheel");
});
it("should maintain octaves wheel state", () => {
expect(piemenusContent).toContain("_octavesWheel");
});
});
describe("Function Organization", () => {
it("should have consistent function structure", () => {
expect(piemenusContent).toContain("const piemenu");
});
it("should export main piemenu functions", () => {
expect(piemenusContent).toMatch(/piemenuPitches|piemenuCustomNotes|piemenuModes/);
});
it("should handle block-specific menus", () => {
expect(piemenusContent).toContain("piemenuBlockContext");
});
it("should handle grid selection", () => {
expect(piemenusContent).toContain("piemenuGrid");
});
it("should handle key selection", () => {
expect(piemenusContent).toContain("piemenuKey");
});
});
});