Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [M3-8547] - Add unit tests for DocsLink component #11336

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11336-added-1732711112187.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

unit test cases for `DocsLink` component ([#11336](https://github.com/linode/manager/pull/11336))
45 changes: 45 additions & 0 deletions packages/manager/src/components/DocsLink/DocsLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import userEvent from '@testing-library/user-event';
import React from 'react';

import { sendHelpButtonClickEvent } from 'src/utilities/analytics/customEventAnalytics';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { DocsLink } from './DocsLink';

import type { DocsLinkProps } from './DocsLink';

vi.mock('src/utilities/analytics/customEventAnalytics', () => ({
sendHelpButtonClickEvent: vi.fn(),
}));

const mockLabel = 'Custom Doc Link Label';
const mockHref =
'https://techdocs.akamai.com/cloud-computing/docs/faqs-for-compute-instances';
const mockAnalyticsLabel = 'Label';

const defaultProps: DocsLinkProps = {
analyticsLabel: mockAnalyticsLabel,
href: mockHref,
label: mockLabel,
};

describe('DocsLink', () => {
it('should render the label', () => {
const { getByText } = renderWithTheme(<DocsLink {...defaultProps} />);
expect(getByText(mockLabel)).toBeVisible();
});

it('should allow user to click the label and redirect to the url', async () => {
const { getByRole } = renderWithTheme(<DocsLink {...defaultProps} />);
const link = getByRole('link', {
name: 'Custom Doc Link Label - link opens in a new tab',
});
expect(link).toBeInTheDocument();
await userEvent.click(link);
expect(sendHelpButtonClickEvent).toHaveBeenCalledTimes(1);
expect(sendHelpButtonClickEvent).toHaveBeenCalledWith(
mockHref,
mockAnalyticsLabel
);
});
});
Loading