Skip to content

Commit f8589f9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix/sampler-tuner-reference-errors
2 parents fb7fb87 + c98a065 commit f8589f9

26 files changed

Lines changed: 1461 additions & 504 deletions

js/__tests__/activity_toolbar_integration.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const loadActivityClass = () => {
9797
helpfulSearchDiv: null
9898
})),
9999
setupSearchController: jest.fn(),
100+
setupWorkspaceLayoutController: jest.fn(),
100101
hideDOMLabel: jest.fn(),
101102
setupActivityRecorder: jest.fn(),
102103
setupActivityAbcParser: jest.fn(),

js/__tests__/block.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ describe("Block Foundation", () => {
118118
image: "forward.svg",
119119
size: 1,
120120
docks: [],
121-
hidden: false
121+
hidden: false,
122+
capabilities: Object.create(null)
122123
};
123124
});
124125

@@ -172,6 +173,23 @@ describe("Block Foundation", () => {
172173
expect(block2.isInlineCollapsible()).toBe(false);
173174
});
174175

176+
it("hasCapability() should read protoblock capability metadata", () => {
177+
mockProtoBlock.capabilities.collapsible = true;
178+
mockProtoBlock.capabilities.specialInput = true;
179+
180+
const block = new Block(mockProtoBlock, mockBlocks);
181+
expect(block.hasCapability("collapsible")).toBe(true);
182+
expect(block.getCapability("specialInput")).toBe(true);
183+
});
184+
185+
it("should return falsey values when capability metadata is absent", () => {
186+
mockProtoBlock.capabilities = Object.create(null);
187+
188+
const block = new Block(mockProtoBlock, mockBlocks);
189+
expect(block.hasCapability("collapsible")).toBe(false);
190+
expect(block.getCapability("collapsible")).toBeUndefined();
191+
});
192+
175193
it("copySize() should sync size from protoblock", () => {
176194
mockProtoBlock.size = 5;
177195
const block = new Block(mockProtoBlock, mockBlocks);

js/__tests__/palette.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,8 @@ describe("Palettes Class", () => {
15161516
insertRow: jest.fn(() => ({
15171517
style: {},
15181518
innerHTML: "",
1519+
textContent: "",
1520+
appendChild: jest.fn(),
15191521
children: [{ style: {}, appendChild: jest.fn() }]
15201522
}))
15211523
},

js/__tests__/protoblocks.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe("ProtoBlock", () => {
5555
expect(block.expandable).toBe(false);
5656
expect(block.args).toBe(0);
5757
expect(block.defaults).toEqual([]);
58+
expect(block.capabilities).toEqual({});
5859
});
5960

6061
test("adjustWidthToLabel should set textWidth and extraWidth", () => {
@@ -106,4 +107,17 @@ describe("ProtoBlock", () => {
106107
expect(block.dockTypes).toContain("numberout");
107108
expect(block.parameter).toBe(true);
108109
});
110+
111+
test("capability helpers should store and read flags", () => {
112+
block.setCapability("collapsible");
113+
block.setCapabilities({
114+
specialInput: true,
115+
noHit: false
116+
});
117+
118+
expect(block.hasCapability("collapsible")).toBe(true);
119+
expect(block.getCapability("specialInput")).toBe(true);
120+
expect(block.hasCapability("noHit")).toBe(false);
121+
expect(block.getCapability("missing")).toBeUndefined();
122+
});
109123
});

js/__tests__/toolbar.test.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ describe("Toolbar Class", () => {
182182
test("renderLogoIcon sets up logo with correct interactions", () => {
183183
const elements = {
184184
"mb-logo": {
185-
innerHTML: "",
185+
textContent: "",
186+
appendChild: jest.fn(),
186187
onmouseenter: null,
187188
onmouseleave: null,
188189
onclick: null,
@@ -208,7 +209,7 @@ describe("Toolbar Class", () => {
208209

209210
//Non-Japanese language
210211
toolbar.renderLogoIcon(mockOnClick);
211-
expect(elements["mb-logo"].innerHTML).toBe("");
212+
expect(elements["mb-logo"].textContent).toBe("");
212213
expect(typeof elements["mb-logo"].onmouseenter).toBe("function");
213214
expect(typeof elements["mb-logo"].onmouseleave).toBe("function");
214215
expect(typeof elements["mb-logo"].onclick).toBe("function");
@@ -225,8 +226,7 @@ describe("Toolbar Class", () => {
225226
// Japanese language
226227
toolbar.language = "ja";
227228
toolbar.renderLogoIcon(mockOnClick);
228-
expect(elements["mb-logo"].innerHTML).toContain("logo-ja.svg");
229-
expect(elements["mb-logo"].innerHTML).toContain("transform: scale(0.85)");
229+
expect(elements["mb-logo"].appendChild).toHaveBeenCalled();
230230
elements["mb-logo"].onclick();
231231
expect(mockOnClick).toHaveBeenCalledTimes(2);
232232
});
@@ -385,10 +385,19 @@ describe("Toolbar Class", () => {
385385
});
386386

387387
test("renderThemeSelectIcon sets onclick and updates theme selection", () => {
388-
const themeSelectIcon = { onclick: null };
388+
const themeSelectIcon = {
389+
onclick: null,
390+
textContent: "",
391+
childNodes: [],
392+
appendChild: jest.fn(),
393+
cloneNode: jest.fn()
394+
};
389395
const themes = ["light", "dark"];
390396
const themeBox = { setAttribute: jest.fn() };
391-
global.docById.mockReturnValue(themeSelectIcon);
397+
global.docById.mockImplementation(id => {
398+
if (id === "themeSelectIcon") return themeSelectIcon;
399+
return { childNodes: [], cloneNode: jest.fn() };
400+
});
392401
global.localStorage.themePreference = "light";
393402
toolbar.renderThemeSelectIcon(themeBox, themes);
394403
expect(themeSelectIcon.onclick).toBeInstanceOf(Function);
@@ -576,7 +585,9 @@ describe("Toolbar Class", () => {
576585
const recordButton = {
577586
classList: { add: jest.fn() },
578587
style: { display: "" },
579-
innerHTML: ""
588+
innerHTML: "",
589+
textContent: "",
590+
appendChild: jest.fn()
580591
};
581592
global.docById.mockReturnValue(recordButton);
582593
global.fnBrowserDetect = jest.fn(() => "firefox");
@@ -592,13 +603,17 @@ describe("Toolbar Class", () => {
592603
classList: { add: jest.fn(), remove: jest.fn() },
593604
style: { display: "" },
594605
innerHTML: "",
606+
textContent: "",
607+
appendChild: jest.fn(),
595608
onclick: null
596609
};
597610

598611
const recordDropdownArrow = {
599612
classList: { add: jest.fn(), remove: jest.fn() },
600613
style: { display: "" },
601614
innerHTML: "",
615+
textContent: "",
616+
appendChild: jest.fn(),
602617
addEventListener: jest.fn(),
603618
removeEventListener: jest.fn(),
604619
querySelector: jest.fn(() => ({ textContent: "arrow_drop_down" })),
@@ -728,7 +743,7 @@ describe("Toolbar Class", () => {
728743
clickHandler();
729744

730745
expect(mockOnClick).toHaveBeenCalledWith(toolbar.activity, false);
731-
expect(elements.menu.innerHTML).toBe("more_vert");
746+
expect(elements.menu.textContent).toBe("more_vert");
732747
expect(elements.toggleAuxBtn.classList.add).toHaveBeenCalledWith("blue", "darken-1");
733748
expect(elements.search.classList.toggle).toHaveBeenCalledWith("open");
734749

@@ -737,7 +752,7 @@ describe("Toolbar Class", () => {
737752

738753
expect(mockOnClick).toHaveBeenCalledWith(toolbar.activity, true);
739754
expect(elements["aux-toolbar"].style.display).toBe("none");
740-
expect(elements.menu.innerHTML).toBe("menu");
755+
expect(elements.menu.textContent).toBe("menu");
741756
expect(elements.toggleAuxBtn.classList.remove).toHaveBeenCalledWith("blue", "darken-1");
742757
expect(elements.toggleAuxBtn.className).toBe("tooltipped aux-toggle");
743758
expect(elements.chooseKeyDiv.style.display).toBe("none");
@@ -1062,7 +1077,7 @@ describe("Toolbar Class", () => {
10621077
test("closeAuxToolbar hides auxiliary toolbar if visible", () => {
10631078
const elements = {
10641079
"aux-toolbar": { style: { display: "block" } },
1065-
"menu": { innerHTML: "" },
1080+
"menu": { innerHTML: "", textContent: "", appendChild: jest.fn() },
10661081
"toggleAuxBtn": {
10671082
className: "some-class blue darken-1",
10681083
classList: {
@@ -1077,7 +1092,7 @@ describe("Toolbar Class", () => {
10771092
toolbar.activity = {};
10781093
toolbar.closeAuxToolbar(mockOnClick);
10791094
expect(elements["aux-toolbar"].style.display).toBe("none");
1080-
expect(elements.menu.innerHTML).toBe("menu");
1095+
expect(elements.menu.textContent).toBe("menu");
10811096
expect(mockOnClick).toHaveBeenCalledWith(toolbar.activity, false);
10821097
expect(elements.toggleAuxBtn.classList.remove).toHaveBeenCalledWith("blue", "darken-1");
10831098
});
@@ -1283,6 +1298,8 @@ describe("Toolbar Class", () => {
12831298
classList: { add: jest.fn(), remove: jest.fn(), contains: jest.fn(() => false) },
12841299
style: { display: "block" },
12851300
innerHTML: "",
1301+
textContent: "",
1302+
appendChild: jest.fn(),
12861303
addEventListener: jest.fn(),
12871304
querySelector: jest.fn(() => ({ textContent: "" })),
12881305
contains: jest.fn(() => false)

0 commit comments

Comments
 (0)