Skip to content

Commit

Permalink
refactor(code_block): improve the copyAriaLabel test case
Browse files Browse the repository at this point in the history
- remove the wrapping describe,
- update the assertion to toHaveAttribute
  • Loading branch information
weronikaolejniczak committed Nov 25, 2024
1 parent dbeb3be commit acc44d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,59 +382,6 @@ exports[`EuiCodeBlock line numbers renders line numbers with a start value 1`] =
</div>
`;

exports[`EuiCodeBlock props copyAriaLabel is rendered 1`] = `
<div
class="euiCodeBlock emotion-euiCodeBlock-s-hasControls"
>
<pre
class="euiCodeBlock__pre emotion-euiCodeBlock__pre-preWrap-padding-controlsOffset"
tabindex="-1"
>
<code
class="euiCodeBlock__code emotion-euiCodeBlock__code"
data-code-language="text"
>
<span
class="euiCodeBlock__line emotion-euiCodeBlock__line"
>
var some = 'code';
</span>
<span
class="euiCodeBlock__line emotion-euiCodeBlock__line"
>
console.log(some);
</span>
</code>
</pre>
<div
class="euiCodeBlock__controls emotion-euiCodeBlock__controls-l"
>
<div
class="euiCodeBlock__copyButton"
>
<span
class="euiToolTipAnchor emotion-euiToolTipAnchor-inlineBlock"
>
<button
aria-label="Copy this code"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="euiCodeBlockCopy"
type="button"
>
<span
aria-hidden="true"
class="euiButtonIcon__icon"
color="inherit"
data-euiicon-type="copyClipboard"
/>
</button>
</span>
</div>
</div>
</div>
`;

exports[`EuiCodeBlock props fontSize l is rendered 1`] = `
<div
class="euiCodeBlock emotion-euiCodeBlock-l"
Expand Down
21 changes: 11 additions & 10 deletions packages/eui/src/components/code/code_block.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ describe('EuiCodeBlock', () => {
});
});

describe('copyAriaLabel', () => {
it('is rendered', () => {
const customLabel = 'Copy this code';
const { container } = render(
<EuiCodeBlock isCopyable copyAriaLabel={customLabel}>
{code}
</EuiCodeBlock>
);
it('renders `copyAriaLabel` on the copy button', () => {
const customLabel = 'Copy this code';
const { getByTestSubject } = render(
<EuiCodeBlock isCopyable copyAriaLabel={customLabel}>
{code}
</EuiCodeBlock>
);

expect(container.firstChild).toMatchSnapshot();
});
expect(getByTestSubject('euiCodeBlockCopy')).toHaveAttribute(
'aria-label',
customLabel
);
});

describe('overflowHeight', () => {
Expand Down

0 comments on commit acc44d3

Please sign in to comment.