Skip to content

Commit e4c1252

Browse files
parthdagia05Parth
andauthored
test: add unit tests for logoconstants default values and exports (#5690)
Co-authored-by: Parth <dagia@Parths-MacBook-Pro.local>
1 parent 2d5b272 commit e4c1252

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

js/__tests__/logoconstants.test.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @license
3+
* MusicBlocks v3.4.1
4+
* Copyright (C) 2026 Music Blocks Contributors
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
global._ = jest.fn(s => s);
20+
21+
const constants = require("../logoconstants");
22+
23+
describe("logoconstants", () => {
24+
test("module loads and exports an object", () => {
25+
expect(constants).toBeDefined();
26+
expect(typeof constants).toBe("object");
27+
});
28+
29+
test("numeric defaults have correct values", () => {
30+
expect(constants.DEFAULTVOLUME).toBe(50);
31+
expect(constants.PREVIEWVOLUME).toBe(80);
32+
expect(constants.DEFAULTDELAY).toBe(500);
33+
expect(constants.OSCVOLUMEADJUSTMENT).toBe(1.5);
34+
expect(constants.TONEBPM).toBe(240);
35+
expect(constants.TARGETBPM).toBe(90);
36+
expect(constants.TURTLESTEP).toBe(-1);
37+
expect(constants.NOTEDIV).toBe(8);
38+
});
39+
40+
test("error message strings are non-empty strings", () => {
41+
const msgKeys = [
42+
"NOMICERRORMSG",
43+
"NANERRORMSG",
44+
"NOSTRINGERRORMSG",
45+
"NOBOXERRORMSG",
46+
"NOACTIONERRORMSG",
47+
"NOINPUTERRORMSG",
48+
"NOSQRTERRORMSG",
49+
"ZERODIVIDEERRORMSG",
50+
"EMPTYHEAPERRORMSG",
51+
"POSNUMBER"
52+
];
53+
for (const key of msgKeys) {
54+
expect(typeof constants[key]).toBe("string");
55+
expect(constants[key].length).toBeGreaterThan(0);
56+
}
57+
});
58+
59+
test("INVALIDPITCH has the expected translation string", () => {
60+
expect(typeof constants.INVALIDPITCH).toBe("string");
61+
expect(constants.INVALIDPITCH).toBe("Not a valid pitch name");
62+
});
63+
64+
test("notation index constants are sequential integers starting at 0", () => {
65+
expect(constants.NOTATIONNOTE).toBe(0);
66+
expect(constants.NOTATIONDURATION).toBe(1);
67+
expect(constants.NOTATIONDOTCOUNT).toBe(2);
68+
expect(constants.NOTATIONTUPLETVALUE).toBe(3);
69+
expect(constants.NOTATIONROUNDDOWN).toBe(4);
70+
expect(constants.NOTATIONINSIDECHORD).toBe(5);
71+
expect(constants.NOTATIONSTACCATO).toBe(6);
72+
});
73+
74+
test("exports exactly the expected set of keys", () => {
75+
const expectedKeys = [
76+
"DEFAULTVOLUME",
77+
"PREVIEWVOLUME",
78+
"DEFAULTDELAY",
79+
"OSCVOLUMEADJUSTMENT",
80+
"TONEBPM",
81+
"TARGETBPM",
82+
"TURTLESTEP",
83+
"NOTEDIV",
84+
"NOMICERRORMSG",
85+
"NANERRORMSG",
86+
"NOSTRINGERRORMSG",
87+
"NOBOXERRORMSG",
88+
"NOACTIONERRORMSG",
89+
"NOINPUTERRORMSG",
90+
"NOSQRTERRORMSG",
91+
"ZERODIVIDEERRORMSG",
92+
"EMPTYHEAPERRORMSG",
93+
"POSNUMBER",
94+
"INVALIDPITCH",
95+
"NOTATIONNOTE",
96+
"NOTATIONDURATION",
97+
"NOTATIONDOTCOUNT",
98+
"NOTATIONTUPLETVALUE",
99+
"NOTATIONROUNDDOWN",
100+
"NOTATIONINSIDECHORD",
101+
"NOTATIONSTACCATO"
102+
];
103+
expect(Object.keys(constants).sort()).toEqual(expectedKeys.sort());
104+
});
105+
106+
test("does not pollute the global scope", () => {
107+
expect(global.DEFAULTVOLUME).toBeUndefined();
108+
expect(global.TONEBPM).toBeUndefined();
109+
expect(global.NOTATIONNOTE).toBeUndefined();
110+
});
111+
});

0 commit comments

Comments
 (0)