Skip to content

Commit 7a1192a

Browse files
committed
2 parents b3e7409 + f0d652a commit 7a1192a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+307601
-295035
lines changed

css/themes.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,15 @@
9595
color: #fff;
9696
}
9797

98+
.dark #chooseKeyDiv {
99+
background: #333;
100+
}
101+
102+
.dark #movable {
103+
background: #333;
104+
color: white;
105+
}
106+
107+
98108

99109
/* Your Custom Theme can go here if you don't want to modify the existing dark mode */

js/__tests__/palette.test.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
const { Palettes, initPalettes } = require('../palette');
2+
3+
global.LEADING = 10;
4+
global.DEFAULTPALETTE = "default";
5+
global.MULTIPALETTES = ["palette1", "palette2"];
6+
global.PALETTEICONS = { "search": "<svg></svg>", "palette1": "<svg></svg>", "palette2": "<svg></svg>" };
7+
global.MULTIPALETTEICONS = ["palette1", "palette2"];
8+
global.SKIPPALETTES = [];
9+
global.toTitleCase = (str) => str.charAt(0).toUpperCase() + str.slice(1);
10+
global._ = (str) => str;
11+
global.platformColor = {
12+
selectorSelected: "#000",
13+
paletteBackground: "#fff",
14+
strokeColor: "#333",
15+
fillColor: "#666",
16+
paletteLabelBackground: "#ccc",
17+
hoverColor: "#ddd",
18+
paletteText: "#000"
19+
};
20+
21+
describe('Palettes Class', () => {
22+
let mockActivity;
23+
let palettes;
24+
25+
beforeEach(() => {
26+
const paletteMock = {
27+
style: { visibility: 'visible' },
28+
children: [
29+
{
30+
children: [
31+
{},
32+
{
33+
children: [
34+
{},
35+
{
36+
parentNode: { removeChild: jest.fn() },
37+
appendChild: jest.fn(() => ({})),
38+
}
39+
]
40+
}
41+
]
42+
}
43+
]
44+
};
45+
46+
global.docById = jest.fn((id) => {
47+
if (id === "PaletteBody") {
48+
return { parentNode: { removeChild: jest.fn() } };
49+
}
50+
if (id === "palette") {
51+
return {
52+
...paletteMock,
53+
children: [
54+
{ children: [{}, { children: [{}, { removeChild: jest.fn(), appendChild: jest.fn(() => ({})) }] }] }
55+
],
56+
};
57+
}
58+
return { style: {}, appendChild: jest.fn(), removeChild: jest.fn() };
59+
});
60+
61+
mockActivity = {
62+
cellSize: 50,
63+
blocks: { protoBlockDict: {}, makeBlock: jest.fn(() => ({})) },
64+
hideSearchWidget: jest.fn(),
65+
showSearchWidget: jest.fn(),
66+
palettes: {},
67+
};
68+
69+
palettes = new Palettes(mockActivity);
70+
});
71+
72+
test('constructor initializes properties correctly', () => {
73+
expect(palettes.activity).toBe(mockActivity);
74+
expect(palettes.cellSize).toBe(Math.floor(50 * 0.5 + 0.5));
75+
});
76+
77+
test('init method sets halfCellSize', () => {
78+
palettes.init();
79+
expect(palettes.halfCellSize).toBe(Math.floor(palettes.cellSize / 2));
80+
});
81+
82+
test('setSize updates cellSize', () => {
83+
palettes.setSize(100);
84+
expect(palettes.cellSize).toBe(Math.floor(100 * 0.5 + 0.5));
85+
});
86+
87+
test('setMobile updates mobile flag and hides menus', () => {
88+
const spyHideMenus = jest.spyOn(palettes, '_hideMenus');
89+
palettes.setMobile(true);
90+
expect(palettes.mobile).toBe(true);
91+
expect(spyHideMenus).toHaveBeenCalled();
92+
});
93+
94+
test('getProtoNameAndPalette returns correct values', () => {
95+
mockActivity.blocks.protoBlockDict = {
96+
testBlock: { name: 'testBlock', palette: { name: 'testPalette' }, hidden: false }
97+
};
98+
expect(palettes.getProtoNameAndPalette('testBlock')).toEqual(['testBlock', 'testPalette', 'testBlock']);
99+
});
100+
101+
test('hide and show functions modify visibility', () => {
102+
palettes.hide();
103+
console.log('Visibility after hide:', docById('palette').style.visibility);
104+
expect(docById('palette').style.visibility).toBe('hidden');
105+
palettes.show();
106+
console.log('Visibility after show:', docById('palette').style.visibility);
107+
expect(docById('palette').style.visibility).toBe('visible');
108+
});
109+
});
110+
111+
describe('initPalettes function', () => {
112+
let palettes;
113+
114+
beforeEach(() => {
115+
palettes = { add: jest.fn(), init_selectors: jest.fn(), makePalettes: jest.fn(), show: jest.fn() };
116+
global.BUILTINPALETTES = ['default'];
117+
});
118+
119+
test('initPalettes initializes palettes correctly', async () => {
120+
await initPalettes(palettes);
121+
expect(palettes.add).toHaveBeenCalledWith('default');
122+
expect(palettes.init_selectors).toHaveBeenCalled();
123+
expect(palettes.makePalettes).toHaveBeenCalledWith(0);
124+
expect(palettes.show).toHaveBeenCalled();
125+
});
126+
});

js/__tests__/rubrics.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ describe('rubrics.js test suite', () => {
9898
turtles: {
9999
turtleList: [
100100
{ painter: { doClear: jest.fn() } }
101-
]
101+
],
102+
getTurtleCount: jest.fn(() => 1),
103+
getTurtle: jest.fn((id) => ({
104+
painter: { doClear: jest.fn() }
105+
}))
102106
}
103107
};
104108

js/__tests__/turtles.test.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
const Turtles = require('../turtles');
2+
3+
global.createjs = {
4+
Container: jest.fn().mockImplementation(() => ({
5+
addChild: jest.fn(),
6+
removeAllChildren: jest.fn(),
7+
on: jest.fn(),
8+
removeAllEventListeners: jest.fn(),
9+
})),
10+
Bitmap: jest.fn().mockImplementation(() => ({})),
11+
};
12+
13+
global.importMembers = jest.fn();
14+
global.setupRhythmActions = jest.fn();
15+
global.setupMeterActions = jest.fn();
16+
global.setupPitchActions = jest.fn();
17+
global.setupIntervalsActions = jest.fn();
18+
global.setupToneActions = jest.fn();
19+
global.setupOrnamentActions = jest.fn();
20+
global.setupVolumeActions = jest.fn();
21+
global.setupDrumActions = jest.fn();
22+
global.setupDictActions = jest.fn();
23+
24+
global.Turtle = jest.fn().mockImplementation(() => ({
25+
painter: {
26+
doSetHeading: jest.fn(),
27+
doSetPensize: jest.fn(),
28+
doSetChroma: jest.fn(),
29+
doSetValue: jest.fn(),
30+
doSetColor: jest.fn(),
31+
},
32+
rename: jest.fn(),
33+
container: {
34+
scaleX: 1,
35+
scaleY: 1,
36+
scale: 1,
37+
on: jest.fn(),
38+
removeAllEventListeners: jest.fn(),
39+
},
40+
}));
41+
42+
describe('Turtles Class', () => {
43+
let activityMock;
44+
let turtles;
45+
46+
beforeEach(() => {
47+
activityMock = {
48+
stage: { addChild: jest.fn(), removeChild: jest.fn() },
49+
refreshCanvas: jest.fn(),
50+
turtleContainer: new createjs.Container(),
51+
hideAuxMenu: jest.fn(),
52+
hideGrids: jest.fn(),
53+
_doCartesianPolar: jest.fn(),
54+
};
55+
56+
turtles = new Turtles(activityMock);
57+
turtles.activity = activityMock;
58+
turtles.getTurtleCount = jest.fn().mockReturnValue(0);
59+
turtles.getTurtle = jest.fn(() => ({
60+
container: {
61+
scaleX: 1,
62+
scaleY: 1,
63+
scale: 1,
64+
},
65+
}));
66+
67+
turtles.pushTurtle = jest.fn();
68+
turtles.addTurtleStageProps = jest.fn();
69+
turtles.createArtwork = jest.fn();
70+
turtles.createHitArea = jest.fn();
71+
turtles.addTurtleGraphicProps = jest.fn();
72+
turtles.isShrunk = jest.fn().mockReturnValue(false);
73+
document.body.innerHTML = '<div id="loader"></div>';
74+
});
75+
76+
test('should initialize properly', () => {
77+
expect(turtles.activity).not.toBeUndefined();
78+
expect(global.importMembers).toHaveBeenCalledWith(turtles, "", [activityMock]);
79+
});
80+
81+
test('should call initActions on construction', () => {
82+
const spy = jest.spyOn(turtles, 'initActions');
83+
turtles.initActions();
84+
expect(spy).toHaveBeenCalled();
85+
});
86+
87+
test('should add a turtle properly', () => {
88+
turtles.addTurtle({}, { id: 1, name: 'TestTurtle' });
89+
90+
expect(turtles.getTurtleCount).toHaveBeenCalled();
91+
expect(turtles.pushTurtle).toHaveBeenCalled();
92+
expect(turtles.addTurtleStageProps).toHaveBeenCalled();
93+
expect(turtles.createArtwork).toHaveBeenCalled();
94+
expect(turtles.createHitArea).toHaveBeenCalled();
95+
expect(turtles.addTurtleGraphicProps).toHaveBeenCalled();
96+
expect(turtles.isShrunk).toHaveBeenCalled();
97+
});
98+
99+
test('should toggle running state correctly', () => {
100+
turtles.markAllAsStopped();
101+
expect(activityMock.refreshCanvas).toHaveBeenCalled();
102+
});
103+
});

0 commit comments

Comments
 (0)