-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Full Coverage for RecurringEventVolunteerModal #4882
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
Merged
palisadoes
merged 3 commits into
PalisadoesFoundation:develop
from
rawadhossain:fix/RecurringEventVolunteerModal
Nov 28, 2025
Merged
Changes from 1 commit
Commits
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
151 changes: 151 additions & 0 deletions
151
src/screens/UserPortal/Volunteer/UpcomingEvents/RecurringEventVolunteerModal.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 |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import React from 'react'; | ||
| import { describe, test, expect, vi, beforeEach } from 'vitest'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import RecurringEventVolunteerModal from './RecurringEventVolunteerModal'; | ||
|
|
||
| const defaultProps = { | ||
| show: true, | ||
| onHide: vi.fn(), | ||
| eventName: 'Weekly Cleanup', | ||
| eventDate: '2024-01-15', | ||
| onSelectSeries: vi.fn(), | ||
| onSelectInstance: vi.fn(), | ||
| }; | ||
|
|
||
| describe('RecurringEventVolunteerModal', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('renders modal with individual volunteering title, description and option texts', () => { | ||
| render(<RecurringEventVolunteerModal {...defaultProps} />); | ||
|
|
||
| // Modal exists | ||
| expect(screen.getByTestId('recurringEventModal')).toBeInTheDocument(); | ||
|
|
||
| // Title for individual volunteering | ||
| expect( | ||
| screen.getByText(`Volunteer for ${defaultProps.eventName}`), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Main description (individual branch) | ||
| expect( | ||
| screen.getByText( | ||
| 'Would you like to volunteer for the entire series or just this instance?', | ||
| ), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Series option description (individual branch) | ||
| expect( | ||
| screen.getByText( | ||
| 'You will be volunteering for all events in this recurring series', | ||
| ), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Instance option description (individual branch, with formatted date) | ||
| const formattedDate = new Date(defaultProps.eventDate).toLocaleDateString(); | ||
| expect( | ||
| screen.getByText( | ||
| `You will only be volunteering for the event on ${formattedDate}`, | ||
| ), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Default selection should be "series" | ||
| const seriesRadio = screen.getByTestId('volunteerForSeriesOption'); | ||
| const instanceRadio = screen.getByTestId('volunteerForInstanceOption'); | ||
| expect(seriesRadio).toBeChecked(); | ||
| expect(instanceRadio).not.toBeChecked(); | ||
| }); | ||
|
|
||
| test('renders group volunteering title, description and option texts when isForGroup is true', () => { | ||
| const groupName = 'Cleanup Crew'; | ||
| render( | ||
| <RecurringEventVolunteerModal | ||
| {...defaultProps} | ||
| isForGroup={true} | ||
| groupName={groupName} | ||
| />, | ||
| ); | ||
|
|
||
| // Title for group volunteering | ||
| expect( | ||
| screen.getByText(`Join ${groupName} - ${defaultProps.eventName}`), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Main description (group branch) | ||
| expect( | ||
| screen.getByText( | ||
| `Would you like to join "${groupName}" for the entire series or just this instance?`, | ||
| ), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Series option description (group branch) | ||
| expect( | ||
| screen.getByText( | ||
| 'You will join this group for all events in the recurring series', | ||
| ), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| // Instance option description (group branch, with formatted date) | ||
| const formattedDate = new Date(defaultProps.eventDate).toLocaleDateString(); | ||
| expect( | ||
| screen.getByText( | ||
| `You will join this group only for the event on ${formattedDate}`, | ||
| ), | ||
| ).toBeInTheDocument(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test('allows switching between instance and series options (covers both onChange handlers)', () => { | ||
| render(<RecurringEventVolunteerModal {...defaultProps} />); | ||
|
|
||
| const seriesRadio = screen.getByTestId('volunteerForSeriesOption'); | ||
| const instanceRadio = screen.getByTestId('volunteerForInstanceOption'); | ||
|
|
||
| // Default is series | ||
| expect(seriesRadio).toBeChecked(); | ||
| expect(instanceRadio).not.toBeChecked(); | ||
|
|
||
| // Switch to instance | ||
| fireEvent.click(instanceRadio); | ||
| expect(instanceRadio).toBeChecked(); | ||
| expect(seriesRadio).not.toBeChecked(); | ||
|
|
||
| // Switch back to series (exercises the series onChange handler branch) | ||
| fireEvent.click(seriesRadio); | ||
| expect(seriesRadio).toBeChecked(); | ||
| expect(instanceRadio).not.toBeChecked(); | ||
| }); | ||
|
|
||
| test('submit triggers onSelectSeries when "series" option is selected', () => { | ||
| render(<RecurringEventVolunteerModal {...defaultProps} />); | ||
|
|
||
| // Series is selected by default | ||
| const submitBtn = screen.getByTestId('submitVolunteerBtn'); | ||
| fireEvent.click(submitBtn); | ||
|
|
||
| expect(defaultProps.onSelectSeries).toHaveBeenCalledTimes(1); | ||
| expect(defaultProps.onSelectInstance).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('submit triggers onSelectInstance when "instance" option is selected', () => { | ||
| render(<RecurringEventVolunteerModal {...defaultProps} />); | ||
|
|
||
| const instanceRadio = screen.getByTestId('volunteerForInstanceOption'); | ||
| const submitBtn = screen.getByTestId('submitVolunteerBtn'); | ||
|
|
||
| // Change selection to instance | ||
| fireEvent.click(instanceRadio); | ||
| fireEvent.click(submitBtn); | ||
|
|
||
| expect(defaultProps.onSelectInstance).toHaveBeenCalledTimes(1); | ||
| expect(defaultProps.onSelectSeries).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('cancel button calls onHide', () => { | ||
| render(<RecurringEventVolunteerModal {...defaultProps} />); | ||
|
|
||
| fireEvent.click(screen.getByText('Cancel')); | ||
|
rawadhossain marked this conversation as resolved.
|
||
|
|
||
| expect(defaultProps.onHide).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.