|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
13 |
| -import {act, fireEvent, render, within} from '@testing-library/react'; |
| 13 | +import {act, fireEvent, render, screen, within} from '@testing-library/react'; |
14 | 14 | import {ActionGroup} from '../';
|
15 | 15 | import {Button} from '@react-spectrum/button';
|
16 | 16 | import {Dialog, DialogTrigger} from '@react-spectrum/dialog';
|
@@ -892,6 +892,54 @@ describe('ActionGroup', function () {
|
892 | 892 | expect(buttons[1]).toHaveAttribute('aria-haspopup', 'true');
|
893 | 893 | expect(buttons[1]).toBeDisabled();
|
894 | 894 | });
|
| 895 | + |
| 896 | + it('menu items should be disabled for items listed in disabledKeys', function () { |
| 897 | + const handleOnAction = jest.fn(); |
| 898 | + |
| 899 | + render( |
| 900 | + <Provider theme={theme}> |
| 901 | + <ActionGroup overflowMode="collapse" onAction={handleOnAction} disabledKeys={['two', 'four']}> |
| 902 | + <Item key="one">One</Item> |
| 903 | + <Item key="two">Two</Item> |
| 904 | + <Item key="three">Three</Item> |
| 905 | + <Item key="four">Four</Item> |
| 906 | + </ActionGroup> |
| 907 | + </Provider> |
| 908 | + ); |
| 909 | + |
| 910 | + const actionGroup = screen.getByRole('toolbar'); |
| 911 | + expect(within(actionGroup).getAllByRole('button')).toHaveLength(2); |
| 912 | + expect(within(actionGroup).getByRole('button', {name: 'One'})).toBeVisible(); |
| 913 | + |
| 914 | + const moreButton = within(actionGroup).getByRole('button', {name: '…'}); |
| 915 | + expect(moreButton).toBeVisible(); |
| 916 | + |
| 917 | + triggerPress(moreButton); |
| 918 | + |
| 919 | + const menu = screen.getByRole('menu'); |
| 920 | + expect(within(menu).getAllByRole('menuitem')).toHaveLength(3); |
| 921 | + |
| 922 | + const itemTwo = within(menu).getByRole('menuitem', {name: 'Two'}); |
| 923 | + expect(itemTwo).toBeVisible(); |
| 924 | + expect(itemTwo).toHaveAttribute('aria-disabled', 'true'); |
| 925 | + |
| 926 | + const itemThree = within(menu).getByRole('menuitem', {name: 'Three'}); |
| 927 | + expect(itemThree).toBeVisible(); |
| 928 | + expect(itemThree).toHaveAttribute('aria-disabled', 'false'); |
| 929 | + |
| 930 | + const itemFour = within(menu).getByRole('menuitem', {name: 'Four'}); |
| 931 | + expect(itemFour).toBeVisible(); |
| 932 | + expect(itemFour).toHaveAttribute('aria-disabled', 'true'); |
| 933 | + |
| 934 | + triggerPress(itemTwo); |
| 935 | + expect(handleOnAction).not.toHaveBeenCalled(); |
| 936 | + |
| 937 | + triggerPress(itemFour); |
| 938 | + expect(handleOnAction).not.toHaveBeenCalled(); |
| 939 | + |
| 940 | + triggerPress(itemThree); |
| 941 | + expect(handleOnAction).toHaveBeenCalled(); |
| 942 | + }); |
895 | 943 | });
|
896 | 944 |
|
897 | 945 | describe('buttonLabelBehavior', function () {
|
|
0 commit comments