Skip to content

Commit

Permalink
Merge pull request #49 from joshuaow91/WEB-21
Browse files Browse the repository at this point in the history
chore: added unit test for cards sections to verify correct content i…
  • Loading branch information
TheDThompsonDev authored Mar 17, 2024
2 parents 46c01c6 + 2374d02 commit 49d685e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/app/components/button/button.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { render, screen, fireEvent } from '@testing-library/react';
import Button from './Button';
import styles from './button.module.css';

jest.mock('./button.module.css', () => ({
button: 'button',
Expand Down Expand Up @@ -28,12 +27,6 @@ test('renders correctly with primary variant', () => {
expect(asFragment()).toMatchSnapshot();
});

// test('has the correct class when variant is primary', () => {
// render(<Button buttonText='Primary Button' variant='primary' />);
// const buttonElement = screen.getByTestId('button-primary');
// expect(buttonElement).toHaveStyle('background-color: #3c3db9');
// });

test('shows icon when showIcon is true', () => {
render(<Button buttonText='Button with Icon' showIcon />);
const iconElement = screen.getByTestId('button-icon');
Expand Down
42 changes: 42 additions & 0 deletions src/app/components/cardsSection/cards.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render, screen } from '@testing-library/react';
import CardsSection from './CardsSection';

describe('CardsSection', () => {
const labelMock = {
lblWorkshopsTitle: 'Workshop Title',
lblSupportTitle: 'Support Title',
lblCohortsTitle: 'Cohorts Title',
lblWorkshopsContent: 'Workshop Content',
lblSupportContent: 'Support Content',
lblCohortsContent: 'Cohorts Content',
btnTextMeetup: 'Join Meetup',
btnTextCommunity: 'Join Community',
btnTextCohort: 'Join Cohort',
meetupUrl: 'https://meetup.com',
communityUrl: 'https://community.com',
cohortUrl: 'https://cohort.com',
};

test('uses the correct href for each link', () => {
render(<CardsSection label={labelMock} />);
const meetupLink = screen.getByRole('link', { name: /join meetup/i });
const communityLink = screen.getByRole('link', { name: /join community/i });
const cohortLink = screen.getByRole('link', { name: /join cohort/i });
expect(meetupLink).toHaveAttribute('href', labelMock.meetupUrl);
expect(communityLink).toHaveAttribute('href', labelMock.communityUrl);
expect(cohortLink).toHaveAttribute('href', labelMock.cohortUrl);
});

test('passes the correct content to each card', () => {
render(<CardsSection label={labelMock} />);
expect(screen.getByText(labelMock.lblWorkshopsTitle)).toBeInTheDocument();
expect(screen.getByText(labelMock.lblWorkshopsContent)).toBeInTheDocument();
expect(screen.getByText(labelMock.btnTextMeetup)).toBeInTheDocument();
expect(screen.getByText(labelMock.lblSupportTitle)).toBeInTheDocument();
expect(screen.getByText(labelMock.lblSupportContent)).toBeInTheDocument();
expect(screen.getByText(labelMock.btnTextCommunity)).toBeInTheDocument();
expect(screen.getByText(labelMock.lblCohortsTitle)).toBeInTheDocument();
expect(screen.getByText(labelMock.lblCohortsContent)).toBeInTheDocument();
expect(screen.getByText(labelMock.btnTextCohort)).toBeInTheDocument();
});
});

0 comments on commit 49d685e

Please sign in to comment.