-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/entire-codebase-validation
Merged
- Loading branch information
Showing
23 changed files
with
610 additions
and
310 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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,41 +1,51 @@ | ||
import React, { act } from 'react' | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import MainAccordion from '../components/MainAccordion' | ||
import { mockResearchOps } from '../resources/mockData' | ||
import { errorLoadingPostingsMessage } from '../resources/constants' | ||
import userEvent from '@testing-library/user-event' | ||
import MajorAccordion from '../components/MajorAccordion' | ||
import { mockMajorNoPosts, mockMajorOnePost } from '../resources/mockData' | ||
|
||
const mockSetSelectedPost = jest.fn() | ||
describe('MajorAccordion', () => { | ||
const mockSetSelectedPost = jest.fn() | ||
|
||
describe('MainAccordion', () => { | ||
test('renders correct number of departments and majors', () => { | ||
render(<MainAccordion | ||
postings={mockResearchOps} | ||
setSelectedPost={mockSetSelectedPost} | ||
isStudent | ||
/>) | ||
test('renders major name', () => { | ||
render( | ||
<MajorAccordion | ||
major={mockMajorNoPosts} | ||
numPosts={mockMajorNoPosts.posts.length} | ||
setSelectedPost={mockSetSelectedPost} | ||
isStudent | ||
/> | ||
) | ||
|
||
mockResearchOps.forEach(department => { | ||
const departmentHeader = screen.getByText(department.name) | ||
expect(departmentHeader).toBeInTheDocument() | ||
// Find the major name using test ID instead of text content | ||
// to account for multiple elements that include the name of the | ||
// major. | ||
const majorNameEl = screen.getByTestId('major-name') | ||
expect(majorNameEl).toHaveTextContent(mockMajorNoPosts.name) | ||
expect(screen.getByText('(0 opportunities)')).toBeInTheDocument() | ||
}) | ||
|
||
// Expand the accordion to check for majors | ||
act(() => { | ||
departmentHeader.click() | ||
}) | ||
test('renders posts for the major', async () => { | ||
render( | ||
<MajorAccordion | ||
major={mockMajorOnePost} | ||
numPosts={mockMajorOnePost.posts.length} | ||
setSelectedPost={mockSetSelectedPost} | ||
isStudent | ||
/> | ||
) | ||
|
||
department.majors.forEach(major => { | ||
expect(screen.getByText(major.name)).toBeInTheDocument() | ||
}) | ||
}) | ||
}) | ||
// Find the major name using test ID | ||
const majorNameEl = screen.getByTestId('major-name') | ||
expect(majorNameEl).toHaveTextContent(mockMajorOnePost.name) | ||
expect(screen.getByText('(1 opportunities)')).toBeInTheDocument() | ||
|
||
test('renders message if no students/research opportunities exist', () => { | ||
render(<MainAccordion | ||
postings={[]} | ||
setSelectedPost={mockSetSelectedPost} | ||
isStudent | ||
/>) | ||
// Find and click the accordion summary | ||
const accordionButton = screen.getByRole('button') | ||
await userEvent.click(accordionButton) | ||
|
||
expect(screen.getByText(errorLoadingPostingsMessage)).toBeInTheDocument() | ||
// After expansion, verify the post content | ||
const firstPostName = mockMajorOnePost.posts[0].name | ||
expect(screen.getByText(firstPostName)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains 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,35 +1,56 @@ | ||
import React, { act } from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import { render, screen, act, within } from '@testing-library/react' | ||
import MajorAccordion from '../components/MajorAccordion' | ||
import { mockMajorNoPosts, mockMajorOnePost } from '../resources/mockData' | ||
|
||
describe('MajorAccordion', () => { | ||
const mockSetSelectedPost = jest.fn() | ||
|
||
test('renders major name', () => { | ||
render(<MajorAccordion | ||
major={mockMajorNoPosts} | ||
setSelectedPost={mockSetSelectedPost} | ||
isStudent | ||
/>) | ||
describe('MajorAccordion', function () { | ||
function getMockSetSelectedPost () { | ||
return jest.fn() | ||
} | ||
|
||
it('renders major name with 0 opportunities', function () { | ||
render( | ||
<MajorAccordion | ||
major={mockMajorNoPosts} | ||
numPosts={mockMajorNoPosts.posts.length} | ||
setSelectedPost={getMockSetSelectedPost()} | ||
isStudent | ||
/> | ||
) | ||
expect(screen.getByText(mockMajorNoPosts.name)).toBeInTheDocument() | ||
expect(screen.getByText('(0 opportunities)')).toBeInTheDocument() | ||
}) | ||
|
||
test('renders posts for the major', () => { | ||
render(<MajorAccordion | ||
major={mockMajorOnePost} | ||
setSelectedPost={mockSetSelectedPost} | ||
isStudent | ||
/>) | ||
it('renders major name and posts when present', function () { | ||
render( | ||
<MajorAccordion | ||
major={mockMajorOnePost} | ||
numPosts={mockMajorOnePost.posts.length} | ||
setSelectedPost={getMockSetSelectedPost()} | ||
isStudent | ||
/> | ||
) | ||
|
||
// Find the expandable summary button | ||
const majorButton = screen.getByRole('button', { | ||
name: new RegExp(`${mockMajorOnePost.name}.*\\(${mockMajorOnePost.posts.length} opportunities\\)`, 'i') | ||
}) | ||
|
||
expect(majorButton).toBeInTheDocument() | ||
|
||
const majorHeader = screen.getByText(mockMajorOnePost.name) | ||
expect(majorHeader).toBeInTheDocument() | ||
// Check for the major name within the summary (button) | ||
expect(within(majorButton).getByText(mockMajorOnePost.name)).toBeInTheDocument() | ||
|
||
// Expand the accordion to check for posts | ||
// Expand the accordion | ||
act(() => { | ||
majorHeader.click() | ||
expect(screen.getByText(mockMajorOnePost.posts[0].name)).toBeInTheDocument() // refer to post[0] because there is only one post in this mock data | ||
majorButton.click() | ||
}) | ||
|
||
// After expansion, find the region and check for the post name | ||
const accordionRegion = screen.getByRole('region') | ||
expect(accordionRegion).toBeInTheDocument() | ||
|
||
const postName = mockMajorOnePost.posts[0].name | ||
expect(within(accordionRegion).getByText(postName)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains 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 |
---|---|---|
|
@@ -37,7 +37,8 @@ describe('PostDialog Component', () => { | |
|
||
// Faculty | ||
expect(screen.getByText('Faculty:')).toBeInTheDocument() | ||
expect(screen.getByText('John Doe ([email protected])')).toBeInTheDocument() | ||
expect(screen.getByText('John Doe')).toBeInTheDocument() | ||
expect(screen.getByText('[email protected]')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the close button and triggers onClose when clicked', () => { | ||
|
Oops, something went wrong.