|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
| 13 | +import {act} from 'react-dom/test-utils'; |
13 | 14 | import {Button} from '@react-spectrum/button';
|
| 15 | +import {Content, Header} from '@react-spectrum/view'; |
| 16 | +import {ContextualHelp} from '@react-spectrum/contextualhelp'; |
14 | 17 | import {Form} from '../';
|
15 | 18 | import {Item, Picker} from '@react-spectrum/picker';
|
| 19 | +import MatchMediaMock from 'jest-matchmedia-mock'; |
16 | 20 | import {Provider} from '@react-spectrum/provider';
|
17 | 21 | import React from 'react';
|
18 |
| -import {render} from '@react-spectrum/test-utils'; |
| 22 | +import {render, triggerPress} from '@react-spectrum/test-utils'; |
19 | 23 | import {TextField} from '@react-spectrum/textfield';
|
20 | 24 | import {theme} from '@react-spectrum/theme-default';
|
21 | 25 | import userEvent from '@testing-library/user-event';
|
| 26 | +import {within} from '@testing-library/dom'; |
22 | 27 |
|
23 | 28 | describe('Form', function () {
|
| 29 | + let matchMedia; |
| 30 | + beforeAll(() => { |
| 31 | + jest.useFakeTimers(); |
| 32 | + }); |
| 33 | + |
| 34 | + beforeEach(() => { |
| 35 | + matchMedia = new MatchMediaMock(); |
| 36 | + }); |
| 37 | + |
24 | 38 | it('should render a form', () => {
|
25 | 39 | let {getByRole} = render(
|
26 | 40 | <Provider theme={theme}>
|
@@ -183,5 +197,45 @@ describe('Form', function () {
|
183 | 197 | let form = getByRole('form');
|
184 | 198 | expect(form.elements['picker'].value).toEqual('one');
|
185 | 199 | });
|
| 200 | + |
| 201 | + it('contextual help should not be disabled nor should its dismiss button be disabled', () => { |
| 202 | + matchMedia.useMediaQuery('(max-width: 700px)'); |
| 203 | + |
| 204 | + let {getByRole, getByLabelText} = render( |
| 205 | + <Provider theme={theme}> |
| 206 | + <Form aria-label="Test" isDisabled> |
| 207 | + <Picker |
| 208 | + name="picker" |
| 209 | + defaultSelectedKey="one" |
| 210 | + label="Test Picker" |
| 211 | + contextualHelp={( |
| 212 | + <ContextualHelp> |
| 213 | + <Header>What is it good for?</Header> |
| 214 | + <Content>Absolutely nothing.</Content> |
| 215 | + </ContextualHelp> |
| 216 | + )}> |
| 217 | + <Item key="one">One</Item> |
| 218 | + <Item key="two">Two</Item> |
| 219 | + <Item key="three">Three</Item> |
| 220 | + </Picker> |
| 221 | + </Form> |
| 222 | + </Provider> |
| 223 | + ); |
| 224 | + |
| 225 | + let button = getByLabelText('Help'); |
| 226 | + triggerPress(button); |
| 227 | + |
| 228 | + let dialog = getByRole('dialog'); |
| 229 | + userEvent.tab(); |
| 230 | + |
| 231 | + let dismissButton = within(dialog).getByRole('button'); |
| 232 | + expect(document.activeElement).toBe(dismissButton); |
| 233 | + |
| 234 | + triggerPress(dismissButton); |
| 235 | + act(() => {jest.runAllTimers();}); |
| 236 | + act(() => {jest.runAllTimers();}); |
| 237 | + |
| 238 | + expect(document.activeElement).toBe(button); |
| 239 | + }); |
186 | 240 | });
|
187 | 241 | });
|
0 commit comments