Skip to content
Closed
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
6 changes: 4 additions & 2 deletions playwright-tests/tests/becomeAMentee.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { HomePage } from '@pages/home.page';
import { MentorshipPage } from '@pages/mentorship.page';

test('Validate "Become a Mentee" section and Find a Mentor button', async ({
page, mentorshipPage, homePage
page,
mentorshipPage,
homePage,
}) => {
// Navigate to Mentorship page
await page.goto('/mentorship');
Expand All @@ -22,7 +24,7 @@ test('Validate "Become a Mentee" section and Find a Mentor button', async ({
];

await expect(mentorshipPage.menteeListItems).toHaveText(items);

await homePage.findMentorButton.click();
await expect(page).toHaveURL(/\/mentorship\/mentors/);
});
3 changes: 3 additions & 0 deletions src/components/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type LinkButtonProps = {
small?: boolean;
children: React.ReactNode;
'data-testid'?: string;
disabled?: boolean;
};

export const LinkButton = ({
Expand All @@ -16,6 +17,7 @@ export const LinkButton = ({
small,
children,
'data-testid': dataTestId,
disabled = false,
}: LinkButtonProps) => {
const isExternal = href.startsWith('https');

Expand Down Expand Up @@ -59,6 +61,7 @@ export const LinkButton = ({
fontSize: small ? '0.8rem' : '1rem',
padding: small ? '7px 16px' : '10px 32px',
}}
disabled={disabled}
>
{children}
</Button>
Expand Down
2 changes: 2 additions & 0 deletions src/components/MentorProfileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useState } from 'react';
import { LinkButton } from '@components';
import { useIsMobile } from '@utils/theme-utils';
import { Mentor, Network } from '@utils/types';
import { IS_REGISTRATION_OPEN } from 'utils/mentorshipConstants';

type MentorProfileCardProps = {
mentor: Mentor;
Expand Down Expand Up @@ -130,6 +131,7 @@ export const MentorProfileCard: React.FC<MentorProfileCardProps> = ({
href={`/mentorship/mentee-registration?id=${mentor.id}`}
reversed
small
disabled={!IS_REGISTRATION_OPEN}
>
Apply for this mentor{' '}
</LinkButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
},
};

// Mutable flag so individual tests can override the registration state
let mockIsRegistrationOpen = false;

jest.mock('../../utils/mentorshipConstants', () => ({
...jest.requireActual('../../utils/mentorshipConstants'),
get IS_REGISTRATION_OPEN() {
return mockIsRegistrationOpen;
},
}));

describe('MentorProfileCard', () => {
it('renders mentor basic info', () => {
render(<MentorProfileCard mentor={mockMentor} />);
Expand Down Expand Up @@ -112,7 +122,7 @@
fireEvent.click(screen.getByText('Reviews'));
expect(screen.getByText('Great mentor!')).toBeInTheDocument();
// Check for star icons (5 stars)
expect(screen.getAllByTestId('StarIcon').length).toBe(5);

Check warning on line 125 in src/components/__tests__/MentorsProfileCard.test.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer a more specific assertion instead of this generic one, e.g. "expect(screen.getAllByTestId('StarIcon')).toHaveLength(5)".

See more on https://sonarcloud.io/project/issues?id=Women-Coding-Community_wcc-frontend&issues=AZ8gyEHbMAuTQp1iREoe&open=AZ8gyEHbMAuTQp1iREoe&pullRequest=294
});

it('renders the Apply for this mentor button', () => {
Expand All @@ -121,4 +131,10 @@
screen.getByRole('link', { name: /Apply for this mentor/i }),
).toBeInTheDocument();
});

it('disables the Apply for this mentor button when registration is closed', () => {

Check failure on line 135 in src/components/__tests__/MentorsProfileCard.test.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add at least one assertion to this test case.

See more on https://sonarcloud.io/project/issues?id=Women-Coding-Community_wcc-frontend&issues=AZ8gyEHbMAuTQp1iREof&open=AZ8gyEHbMAuTQp1iREof&pullRequest=294
render(<MentorProfileCard mentor={mockMentor} />);
expect(screen.getByRole('link', { name: /Apply for this mentor/i }))
.toBeDisabled;
});
});