-
-
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
Closed
gkbishnoi07
wants to merge
21
commits into
PalisadoesFoundation:develop-postgres
from
gkbishnoi07:button-changes
Closed
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6c443e3
Implemented a 'Visit' button for the Joined Organizations filter in t…
bbc126d
fix: resolved test failure for 'Visit' button feature
52ae3bb
fix: resolved all issues
63f3301
fix: resolved all failed test cases
34335ce
implemented a 'Visit' button for the Joined Organizations filter in t…
74ac436
fix: failed test
60df684
fix: resolved all failed test cases
f9a2705
fixing latest failed test cases
074bf17
check formatting test
480a62d
check formatting test
8a74256
resolved presented issues
072625f
resolved presented issues
e27de64
resolved presented issues
f610e62
resolved presented issues
6096a3d
resolved presented issues
f7b878f
resolved eslint issues
a025661
resolved eslint issues
a142f66
resolved eslint issues
58a9cf7
resolved eslint issues
d2150ba
resolved eslint issues
050dfa2
Your commit message
gkbishnoi07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
211 changes: 185 additions & 26 deletions
211
src/components/OrganizationCard/OrganizationCard.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
* | ||
* - 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(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
🧰 Tools
🪛 eslint
[error] 13-13: Delete
·
(prettier/prettier)
🪛 GitHub Actions: PR Workflow
[warning] Code style issues found. File needs to be formatted using Prettier.