Skip to content

Commit 938a676

Browse files
authored
Fix Turtles Regression and Restore Failing Tests (sugarlabs#5760)
This PR fixes failing tests in js/tests/turtles.test.js and resolves regression in js/turtles.js where the background color functionality was accidentally removed during a previous refactor.
1 parent 5a34c5b commit 938a676

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

js/__tests__/turtles.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ global.setupVolumeActions = jest.fn();
4040
global.setupDrumActions = jest.fn();
4141
global.setupDictActions = jest.fn();
4242

43+
global.LEADING = 35;
44+
global.CARTESIANBUTTON = "";
45+
global.CLEARBUTTON = "";
46+
global.COLLAPSEBUTTON = "";
47+
global.EXPANDBUTTON = "";
48+
global.MBOUNDARY = "";
49+
global.piemenuGrid = {};
50+
global.base64Encode = jest.fn(str => str);
51+
4352
global.Turtle = jest.fn().mockImplementation(() => ({
4453
painter: {
4554
doSetHeading: jest.fn(),
@@ -113,6 +122,9 @@ describe("Turtles Class", () => {
113122
turtles.addTurtleGraphicProps = jest.fn();
114123
turtles.isShrunk = jest.fn().mockReturnValue(false);
115124
document.body.innerHTML = '<div id="loader"></div>';
125+
window.jQuery = jest.fn().mockReturnValue({
126+
tooltip: jest.fn()
127+
});
116128
});
117129

118130
test("should initialize properly", () => {
@@ -382,6 +394,7 @@ describe("setBackgroundColor", () => {
382394
turtles._scale = 1.0;
383395
global.platformColor = { background: "#ffffff" };
384396
turtles._backgroundColor = platformColor.background;
397+
turtles._borderContainer = new createjs.Container();
385398
});
386399

387400
test("should set default background color when index is -1", () => {
@@ -447,6 +460,7 @@ describe("doScale", () => {
447460
turtles._locked = false;
448461
turtles._queue = [];
449462
turtles._backgroundColor = "#ffffff";
463+
turtles._borderContainer = new createjs.Container();
450464
});
451465

452466
test("should update scale, width, and height when not locked", () => {

js/turtles.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,17 @@ Turtles.TurtlesView = class {
864864
// Remove any old background containers
865865
borderContainer.removeAllChildren();
866866

867+
// Update the canvas background color
868+
const canvas = this.canvas;
869+
if (canvas) {
870+
canvas.style.backgroundColor = this._backgroundColor;
871+
}
872+
873+
// Also update body background if available
874+
if (typeof document !== "undefined") {
875+
document.body.style.backgroundColor = this._backgroundColor;
876+
}
877+
867878
const turtlesStage = this.stage;
868879
// We put the buttons on the stage so they will be on top
869880

0 commit comments

Comments
 (0)