|
| 1 | +/* |
| 2 | + * Copyright 2025 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 {act, pointerMap, render} from '@react-spectrum/test-utils-internal'; |
| 14 | +import {ActionButton, CustomDialog, DialogTrigger, Tag, TagGroup} from '../src'; |
| 15 | +import React from 'react'; |
| 16 | +import userEvent from '@testing-library/user-event'; |
| 17 | + |
| 18 | +describe('CustomDialog', () => { |
| 19 | + let user; |
| 20 | + beforeAll(() => { |
| 21 | + user = userEvent.setup({delay: null, pointerMap}); |
| 22 | + jest.useFakeTimers(); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + jest.clearAllMocks(); |
| 27 | + act(() => jest.runAllTimers()); |
| 28 | + }); |
| 29 | + |
| 30 | + afterAll(function () { |
| 31 | + jest.restoreAllMocks(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should allow you to render a taggroup inside', async () => { |
| 35 | + let {getByRole} = render( |
| 36 | + <DialogTrigger> |
| 37 | + <ActionButton>Open dialog</ActionButton> |
| 38 | + <CustomDialog isDismissible> |
| 39 | + <TagGroup |
| 40 | + label="Ice cream categories" |
| 41 | + maxRows={1} |
| 42 | + onRemove={() => {}}> |
| 43 | + <Tag>Chocolate</Tag> |
| 44 | + <Tag>Mint</Tag> |
| 45 | + <Tag>Strawberry</Tag> |
| 46 | + <Tag>Vanilla</Tag> |
| 47 | + </TagGroup> |
| 48 | + </CustomDialog> |
| 49 | + </DialogTrigger> |
| 50 | + ); |
| 51 | + |
| 52 | + |
| 53 | + let trigger = getByRole('button'); |
| 54 | + await user.click(trigger); |
| 55 | + act(() => {jest.runAllTimers();}); |
| 56 | + |
| 57 | + expect(getByRole('dialog')).toBeVisible(); |
| 58 | + }); |
| 59 | +}); |
0 commit comments