|
| 1 | +/* |
| 2 | + * Copyright 2020 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 {DismissButton} from '..'; |
| 14 | +import React from 'react'; |
| 15 | +import {render} from '@testing-library/react'; |
| 16 | + |
| 17 | + |
| 18 | +describe('DismissButton', function () { |
| 19 | + it('should have a default aria-label', function () { |
| 20 | + let {getByRole} = render(<DismissButton />); |
| 21 | + expect(getByRole('button', {hidden: true})).toHaveAttribute('aria-label', 'Dismiss'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should accept an aria-label', function () { |
| 25 | + let {getByRole} = render(<DismissButton aria-label="foo" />); |
| 26 | + expect(getByRole('button', {hidden: true})).toHaveAttribute('aria-label', 'foo'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should accept an aria-labelledby', function () { |
| 30 | + let {getByRole} = render( |
| 31 | + <> |
| 32 | + <span id="span-id">bar</span> |
| 33 | + <DismissButton aria-labelledby="span-id" /> |
| 34 | + </> |
| 35 | + ); |
| 36 | + expect(getByRole('button', {hidden: true})).toHaveAttribute('aria-labelledby', 'span-id'); |
| 37 | + expect(getByRole('button', {hidden: true})).not.toHaveAttribute('aria-label'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should accept an aria-labelledby and aria-label', function () { |
| 41 | + let {getByRole} = render( |
| 42 | + <> |
| 43 | + <span id="span-id">bar</span> |
| 44 | + <DismissButton aria-labelledby="span-id" aria-label="foo" id="self" /> |
| 45 | + </> |
| 46 | + ); |
| 47 | + expect(getByRole('button', {hidden: true})).toHaveAttribute('aria-labelledby', 'span-id self'); |
| 48 | + expect(getByRole('button', {hidden: true})).toHaveAttribute('aria-label', 'foo'); |
| 49 | + }); |
| 50 | + |
| 51 | +}); |
0 commit comments