Skip to content

Commit 15d4aae

Browse files
authored
test suite for js/artwork.js (#4387)
* creating test for js/artwork.js * Exporting modules for test
1 parent 4c40a09 commit 15d4aae

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

js/__tests__/artwork.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
global._THIS_IS_TURTLE_BLOCKS_ = true;
2+
const { showMaterialHighlight, hideButtonHighlight, hidePaletteNameDisplay, COLLAPSEBUTTONXOFF, STANDARDBLOCKHEIGHT, FILLCOLORS, TURTLESVG } = require('../artwork');
3+
4+
global.createjs = {
5+
Shape: jest.fn(() => ({
6+
graphics: { f: jest.fn().mockReturnThis(), drawCircle: jest.fn().mockReturnThis() },
7+
alpha: 0,
8+
x: 0,
9+
y: 0
10+
})),
11+
Tween: {
12+
get: jest.fn(() => ({
13+
to: jest.fn().mockReturnThis()
14+
}))
15+
},
16+
Ease: { circInOut: jest.fn() }
17+
};
18+
19+
describe('artwork.js Test Suite', () => {
20+
let mockStage;
21+
22+
beforeEach(() => {
23+
mockStage = {
24+
addChild: jest.fn(),
25+
removeChild: jest.fn()
26+
};
27+
});
28+
29+
test('showMaterialHighlight creates highlight and active shapes', () => {
30+
const event = { rawX: 100, rawY: 100 };
31+
const scale = 1;
32+
const result = showMaterialHighlight(50, 50, 10, event, scale, mockStage);
33+
expect(result).toHaveProperty('highlight');
34+
expect(result).toHaveProperty('active');
35+
expect(mockStage.addChild).toHaveBeenCalledWith(result.highlight, result.active);
36+
});
37+
38+
test('hideButtonHighlight removes highlight properly', () => {
39+
jest.useFakeTimers();
40+
const circles = { highlight: {}, active: {} };
41+
hideButtonHighlight(circles, mockStage);
42+
jest.runAllTimers();
43+
expect(mockStage.removeChild).toBeCalledWith(circles.active, circles.highlight);
44+
jest.useRealTimers();
45+
});
46+
47+
test('hidePaletteNameDisplay removes palette text after delay', () => {
48+
jest.useFakeTimers();
49+
const paletteText = {};
50+
hidePaletteNameDisplay(paletteText, mockStage);
51+
jest.runAllTimers();
52+
expect(mockStage.removeChild).toBeCalledWith(paletteText);
53+
jest.useRealTimers();
54+
});
55+
56+
test('Constants are correctly defined', () => {
57+
expect(typeof COLLAPSEBUTTONXOFF).toBe('number');
58+
expect(typeof STANDARDBLOCKHEIGHT).toBe('number');
59+
expect(Array.isArray(FILLCOLORS)).toBe(true);
60+
expect(typeof TURTLESVG).toBe('string');
61+
});
62+
});

js/artwork.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)