Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/scratch-gui/src/containers/blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ class Blocks extends React.Component {
this.props.onRequestCloseCustomProcedures(data);
const ws = this.workspace;
this.updateToolbox();
ws.getToolbox().selectCategoryByName('myBlocks');
const toolbox = ws.getToolbox();
toolbox.setSelectedItem(toolbox.getToolboxItemById('myBlocks'));
}
handleDrop (dragInfo) {
fetch(dragInfo.payload.bodyUrl)
Expand All @@ -668,7 +669,7 @@ class Blocks extends React.Component {
});
}
render () {

const {
anyModalVisible,
canUseCloud,
Expand All @@ -693,7 +694,7 @@ class Blocks extends React.Component {
colorMode,
...props
} = this.props;

return (
<React.Fragment>
<DroppableBlocks
Expand Down
33 changes: 33 additions & 0 deletions packages/scratch-gui/test/unit/containers/blocks.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
import {Blocks} from '../../../src/containers/blocks.jsx';

describe('Blocks container handleCustomProceduresClose', () => {
test('selects the My Blocks category after closing', () => {
// The My Blocks category has toolboxitemid="myBlocks" but its
// display name is a translated string like "My Blocks".
// A correct implementation must find the category even when the
// display name doesn't match the toolbox item ID.
const myBlocksItem = {name: 'Mis Bloques'};
const toolbox = {
selectedItem: null,
getToolboxItemById: jest.fn(id => (id === 'myBlocks' ? myBlocksItem : null)),
// Simulates real selectCategoryByName: looks up by display name, not ID
selectCategoryByName: jest.fn(name => {
toolbox.selectedItem = (name === 'Mis Bloques') ? myBlocksItem : null;
}),
setSelectedItem: jest.fn(item => {
toolbox.selectedItem = item;
})
};
Comment on lines +10 to +20
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only asserts the end state (selectedItem) and would still pass if the implementation switched to selectCategoryByName(<translated name>), which wouldn’t verify the intended fix (selecting by toolbox item ID / setSelectedItem path). Consider strengthening the test by asserting getToolboxItemById('myBlocks') and setSelectedItem(myBlocksItem) are called (and optionally that selectCategoryByName is not called), so the test fails if the implementation regresses to name-based selection.

Copilot uses AI. Check for mistakes.
const instance = {
props: {onRequestCloseCustomProcedures: jest.fn()},
workspace: {getToolbox: jest.fn().mockReturnValue(toolbox)},
updateToolbox: jest.fn()
};

Blocks.prototype.handleCustomProceduresClose.call(instance, {});

// The category must actually be resolved and selected.
// If the lookup silently fails, selectedItem will be null
// and the toolbox won't scroll.
expect(toolbox.selectedItem).toBe(myBlocksItem);
});
});

describe('Blocks container onWorkspaceUpdate', () => {
let instance;

Expand Down
Loading