Skip to content

Commit 3fe5902

Browse files
sadpandajoeclaude
andcommitted
fix(dashboard): use toHaveStyleRule and getByTestId in droptarget test
Replace CSSOM scan with @emotion/jest toHaveStyleRule matcher using the target option to verify the .empty-droptarget rule on StyledHeader. Switch from container.querySelector to getByTestId for consistency with other tests in this file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0b442ef commit 3fe5902

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ test('should apply min-height to the top-level tab drop target so tabs can be dr
496496
(fetchFaveStar as jest.Mock).mockReturnValue({ type: 'mock-action' });
497497
(setActiveTab as jest.Mock).mockReturnValue({ type: 'mock-action' });
498498

499-
const { container } = render(<DashboardBuilder />, {
499+
const { getByTestId } = render(<DashboardBuilder />, {
500500
useRedux: true,
501501
store: storeWithState({
502502
...mockState,
@@ -507,33 +507,22 @@ test('should apply min-height to the top-level tab drop target so tabs can be dr
507507
useTheme: true,
508508
});
509509

510-
const headerWrapper = container.querySelector(
511-
'[data-test="dashboard-header-wrapper"]',
512-
);
513-
expect(headerWrapper).toBeInTheDocument();
510+
const headerWrapper = getByTestId('dashboard-header-wrapper');
514511

515512
// The Droppable inside the header should have the empty-droptarget class
516513
// when there are no top-level tabs and edit mode is active. Without this
517514
// class (and its associated min-height CSS rule), the drop target has zero
518515
// height and users cannot drag tabs onto dashboards that already have
519516
// content.
520-
const droptarget = headerWrapper!.querySelector('.empty-droptarget');
517+
const droptarget = headerWrapper.querySelector('.empty-droptarget');
521518
expect(droptarget).toBeInTheDocument();
522519

523520
// Verify the StyledHeader CSS defines min-height for .empty-droptarget.
524-
// getComputedStyle doesn't work in jsdom for styled-components injected
525-
// styles, so we check the CSSOM directly.
526-
const allRules = Array.from(document.styleSheets).flatMap(sheet => {
527-
try {
528-
return Array.from(sheet.cssRules).map(rule => rule.cssText);
529-
} catch {
530-
return [];
531-
}
532-
});
533-
const emptyDroptargetRule = allRules.find(
534-
rule => rule.includes('.empty-droptarget') && rule.includes('min-height'),
521+
expect(headerWrapper).toHaveStyleRule(
522+
'min-height',
523+
expect.stringMatching(/\S+/),
524+
{ target: '.empty-droptarget' },
535525
);
536-
expect(emptyDroptargetRule).toBeDefined();
537526
});
538527

539528
test('should maintain layout when switching between tabs', async () => {

0 commit comments

Comments
 (0)