Skip to content

Commit e06b619

Browse files
refactor test
1 parent c0fab02 commit e06b619

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

  • superset-frontend/packages/superset-ui-core/src/components/Select

‎superset-frontend/packages/superset-ui-core/src/components/Select/Select.test.tsx‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -837,20 +837,34 @@ test('dropdown width matches input width after tags collapse in oneLine mode', a
837837
});
838838

839839
const selectElement = document.querySelector('.ant-select') as HTMLElement;
840+
expect(selectElement).toBeInTheDocument();
841+
842+
// Mock the select element's width since JSDOM doesn't perform real layout
843+
jest.spyOn(selectElement, 'getBoundingClientRect').mockReturnValue({
844+
width: 300,
845+
height: 32,
846+
top: 0,
847+
left: 0,
848+
right: 300,
849+
bottom: 32,
850+
x: 0,
851+
y: 0,
852+
toJSON: () => ({}),
853+
} as DOMRect);
854+
855+
// Close and reopen to trigger width measurement with mocked value
856+
await type('{esc}');
857+
await open();
858+
840859
const dropdown = document.querySelector(
841860
'.ant-select-dropdown',
842861
) as HTMLElement;
843-
844-
expect(selectElement).toBeInTheDocument();
845862
expect(dropdown).toBeInTheDocument();
846863

847-
// The dropdown width should match the collapsed input width
848-
const selectWidth = selectElement.getBoundingClientRect().width;
849-
const dropdownWidth = dropdown.getBoundingClientRect().width;
850-
851-
// In oneLine mode with tags, dropdown width should match input width
852-
// Allow small tolerance for sub-pixel differences
853-
expect(Math.abs(dropdownWidth - selectWidth)).toBeLessThanOrEqual(1);
864+
// Verify the dropdown has inline width matching the mocked select width
865+
await waitFor(() => {
866+
expect(parseInt(dropdown.style.width, 10)).toBe(300);
867+
});
854868
});
855869

856870
test('does not render "Select all" when there are 0 or 1 options', async () => {

0 commit comments

Comments
 (0)