Skip to content

Commit

Permalink
chore: add support for test id in top nav
Browse files Browse the repository at this point in the history
  • Loading branch information
tewarig committed Dec 1, 2024
1 parent bc2811a commit 0c3ad46
Show file tree
Hide file tree
Showing 4 changed files with 794 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/blade/src/components/TopNav/TopNav.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeSize } from '~utils';
import { metaAttribute, MetaConstants } from '~utils/metaAttribute';
import type { StyledPropsBlade } from '~components/Box/styledProps';
import { componentZIndices } from '~utils/componentZIndices';
import type { DataAnalyticsAttribute } from '~utils/types';
import type { DataAnalyticsAttribute, TestID } from '~utils/types';
import { makeAnalyticsAttribute } from '~utils/makeAnalyticsAttribute';

const TOP_NAV_HEIGHT = size[56];
Expand All @@ -38,6 +38,7 @@ type TopNavProps = {
| 'zIndex'
| keyof DataAnalyticsAttribute
> &
TestID &
StyledPropsBlade;

const TopNav = ({ children, ...rest }: TopNavProps): React.ReactElement => {
Expand All @@ -54,7 +55,7 @@ const TopNav = ({ children, ...rest }: TopNavProps): React.ReactElement => {
height={makeSize(TOP_NAV_HEIGHT)}
zIndex={componentZIndices.topnav}
{...rest}
{...metaAttribute({ name: MetaConstants.TopNav })}
{...metaAttribute({ name: MetaConstants.TopNav, testID: rest.testID })}
{...makeAnalyticsAttribute(rest)}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ describe('TopNav', () => {
const { container } = renderWithTheme(<TopNavExample />);
expect(container).toMatchSnapshot();
});

test('it shpuld support adding test Id', () => {
const { container } = renderWithTheme(<TopNavExample />);
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { Text } from '~components/Typography';
const TopNavExample = (): React.ReactElement => {
return (
<Box height="100vh" backgroundColor="surface.background.gray.intense">
<TopNav backgroundColor="surface.background.gray.intense" data-analytics-topnav="demo">
<TopNav
backgroundColor="surface.background.gray.intense"
data-analytics-topnav="demo"
testID="demo"
>
<TopNavBrand>
<RazorpayLogo />
</TopNavBrand>
Expand Down
Loading

0 comments on commit 0c3ad46

Please sign in to comment.