EnxDev commented on code in PR #36855:
URL: https://github.com/apache/superset/pull/36855#discussion_r2652686752
##########
superset-frontend/src/dashboard/components/gridComponents/TabsRenderer/TabsRenderer.test.tsx:
##########
@@ -199,4 +199,102 @@ describe('TabsRenderer', () => {
expect(screen.getByText('Tab 1 Content')).toBeInTheDocument();
expect(screen.queryByText('Tab 2 Content')).not.toBeInTheDocument(); //
Not active
});
+
+ test('updates DndContext key when tabIds change to reset drag state', () => {
+ const threeTabItems: TabItem[] = [
+ {
+ key: 'tab-1',
+ label: <div>Tab 1</div>,
+ closeIcon: <div>×</div>,
+ children: <div>Tab 1 Content</div>,
+ },
+ {
+ key: 'tab-2',
+ label: <div>Tab 2</div>,
+ closeIcon: <div>×</div>,
+ children: <div>Tab 2 Content</div>,
+ },
+ {
+ key: 'tab-3',
+ label: <div>Tab 3</div>,
+ closeIcon: <div>×</div>,
+ children: <div>Tab 3 Content</div>,
+ },
+ ];
+
+ const mockRef = { current: null };
+ const onTabsReorderMock = jest.fn();
+ const initialTabIds = ['tab-1', 'tab-2', 'tab-3'];
+
+ const props: TabsRendererProps = {
+ ...mockProps,
+ tabItems: threeTabItems,
+ tabIds: initialTabIds,
+ editMode: true,
+ tabsDragSourceRef: mockRef,
+ onTabsReorder: onTabsReorderMock,
+ };
+
+ const { rerender } = render(<TabsRenderer {...props} />);
+
+ // Verify component renders in edit mode with DndContext
+ expect(screen.getByTestId('dashboard-component-tabs')).toBeInTheDocument();
+
+ // Simulate first reorder: tab-1 moved to end -> ['tab-2', 'tab-3',
'tab-1']
+ const reorderedTabIds = ['tab-2', 'tab-3', 'tab-1'];
+ rerender(<TabsRenderer {...props} tabIds={reorderedTabIds} />);
+
+ // The component should re-render with new tabIds
+ // The key prop on DndContext (JSON.stringify(tabIds)) ensures fresh drag
state
+ expect(screen.getByTestId('dashboard-component-tabs')).toBeInTheDocument();
+
+ // Simulate second reorder: tab-2 moved to end -> ['tab-3', 'tab-1',
'tab-2']
+ const secondReorderedTabIds = ['tab-3', 'tab-1', 'tab-2'];
+ rerender(<TabsRenderer {...props} tabIds={secondReorderedTabIds} />);
+
+ // Component should still render correctly after multiple reorders
+ expect(screen.getByTestId('dashboard-component-tabs')).toBeInTheDocument();
Review Comment:
I’m removing this weak test, as it should be covered by an E2E test instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]