Skip to content

Commit c9d1bd7

Browse files
committed
remove cursor update from getRandomColor and add setRandomColor function
1 parent b1d217f commit c9d1bd7

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/myr/Myr.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,14 @@ class Myr {
729729
i++;
730730
}
731731
}
732-
this.cursor.color = color;
733732
return color;
734733
}
735734

735+
setRandomColor = (colors = null) => {
736+
this.cursor.color = this.getRandomColor(colors);
737+
return this.cursor.color;
738+
}
739+
736740
drop = (outerElId) => {
737741
this.getEl(outerElId)["dynamic-body"] = "shape: box; mass: 5";
738742
return outerElId;

src/myr/reference.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,14 @@ let transformations = [
260260
{
261261
name: "getRandomColor",
262262
parameters: [{ type: "array", name: "colors" }],
263-
description: <span>The getRandomColor function returns a random color and changes the color of the cursor. If passed an array, getRandomColor will choose randomly from the given colors.</span>,
263+
description: <span>The getRandomColor function returns a random color. If passed an array, getRandomColor will choose randomly from the given colors.</span>,
264264
example: "getRandomColor"
265265
},
266+
{
267+
name: "setRandomColor",
268+
parameters: [{ type: "array", name: "colors" }],
269+
description: <span>The setRandomColor function changes the color of the cursor to a random color. If passed an array, setRandomColor will choose randomly from the given colors.</span>,
270+
},
266271
{
267272
name: "getColor",
268273
parameters: [],

src/tests/Myr.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,26 @@ describe("Updates to Myr's Model", () => {
138138
expect(colorRegEx.test(color)).toBeTruthy();
139139
});
140140

141+
it("to set Random Color", ()=> {
142+
myr.cursor.color = null;
143+
myr.setRandomColor();
144+
expect(myr.cursor.color).not.toBeNull();
145+
})
146+
141147
it("pick Random Color out of a list of colors", () => {
142148
let colors = ["blue", "green", "red", "hotpink", "FF00FF", "rgb(100,33,93)"];
143149
let color = myr.getRandomColor(colors);
144150
expect(color).not.toBeUndefined();
145151
expect(colors.includes(color)).toBeTruthy();
146152
});
153+
154+
it("pick and set Random Color out of a list of colors", () => {
155+
let colors = ["blue", "green", "red", "hotpink", "FF00FF", "rgb(100,33,93)"];
156+
myr.cursor.color = null;
157+
myr.setRandomColor(colors);
158+
expect(myr.cursor.color).not.toBeNull();
159+
expect(colors.includes(myr.cursor.color)).toBeTruthy();
160+
});
147161
});
148162

149163
describe("Component Renders", () => {

0 commit comments

Comments
 (0)