A11y : Updated EmptyListCTA to switch between Button and LinkButton (#46292)

* Updated EmptyListCTA to switch between Button and LinkButton

* Added tests
This commit is contained in:
Yaelle Chaudy
2022-03-08 12:41:00 +01:00
committed by GitHub
parent 2aeae69a16
commit bfde8ee603
2 changed files with 23 additions and 4 deletions
@@ -0,0 +1,18 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import EmptyListCTA from './EmptyListCTA';
describe('EmptyListCTA', () => {
it('should return a button element if there is no buttonLink prop', () => {
render(<EmptyListCTA title="title" buttonIcon="plus" buttonTitle="button title" />);
expect(screen.getByRole('button', { name: 'button title' }));
});
it('should return an anchor element if there is a buttonLink prop', () => {
render(<EmptyListCTA title="title" buttonIcon="plus" buttonLink="href" buttonTitle="button title" />);
expect(screen.getByRole('link', { name: 'button title' }));
});
});
@@ -1,7 +1,7 @@
import React, { MouseEvent } from 'react';
import { css } from '@emotion/css';
import { CallToActionCard, Icon, IconName, LinkButton } from '@grafana/ui';
import { selectors } from '@grafana/e2e-selectors';
import { Button, CallToActionCard, Icon, IconName, LinkButton } from '@grafana/ui';
import React, { MouseEvent } from 'react';
export interface Props {
title: string;
@@ -75,8 +75,9 @@ const EmptyListCTA: React.FunctionComponent<Props> = ({
`
: '';
const ButtonEl = buttonLink ? LinkButton : Button;
const ctaElement = (
<LinkButton
<ButtonEl
size="lg"
onClick={onClick}
href={buttonLink}
@@ -86,7 +87,7 @@ const EmptyListCTA: React.FunctionComponent<Props> = ({
disabled={buttonDisabled}
>
{buttonTitle}
</LinkButton>
</ButtonEl>
);
return <CallToActionCard className={ctaStyle} message={title} footer={footer()} callToActionElement={ctaElement} />;