Skip to content

Commit

Permalink
feat(quickLinks): updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisraymond-uchicago committed Dec 10, 2024
1 parent 1057f3a commit d2eb4e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/lib/Home/Components/QuickLinks/QuickLinks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ describe('Quicklinks Component', () => {
render(<QuickLinks />);
const element = screen.getByTestId('quick-links');
expect(element).toBeInTheDocument();
const resourceCallouts = screen.getAllByTestId('resource-callout');
expect(resourceCallouts.length).toBe(2);
});
});
42 changes: 33 additions & 9 deletions src/lib/Home/Components/ResourceCallout/ResourceCallout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import ResourceCallout from './ResourceCallout';

describe('ResourceCallout Component', () => {
test('renders the ResourceCallout component', () => {
render(<ResourceCallout />);
const element = screen.getByTestId('resource-callout');
expect(element).toBeInTheDocument();
import ResourceCallout from './ResourceCallout'; // Adjust the import path as needed

const mockData = {
title: 'Test Resources',
links: [
{ title: 'Select a Repository', href: 'https://www.testUrl.com' },
{
title: 'Register Your Study',
href: 'https://www.testUrl2.com',
},
],
};

describe('ResourceCallout', () => {
test('renders the ResourceCallout component correctly', () => {
render(<ResourceCallout resourceCalloutData={mockData} />);
const headerElement = screen.getByTestId('resource-callout-header');
expect(headerElement).toHaveTextContent('Test Resources');

const listItems = screen.getAllByRole('listitem');
expect(listItems.length).toBe(mockData.links.length);

mockData.links.forEach((linkData) => {
const link = screen.getByText(linkData.title);
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', linkData.href);
});
});

test('should render an arrow icon for each link', () => {
render(<ResourceCallout resourceCalloutData={mockData} />);
const icons = screen.getAllByTestId('icon-link-arrow');
expect(icons.length).toBe(mockData.links.length);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ResourceCallout: React.FC<resourceCalloutProps> = ({
{resourceCalloutData.links.map(
(resourceLink: resourceCalloutLink, i: number) => (
<li className="flex space-x-2 align-top pb-2" key={i}>
<span className="mr-1 pt-2">
<span className="mr-1 pt-2" data-testid="icon-link-arrow">
<IconLinkArrow />
</span>
<a
Expand Down

0 comments on commit d2eb4e3

Please sign in to comment.