-
Notifications
You must be signed in to change notification settings - Fork 28
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
Remove jQuery from Instructor List (Fix #777 Part 1/2) #806
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5e3703
slight cleanup
harsh183 012d776
add User Event to the project
harsh183 1ec1548
test cases for instructor list
harsh183 cd7f52e
cleanup number of instructor check
harsh183 ab62e43
replace jquery from insturctor list with react state
harsh183 6b686ee
make linter happy
harsh183 5e45ad2
remove comment
harsh183 cb9d595
Merge branch 'staging' into hd/remove-jquery
angrave 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from "@testing-library/user-event"; | ||
import * as KeyCode from 'keycode-js'; | ||
import InstructorList from './InstructorList'; | ||
|
||
describe('Instructor List', () => { | ||
const universityName = 'University of Test' | ||
const baseProps = { | ||
loading: false, | ||
currUni: { name: universityName, id: 0 }, | ||
onInactive: jest.fn() | ||
}; | ||
|
||
// All instructors have the same univeristy display in common | ||
const numberOfInstructors = () => screen.queryAllByText(`University: ${universityName}`).length | ||
|
||
test('it renders', () => { | ||
render(<InstructorList {...baseProps} instructors={[]} />); | ||
|
||
expect(numberOfInstructors()).toBe(0); | ||
}); | ||
|
||
// Note: only setting up fields we use for display, add more as needed | ||
const instructors = [ | ||
{ id: 0, firstName: "Harsh", lastName: "Deep", email: "harsh@example.com" }, | ||
{ id: 1, firstName: "Alan", email: "alan@example.com" }, | ||
{ id: 2, lastName: "Turing", email: "turing@example.com" }, | ||
] | ||
|
||
test('it shows all instructors', () => { | ||
render(<InstructorList {...baseProps} instructors={instructors} />); | ||
|
||
expect(numberOfInstructors()).toBe(3); | ||
|
||
expect(screen.getByText("Harsh Deep")).toBeVisible(); | ||
expect(screen.getByText("Alan")).toBeVisible(); | ||
expect(screen.getByText("Unknown Turing")).toBeVisible(); | ||
|
||
expect(screen.getByText("Email: harsh@example.com")).toBeVisible(); | ||
expect(screen.getByText("Email: alan@example.com")).toBeVisible(); | ||
expect(screen.getByText("Email: harsh@example.com")).toBeVisible(); | ||
}); | ||
|
||
test('it filters based on first, last and email and we can reset the filters', async () => { | ||
render(<InstructorList {...baseProps} instructors={instructors} />); | ||
|
||
const searchField = screen.getByLabelText("Search:"); | ||
const searchButton = screen.getByRole("button", { name: "search"}); | ||
const resetButton = screen.getByRole("button", { name: "Reset" }); | ||
|
||
// First Name | ||
await userEvent.type(searchField, "Harsh"); | ||
await userEvent.click(searchButton); | ||
|
||
expect(numberOfInstructors()).toBe(1); | ||
expect(screen.getByText("Harsh Deep")).toBeVisible(); | ||
|
||
// Last Name | ||
await userEvent.clear(searchField); | ||
await userEvent.type(searchField, "Turing"); | ||
await userEvent.click(searchButton); | ||
|
||
expect(numberOfInstructors()).toBe(1); | ||
expect(screen.getByText("Unknown Turing")).toBeVisible(); | ||
|
||
await userEvent.clear(searchField); | ||
await userEvent.type(searchField, "alan@example"); | ||
await userEvent.click(searchButton); | ||
|
||
expect(numberOfInstructors()).toBe(1); | ||
expect(screen.getByText("Alan")).toBeVisible(); | ||
|
||
// Reset | ||
await userEvent.click(resetButton); | ||
expect(searchField.value).toBe(""); | ||
expect(numberOfInstructors()).toBe(3); | ||
}); | ||
}); |
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
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.
@angrave if we want, we can make the search happen 'live' with every state change. That way we won't need to even hit enter or click the button now that we're not using
jQuery
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.
This can be a separate commit actually, I'll make this into a new issue so that this PR is fixed on just removing jquery.
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.
#807
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.
Sounds good.
@harsh183
FYI how to properly debounce a search in react-
https://www.alexhughes.dev/blog/settimeout-with-hooks/
https://dev.to/imforja/5-steps-to-perform-a-search-when-user-stops-typing-using-react-hooks-in-a-controlled-component-5edd