|
| 1 | +/* |
| 2 | + * Copyright 2026 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import {Button} from '../src/Button'; |
| 14 | +import {ButtonGroup} from '../src/ButtonGroup'; |
| 15 | +import {describe, expect, it} from 'vitest'; |
| 16 | +import React from 'react'; |
| 17 | +import {render} from './utils/render'; |
| 18 | + |
| 19 | +describe('ButtonGroup', () => { |
| 20 | + it('stacks vertically when the container shrinks below the width of buttons with no-space labels', async () => { |
| 21 | + let {container} = await render( |
| 22 | + <div style={{width: '500px'}} data-testid="wrapper"> |
| 23 | + <ButtonGroup data-testid="button-group"> |
| 24 | + <Button variant="primary">nospace</Button> |
| 25 | + <Button variant="secondary">nospace</Button> |
| 26 | + <Button variant="secondary">nospace</Button> |
| 27 | + </ButtonGroup> |
| 28 | + </div> |
| 29 | + ); |
| 30 | + |
| 31 | + let wrapper = container.querySelector('[data-testid="wrapper"]') as HTMLElement; |
| 32 | + let buttonGroup = container.querySelector('[data-testid="button-group"]') as HTMLElement; |
| 33 | + |
| 34 | + // Initially wide — buttons should be laid out horizontally |
| 35 | + expect(getComputedStyle(buttonGroup).flexDirection).toBe('row'); |
| 36 | + |
| 37 | + // Shrink the container below the combined button widths to trigger overflow detection |
| 38 | + wrapper.style.width = '50px'; |
| 39 | + |
| 40 | + // Wait for ResizeObserver and React re-render to settle |
| 41 | + await expect.poll(() => getComputedStyle(buttonGroup).flexDirection).toBe('column'); |
| 42 | + |
| 43 | + // Restore the container width — should return to horizontal |
| 44 | + wrapper.style.width = '500px'; |
| 45 | + await expect.poll(() => getComputedStyle(buttonGroup).flexDirection).toBe('row'); |
| 46 | + }); |
| 47 | +}); |
0 commit comments