-
-
Notifications
You must be signed in to change notification settings - Fork 652
card component enhanced #974
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 14 commits
1e8e1a7
6a15a66
b1b11fd
e1d9912
101a65d
63fe7aa
fcee7c1
a236501
d2472b3
735ae39
9b98402
d6d47c1
5e51ee9
30db1ca
7e3e27e
8c9f2a1
f19d93d
07b68ca
677f1da
6b3187d
02cf0df
77d2cd0
f21c6f0
673c359
93e2b57
3a37370
d0d4023
df24d38
1fd224a
3493b43
8e72351
1018a2b
801b11b
57b7272
88b7f2c
27b1476
33a6c04
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 |
|---|---|---|
|
|
@@ -3,11 +3,17 @@ import { mockContributeData } from '@unit/data/mockContributeData' | |
| import { fetchAlgoliaData } from 'api/fetchAlgoliaData' | ||
| import { render } from 'wrappers/testUtil' | ||
| import ContributePage from 'pages/Contribute' | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
|
|
||
| // Mock dependencies | ||
| jest.mock('api/fetchAlgoliaData', () => ({ | ||
| fetchAlgoliaData: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('@fortawesome/react-fontawesome', () => ({ | ||
| FontAwesomeIcon: jest.fn(() => null), | ||
| })) | ||
|
|
||
| jest.mock('components/Pagination', () => | ||
| jest.fn(({ currentPage, onPageChange, totalPages }) => | ||
| totalPages > 1 ? ( | ||
|
|
@@ -19,12 +25,19 @@ jest.mock('components/Pagination', () => | |
| ) | ||
|
|
||
| describe('Contribute Component', () => { | ||
| // Suppress console errors and warnings during tests | ||
| beforeEach(() => { | ||
| jest.spyOn(console, 'error').mockImplementation(() => {}) | ||
| jest.spyOn(console, 'warn').mockImplementation(() => {}) | ||
|
|
||
| // Reset mocks before each test | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue(mockContributeData) | ||
| ;(FontAwesomeIcon as jest.Mock).mockReturnValue(<div>Icon</div>) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| }) | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| jest.restoreAllMocks() | ||
| }) | ||
|
|
||
| test('renders skeleton initially', async () => { | ||
|
|
@@ -36,19 +49,22 @@ describe('Contribute Component', () => { | |
| }) | ||
|
|
||
| test('renders contribute data correctly', async () => { | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue({ | ||
| const mockIssuesData = { | ||
| ...mockContributeData, | ||
| hits: mockContributeData.issues, | ||
| totalPages: 1, | ||
| }) | ||
| } | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue(mockIssuesData) | ||
|
|
||
| render(<ContributePage />) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Contribution 1')).toBeInTheDocument() | ||
| }) | ||
| expect(screen.getByText('This is a summary of Contribution 1')).toBeInTheDocument() | ||
| const viewButton = screen.getByText('Read More') | ||
| expect(viewButton).toBeInTheDocument() | ||
|
|
||
|
Contributor
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 pipeline failures: trailing whitespace and missing newline. The pipeline is failing due to trailing whitespace on line 65 and a missing newline at the end of the file. These are simple code style issues that should be fixed. -
+And add a newline at the end of the file: -})
+})
+Also applies to: 283-283 |
||
| const readMoreButtons = screen.getAllByRole('button', { name: /read more/i }) | ||
| expect(readMoreButtons.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| test('displays "No issues found" when there are no issues', async () => { | ||
|
|
@@ -143,58 +159,70 @@ describe('Contribute Component', () => { | |
| render(<ContributePage />) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.queryByText('Read More')).not.toBeInTheDocument() | ||
| expect(screen.queryByRole('button', { name: /read more/i })).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| test('renders SubmitButton correctly', async () => { | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue({ | ||
| const mockIssuesData = { | ||
| ...mockContributeData, | ||
| hits: mockContributeData.issues, | ||
| totalPages: 1, | ||
| }) | ||
| } | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue(mockIssuesData) | ||
| render(<ContributePage />) | ||
|
|
||
| await waitFor(() => { | ||
| const readMoreButton = screen.getByText('Read More') | ||
| expect(readMoreButton).toBeInTheDocument() | ||
| const readMoreButtons = screen.getAllByRole('button', { name: /read more/i }) | ||
| expect(readMoreButtons.length).toBeGreaterThan(0) | ||
| }) | ||
| }) | ||
|
|
||
| test('opens modal when SubmitButton is clicked', async () => { | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue({ | ||
| const mockIssuesData = { | ||
| ...mockContributeData, | ||
| hits: mockContributeData.issues, | ||
| totalPages: 1, | ||
| }) | ||
| } | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue(mockIssuesData) | ||
|
|
||
| render(<ContributePage />) | ||
|
|
||
| await waitFor(() => { | ||
| const readMoreButton = screen.getByText('Read More') | ||
| fireEvent.click(readMoreButton) | ||
| const readMoreButtons = screen.getAllByRole('button', { name: /read more/i }) | ||
| expect(readMoreButtons.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| const readMoreButton = screen.getAllByRole('button', { name: /read more/i })[0] | ||
| fireEvent.click(readMoreButton) | ||
|
|
||
| await waitFor(() => { | ||
| const modalTitle = screen.getByText('Close') | ||
| expect(modalTitle).toBeInTheDocument() | ||
| const closeButton = screen.getByRole('button', { name: /close/i }) | ||
| expect(closeButton).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| test('closes modal when onClose is called', async () => { | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue({ | ||
| const mockIssuesData = { | ||
| ...mockContributeData, | ||
| hits: mockContributeData.issues, | ||
| totalPages: 1, | ||
| }) | ||
| } | ||
| ;(fetchAlgoliaData as jest.Mock).mockResolvedValue(mockIssuesData) | ||
|
|
||
| render(<ContributePage />) | ||
|
|
||
| await waitFor(() => { | ||
| const readMoreButton = screen.getByText('Read More') | ||
| fireEvent.click(readMoreButton) | ||
| const readMoreButtons = screen.getAllByRole('button', { name: /read more/i }) | ||
| expect(readMoreButtons.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| const readMoreButton = screen.getAllByRole('button', { name: /read more/i })[0] | ||
| fireEvent.click(readMoreButton) | ||
|
|
||
| await waitFor(() => { | ||
| const closeButton = screen.getByText('Close') | ||
| const closeButton = screen.getByRole('button', { name: /close/i }) | ||
| expect(closeButton).toBeInTheDocument() | ||
| fireEvent.click(closeButton) | ||
| }) | ||
|
|
||
|
|
@@ -218,12 +246,12 @@ describe('Contribute Component', () => { | |
|
|
||
| // Wait for both cards to be rendered | ||
| await waitFor(() => { | ||
| const readMoreButtons = screen.getAllByText('Read More') | ||
| const readMoreButtons = screen.getAllByRole('button', { name: /read more/i }) | ||
| expect(readMoreButtons).toHaveLength(2) | ||
| }) | ||
|
|
||
| // Click first card's Read More button | ||
| const readMoreButtons = screen.getAllByText('Read More') | ||
| const readMoreButtons = screen.getAllByRole('button', { name: /read more/i }) | ||
| fireEvent.click(readMoreButtons[0]) | ||
|
|
||
| // Verify first modal is open | ||
|
|
@@ -240,7 +268,7 @@ describe('Contribute Component', () => { | |
|
|
||
| // Click close button | ||
| await waitFor(() => { | ||
| const closeButton = screen.getByText('Close') | ||
| const closeButton = screen.getByRole('button', { name: /close/i }) | ||
| fireEvent.click(closeButton) | ||
| }) | ||
|
|
||
|
|
@@ -252,4 +280,4 @@ describe('Contribute Component', () => { | |
| expect(screen.getByText('Hint 2')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.