Chore: add selector for items in the megamenu (#65633)

add selector for items in the megamenu
This commit is contained in:
Ashley Harrison
2023-03-30 16:57:08 +01:00
committed by GitHub
parent 31aadeaecd
commit ff96cd1342
2 changed files with 23 additions and 3 deletions

View File

@@ -247,6 +247,9 @@ export const Components = {
button: 'Reporting', button: 'Reporting',
}, },
}, },
NavMenu: {
item: 'data-testid Nav menu item',
},
NavToolbar: { NavToolbar: {
container: 'data-testid Nav toolbar', container: 'data-testid Nav toolbar',
}, },

View File

@@ -2,6 +2,7 @@ import { css, cx } from '@emotion/css';
import React from 'react'; import React from 'react';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2 } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { Icon, IconName, Link, useTheme2 } from '@grafana/ui'; import { Icon, IconName, Link, useTheme2 } from '@grafana/ui';
export interface Props { export interface Props {
@@ -31,7 +32,11 @@ export function NavBarMenuItem({ children, icon, isActive, isChild, onClick, tar
); );
let element = ( let element = (
<button className={cx(styles.button, styles.element)} onClick={onClick}> <button
data-testid={selectors.components.NavMenu.item}
className={cx(styles.button, styles.element)}
onClick={onClick}
>
{linkContent} {linkContent}
</button> </button>
); );
@@ -39,11 +44,23 @@ export function NavBarMenuItem({ children, icon, isActive, isChild, onClick, tar
if (url) { if (url) {
element = element =
!target && url.startsWith('/') ? ( !target && url.startsWith('/') ? (
<Link className={styles.element} href={url} target={target} onClick={onClick}> <Link
data-testid={selectors.components.NavMenu.item}
className={styles.element}
href={url}
target={target}
onClick={onClick}
>
{linkContent} {linkContent}
</Link> </Link>
) : ( ) : (
<a href={url} target={target} className={styles.element} onClick={onClick}> <a
data-testid={selectors.components.NavMenu.item}
href={url}
target={target}
className={styles.element}
onClick={onClick}
>
{linkContent} {linkContent}
</a> </a>
); );