forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogoconstants.test.js
More file actions
112 lines (104 loc) · 3.86 KB
/
logoconstants.test.js
File metadata and controls
112 lines (104 loc) · 3.86 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
/**
* @license
* MusicBlocks v3.4.1
* Copyright (C) 2026 Music Blocks Contributors
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
global._ = jest.fn(s => s);
const constants = require("../logoconstants");
describe("logoconstants", () => {
test("module loads and exports an object", () => {
expect(constants).toBeDefined();
expect(typeof constants).toBe("object");
});
test("numeric defaults have correct values", () => {
expect(constants.DEFAULTVOLUME).toBe(50);
expect(constants.PREVIEWVOLUME).toBe(80);
expect(constants.DEFAULTDELAY).toBe(500);
expect(constants.OSCVOLUMEADJUSTMENT).toBe(1.5);
expect(constants.TONEBPM).toBe(240);
expect(constants.TARGETBPM).toBe(90);
expect(constants.TURTLESTEP).toBe(-1);
expect(constants.NOTEDIV).toBe(8);
});
test("error message strings are non-empty strings", () => {
const msgKeys = [
"NOMICERRORMSG",
"NANERRORMSG",
"NOSTRINGERRORMSG",
"NOBOXERRORMSG",
"NOACTIONERRORMSG",
"NOINPUTERRORMSG",
"NOSQRTERRORMSG",
"ZERODIVIDEERRORMSG",
"EMPTYHEAPERRORMSG",
"POSNUMBER"
];
for (const key of msgKeys) {
expect(typeof constants[key]).toBe("string");
expect(constants[key].length).toBeGreaterThan(0);
}
});
test("INVALIDPITCH has the expected translation string", () => {
expect(typeof constants.INVALIDPITCH).toBe("string");
expect(constants.INVALIDPITCH).toBe("Not a valid pitch name");
});
test("notation index constants are sequential integers starting at 0", () => {
expect(constants.NOTATIONNOTE).toBe(0);
expect(constants.NOTATIONDURATION).toBe(1);
expect(constants.NOTATIONDOTCOUNT).toBe(2);
expect(constants.NOTATIONTUPLETVALUE).toBe(3);
expect(constants.NOTATIONROUNDDOWN).toBe(4);
expect(constants.NOTATIONINSIDECHORD).toBe(5);
expect(constants.NOTATIONSTACCATO).toBe(6);
});
test("exports exactly the expected set of keys", () => {
const expectedKeys = [
"DEFAULTVOLUME",
"PREVIEWVOLUME",
"DEFAULTDELAY",
"OSCVOLUMEADJUSTMENT",
"TONEBPM",
"TARGETBPM",
"TURTLESTEP",
"NOTEDIV",
"NOMICERRORMSG",
"NANERRORMSG",
"NOSTRINGERRORMSG",
"NOBOXERRORMSG",
"NOACTIONERRORMSG",
"NOINPUTERRORMSG",
"NOSQRTERRORMSG",
"ZERODIVIDEERRORMSG",
"EMPTYHEAPERRORMSG",
"POSNUMBER",
"INVALIDPITCH",
"MIN_HIGHLIGHT_DURATION_MS",
"NOTATIONNOTE",
"NOTATIONDURATION",
"NOTATIONDOTCOUNT",
"NOTATIONTUPLETVALUE",
"NOTATIONROUNDDOWN",
"NOTATIONINSIDECHORD",
"NOTATIONSTACCATO"
];
expect(Object.keys(constants).sort()).toEqual(expectedKeys.sort());
});
test("does not pollute the global scope", () => {
expect(global.DEFAULTVOLUME).toBeUndefined();
expect(global.TONEBPM).toBeUndefined();
expect(global.NOTATIONNOTE).toBeUndefined();
});
});