|
22 | 22 | * SOFTWARE. |
23 | 23 | */ |
24 | 24 |
|
25 | | -import { render } from '@testing-library/react' |
| 25 | +import { render, screen } from '@testing-library/react' |
26 | 26 | import { vi } from 'vitest' |
27 | 27 | import '@testing-library/jest-dom' |
28 | 28 | import { runAxeCheck } from '@instructure/ui-axe-check' |
@@ -76,6 +76,53 @@ describe('<ColorContrast />', () => { |
76 | 76 | }) |
77 | 77 | }) |
78 | 78 |
|
| 79 | + describe('labelLevel prop', () => { |
| 80 | + it('should render label as div when labelLevel is not provided', async () => { |
| 81 | + render(<ColorContrast {...testColors} {...testLabels} />) |
| 82 | + |
| 83 | + const heading = screen.queryByRole('heading', { |
| 84 | + name: testLabels.label |
| 85 | + }) |
| 86 | + expect(heading).not.toBeInTheDocument() |
| 87 | + |
| 88 | + const labelText = screen.getByText(testLabels.label) |
| 89 | + expect(labelText).toBeInTheDocument() |
| 90 | + expect(labelText.tagName.toLowerCase()).toBe('div') |
| 91 | + }) |
| 92 | + |
| 93 | + it('should render label as Heading when labelLevel is provided', async () => { |
| 94 | + render(<ColorContrast {...testColors} {...testLabels} labelLevel="h2" />) |
| 95 | + |
| 96 | + const heading = screen.getByRole('heading', { |
| 97 | + name: testLabels.label, |
| 98 | + level: 2 |
| 99 | + }) |
| 100 | + expect(heading).toBeInTheDocument() |
| 101 | + }) |
| 102 | + |
| 103 | + it('should render correct heading level', async () => { |
| 104 | + const { rerender } = render( |
| 105 | + <ColorContrast {...testColors} {...testLabels} labelLevel="h3" /> |
| 106 | + ) |
| 107 | + |
| 108 | + let heading = screen.getByRole('heading', { |
| 109 | + name: testLabels.label, |
| 110 | + level: 3 |
| 111 | + }) |
| 112 | + expect(heading).toBeInTheDocument() |
| 113 | + |
| 114 | + rerender( |
| 115 | + <ColorContrast {...testColors} {...testLabels} labelLevel="h1" /> |
| 116 | + ) |
| 117 | + |
| 118 | + heading = screen.getByRole('heading', { |
| 119 | + name: testLabels.label, |
| 120 | + level: 1 |
| 121 | + }) |
| 122 | + expect(heading).toBeInTheDocument() |
| 123 | + }) |
| 124 | + }) |
| 125 | + |
79 | 126 | describe('should calculate contrast correctly', () => { |
80 | 127 | it('on opaque colors', async () => { |
81 | 128 | const color1 = '#fff' |
|
0 commit comments