-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathBooleanBlocks.test.js
More file actions
110 lines (96 loc) · 2.99 KB
/
BooleanBlocks.test.js
File metadata and controls
110 lines (96 loc) · 2.99 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
/**
* MusicBlocks v3.6.2
*
* @author Om Santosh Suneri
*
* @copyright 2025 Om Santosh Suneri
*
* @license
* 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/>.
*/
const { setupBooleanBlocks } = require("../BooleanBlocks");
global._ = jest.fn(str => str);
global.NOINPUTERRORMSG = "No input error message";
let createdBlocks = [];
/**
* Minimal BooleanBlock stub
* Captures created instances
*/
global.BooleanBlock = class {
constructor(type) {
this.type = type;
createdBlocks.push(this);
}
setPalette() {}
setHelpString() {}
formBlock() {}
setup() {}
beginnerBlock() {}
};
describe("setupBooleanBlocks - Real Coverage Tests", () => {
let mockActivity;
let mockLogo;
beforeEach(() => {
createdBlocks = [];
mockActivity = {
blocks: {
blockList: {
blk1: { value: true, connections: [null, null, null] },
blk2: { value: false, connections: [null, null, null] },
blk3: { value: true, connections: [null, "blk4", "blk5"] },
blk4: { value: false, connections: [null, null, null] },
blk5: { value: true, connections: [null, null, null] },
},
},
errorMsg: jest.fn(),
};
mockLogo = {
parseArg: jest.fn((logo, turtle, cblk) => {
return mockActivity.blocks.blockList[cblk].value;
}),
};
setupBooleanBlocks(mockActivity);
});
function getBlock(type) {
return createdBlocks.find(b => b.type === type);
}
test("Not block works", () => {
const notBlock = getBlock("not");
const result = notBlock.arg(mockLogo, "turtle", "blk3", true);
expect(result).toBe(true);
});
test("And block works", () => {
const andBlock = getBlock("and");
const result = andBlock.arg(mockLogo, "turtle", "blk3", true);
expect(result).toBe(false);
});
test("Or block works", () => {
const orBlock = getBlock("or");
const result = orBlock.arg(mockLogo, "turtle", "blk3", true);
expect(result).toBe(true);
});
test("Equal block works", () => {
const equalBlock = getBlock("equal");
const result = equalBlock.arg(mockLogo, "turtle", "blk3", true);
expect(result).toBe(false);
});
test("Null connection triggers error", () => {
const notBlock = getBlock("not");
notBlock.arg(mockLogo, "turtle", "blk1", true);
expect(mockActivity.errorMsg).toHaveBeenCalledWith(
global.NOINPUTERRORMSG,
"blk1"
);
});
});