-
-
Notifications
You must be signed in to change notification settings - Fork 886
'Visit' Button Feature Added to Joined Organizations Filter #3232
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
Changes from 18 commits
6c443e3
bbc126d
52ae3bb
63f3301
34335ce
74ac436
60df684
f9a2705
074bf17
480a62d
8a74256
072625f
e27de64
f610e62
6096a3d
f7b878f
a025661
a142f66
58a9cf7
d2150ba
050dfa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,49 +1,208 @@ | ||||||
import { vi } from 'vitest'; // Import vi from vitest instead of jest | ||||||
import React from 'react'; | ||||||
import { render, screen } from '@testing-library/react'; | ||||||
import { render, screen, fireEvent } from '@testing-library/react'; | ||||||
import { MockedProvider } from '@apollo/client/testing'; | ||||||
import { I18nextProvider } from 'react-i18next'; | ||||||
import OrganizationCard from './OrganizationCard'; | ||||||
import i18nForTest from 'utils/i18nForTest'; | ||||||
|
||||||
/** | ||||||
* This file contains unit tests for the `OrganizationCard` component. | ||||||
* | ||||||
* The tests cover: | ||||||
* | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix formatting to pass pipeline checks. Remove the whitespace from the empty line to resolve the Prettier formatting issue. - *
+ * 📝 Committable suggestion
Suggested change
🧰 Tools🪛 eslint[error] 13-13: Delete (prettier/prettier) 🪛 GitHub Actions: PR Workflow[warning] Code style issues found. File needs to be formatted using Prettier. |
||||||
* - Rendering the component with all provided props and verifying the correct display of text elements. | ||||||
* - Ensuring the component handles cases where certain props (like image) are not provided. | ||||||
* | ||||||
* These tests utilize the React Testing Library for rendering and querying DOM elements. | ||||||
*/ | ||||||
|
||||||
describe('Testing the Organization Card', () => { | ||||||
it('should render props and text elements test for the page component', () => { | ||||||
const props = { | ||||||
id: '123', | ||||||
image: 'https://via.placeholder.com/80', | ||||||
firstName: 'John', | ||||||
lastName: 'Doe', | ||||||
name: 'Sample', | ||||||
}; | ||||||
const mockNavigate = vi.fn(); // Use vitest.fn() instead of jest.fn() | ||||||
|
||||||
vi.mock('react-router-dom', async () => { | ||||||
const actual = await vi.importActual('react-router-dom'); | ||||||
return { | ||||||
...actual, | ||||||
BrowserRouter: ({ children }: { children: React.ReactNode }) => children, | ||||||
useNavigate: () => mockNavigate, | ||||||
}; | ||||||
}); | ||||||
|
||||||
const defaultProps = { | ||||||
id: '123', | ||||||
name: 'Test Organization', | ||||||
image: 'test-image.jpg', | ||||||
description: 'Test Description', | ||||||
admins: [{ id: '1' }], | ||||||
members: [{ id: '1' }, { id: '2' }], | ||||||
address: { | ||||||
city: 'Test City', | ||||||
countryCode: 'TC', | ||||||
line1: 'Test Line 1', | ||||||
postalCode: '12345', | ||||||
state: 'Test State', | ||||||
}, | ||||||
userRegistrationRequired: false, | ||||||
membershipRequests: [], | ||||||
}; | ||||||
|
||||||
describe('OrganizationCard', () => { | ||||||
beforeEach(() => { | ||||||
vi.clearAllMocks(); // Use vitest.clearAllMocks() instead of jest.clearAllMocks() | ||||||
}); | ||||||
|
||||||
test('renders organization card with image', () => { | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard {...defaultProps} membershipRequestStatus="" /> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
render(<OrganizationCard {...props} />); | ||||||
expect(screen.getByText(defaultProps.name)).toBeInTheDocument(); | ||||||
|
||||||
expect(screen.getByText(props.name)).toBeInTheDocument(); | ||||||
expect(screen.getByText(/Owner:/i)).toBeInTheDocument(); | ||||||
expect(screen.getByText(props.firstName)).toBeInTheDocument(); | ||||||
expect(screen.getByText(props.lastName)).toBeInTheDocument(); | ||||||
// Find the h6 element with className orgadmin | ||||||
const statsContainer = screen.getByText((content) => { | ||||||
const normalizedContent = content | ||||||
.toLowerCase() | ||||||
.replace(/\s+/g, ' ') | ||||||
.trim(); | ||||||
return ( | ||||||
normalizedContent.includes('admins') && | ||||||
normalizedContent.includes('members') | ||||||
); | ||||||
}); | ||||||
|
||||||
expect(statsContainer).toBeInTheDocument(); | ||||||
expect(statsContainer.textContent).toContain('1'); // Check for admin count | ||||||
expect(statsContainer.textContent).toContain('2'); // Check for member count | ||||||
expect(screen.getByRole('img')).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
it('Should render text elements when props value is not passed', () => { | ||||||
const props = { | ||||||
id: '123', | ||||||
test('renders organization card without image', () => { | ||||||
const propsWithoutImage = { | ||||||
...defaultProps, | ||||||
image: '', | ||||||
firstName: 'John', | ||||||
lastName: 'Doe', | ||||||
name: 'Sample', | ||||||
}; | ||||||
|
||||||
render(<OrganizationCard {...props} />); | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard {...propsWithoutImage} membershipRequestStatus="" /> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
expect(screen.getByTestId('emptyContainerForImage')).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
test('renders "Join Now" button when membershipRequestStatus is empty', () => { | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard {...defaultProps} membershipRequestStatus="" /> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
expect(screen.getByTestId('joinBtn')).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
test('renders "Visit" button when membershipRequestStatus is accepted', () => { | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard | ||||||
{...defaultProps} | ||||||
membershipRequestStatus="accepted" | ||||||
/> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
const visitButton = screen.getByTestId('manageBtn'); | ||||||
expect(visitButton).toBeInTheDocument(); | ||||||
|
||||||
fireEvent.click(visitButton); | ||||||
expect(mockNavigate).toHaveBeenCalledWith('/user/organization/123'); | ||||||
}); | ||||||
|
||||||
test('renders "Withdraw" button when membershipRequestStatus is pending', () => { | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard | ||||||
{...defaultProps} | ||||||
membershipRequestStatus="pending" | ||||||
/> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
expect(screen.getByTestId('withdrawBtn')).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
test('displays address when provided', () => { | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard {...defaultProps} membershipRequestStatus="" /> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
expect(screen.getByText(/Test City/i)).toBeInTheDocument(); | ||||||
expect(screen.getByText(/TC/i)).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
test('displays organization description', () => { | ||||||
render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard {...defaultProps} membershipRequestStatus="" /> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
|
||||||
expect(screen.getByText('Test Description')).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
test('displays correct button based on membership status', () => { | ||||||
// Test for empty status (Join Now button) | ||||||
const { rerender } = render( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard {...defaultProps} membershipRequestStatus="" /> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
expect(screen.getByTestId('joinBtn')).toBeInTheDocument(); | ||||||
|
||||||
// Test for accepted status (Visit button) | ||||||
rerender( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard | ||||||
{...defaultProps} | ||||||
membershipRequestStatus="accepted" | ||||||
/> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
expect(screen.getByTestId('manageBtn')).toBeInTheDocument(); | ||||||
|
||||||
expect(screen.getByText(props.name)).toBeInTheDocument(); | ||||||
expect(screen.getByText(/Owner:/i)).toBeInTheDocument(); | ||||||
expect(screen.getByText(props.firstName)).toBeInTheDocument(); | ||||||
expect(screen.getByText(props.lastName)).toBeInTheDocument(); | ||||||
// Test for pending status (Withdraw button) | ||||||
rerender( | ||||||
<MockedProvider> | ||||||
<I18nextProvider i18n={i18nForTest}> | ||||||
<OrganizationCard | ||||||
{...defaultProps} | ||||||
membershipRequestStatus="pending" | ||||||
/> | ||||||
</I18nextProvider> | ||||||
</MockedProvider>, | ||||||
); | ||||||
expect(screen.getByTestId('withdrawBtn')).toBeInTheDocument(); | ||||||
}); | ||||||
}); |
Uh oh!
There was an error while loading. Please reload this page.