Skip to content

Commit 93c40c8

Browse files
authored
test suite for js/turtledefs.js (#4383)
* Create test file turtledefs.test.js * Exporting modules for test * Updating test turtledefs.test.js * updating export modules
1 parent 0fd329a commit 93c40c8

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

js/__tests__/turtledefs.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
global._ = jest.fn((str) => str);
2+
global._THIS_IS_TURTLE_BLOCKS_ = true;
3+
const {
4+
createDefaultStack,
5+
LOGOJA1,
6+
NUMBERBLOCKDEFAULT,
7+
DEFAULTPALETTE,
8+
TITLESTRING
9+
} = require('../turtledefs');
10+
11+
global.GUIDEURL = "guide url";
12+
global.RUNBUTTON = "RUNBUTTON";
13+
global.STOPBUTTON = "STOPBUTTON";
14+
global.HELPTURTLEBUTTON = "HELPTURTLEBUTTON";
15+
global.LANGUAGEBUTTON = "LANGUAGEBUTTON";
16+
17+
if (GUIDEURL === "guide url") {
18+
GUIDEURL = "https://github.com/sugarlabs/turtleblocksjs/tree/master/guide/README.md";
19+
}
20+
21+
describe("turtledefs.js", () => {
22+
test("LOGOJA1 should be properly initialized", () => {
23+
expect(LOGOJA1).toBeDefined();
24+
expect(typeof LOGOJA1).toBe("string");
25+
});
26+
27+
test("NUMBERBLOCKDEFAULT should be initialized correctly", () => {
28+
expect(NUMBERBLOCKDEFAULT).toBeDefined();
29+
expect(NUMBERBLOCKDEFAULT).toBe(100);
30+
});
31+
32+
test("DEFAULTPALETTE should have correct value", () => {
33+
expect(DEFAULTPALETTE).toBe("turtle");
34+
});
35+
36+
test("GUIDEURL should default to the correct URL", () => {
37+
expect(GUIDEURL).toBe("https://github.com/sugarlabs/turtleblocksjs/tree/master/guide/README.md");
38+
});
39+
40+
test("TITLESTRING should be defined", () => {
41+
expect(TITLESTRING).toBeDefined();
42+
});
43+
44+
test("createDefaultStack function should be callable", () => {
45+
expect(typeof createDefaultStack).toBe("function");
46+
});
47+
});

js/turtledefs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,12 @@ const createHelpContent = (activity) => {
817817
]);
818818
}
819819
};
820+
if (typeof module !== "undefined" && module.exports) {
821+
module.exports = {
822+
createDefaultStack,
823+
LOGOJA1,
824+
NUMBERBLOCKDEFAULT,
825+
DEFAULTPALETTE,
826+
TITLESTRING
827+
}
828+
}

0 commit comments

Comments
 (0)