generated from openedx/frontend-template-application
-
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 pull request #12 from Pearson-Advance/vue/PADV-706
PADV-706 Add filters to instructors table
- Loading branch information
Showing
5 changed files
with
174 additions
and
4 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/features/Instructors/InstructorsFilters/_test_/index.test.jsx
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,81 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, act } from '@testing-library/react'; | ||
import InstructorsFilters from 'features/Instructors/InstructorsFilters'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
describe('InstructorsFilters Component', () => { | ||
test('call service when apply filters', async () => { | ||
const fetchData = jest.fn(); | ||
const resetPagination = jest.fn(); | ||
const { getByPlaceholderText, getByText } = render( | ||
<InstructorsFilters fetchData={fetchData} resetPagination={resetPagination} />, | ||
); | ||
|
||
const button = getByText('Filters'); | ||
await act(async () => { | ||
fireEvent.click(button); | ||
}); | ||
|
||
const nameInput = getByPlaceholderText('Enter Instructor Name'); | ||
const emailInput = getByPlaceholderText('Enter Instructor Email'); | ||
const classNameInput = getByPlaceholderText('Enter Class Name'); | ||
const buttonApplyFilters = getByText('Apply Filters'); | ||
|
||
expect(nameInput).toBeInTheDocument(); | ||
expect(emailInput).toBeInTheDocument(); | ||
expect(classNameInput).toBeInTheDocument(); | ||
|
||
fireEvent.change(nameInput, { target: { value: 'Name' } }); | ||
fireEvent.change(emailInput, { target: { value: '[email protected]' } }); | ||
fireEvent.change(classNameInput, { target: { value: 'CCX01' } }); | ||
|
||
expect(nameInput).toHaveValue('Name'); | ||
expect(emailInput).toHaveValue('[email protected]'); | ||
expect(classNameInput).toHaveValue('CCX01'); | ||
|
||
await act(async () => { | ||
fireEvent.click(buttonApplyFilters); | ||
}); | ||
|
||
expect(fetchData).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('clear filters', async () => { | ||
const fetchData = jest.fn(); | ||
const resetPagination = jest.fn(); | ||
const { getByPlaceholderText, getByText } = render( | ||
<InstructorsFilters fetchData={fetchData} resetPagination={resetPagination} />, | ||
); | ||
|
||
const button = getByText('Filters'); | ||
await act(async () => { | ||
fireEvent.click(button); | ||
}); | ||
|
||
const nameInput = getByPlaceholderText('Enter Instructor Name'); | ||
const emailInput = getByPlaceholderText('Enter Instructor Email'); | ||
const classNameInput = getByPlaceholderText('Enter Class Name'); | ||
const buttonClearFilters = getByText('Clear'); | ||
|
||
expect(nameInput).toBeInTheDocument(); | ||
expect(emailInput).toBeInTheDocument(); | ||
expect(classNameInput).toBeInTheDocument(); | ||
|
||
fireEvent.change(nameInput, { target: { value: 'Name' } }); | ||
fireEvent.change(emailInput, { target: { value: '[email protected]' } }); | ||
fireEvent.change(classNameInput, { target: { value: 'CCX01' } }); | ||
|
||
expect(nameInput).toHaveValue('Name'); | ||
expect(emailInput).toHaveValue('[email protected]'); | ||
expect(classNameInput).toHaveValue('CCX01'); | ||
|
||
await act(async () => { | ||
fireEvent.click(buttonClearFilters); | ||
}); | ||
|
||
expect(nameInput).toHaveValue(''); | ||
expect(emailInput).toHaveValue(''); | ||
expect(classNameInput).toHaveValue(''); | ||
expect(resetPagination).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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 React, { useState } from 'react'; | ||
import { | ||
DropdownButton, Form, Col, Button, | ||
} from '@edx/paragon'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const initialFilterFormValues = { | ||
instructorName: '', | ||
instructorEmail: '', | ||
ccxId: '', | ||
}; | ||
|
||
const InstructorsFilters = ({ fetchData, resetPagination }) => { | ||
const [filters, setFilters] = useState(initialFilterFormValues); | ||
|
||
const handleInputChange = (e) => { | ||
setFilters({ | ||
...filters, | ||
[e.target.name]: e.target.value.trim(), | ||
}); | ||
}; | ||
|
||
const handleApplyFilters = async () => { | ||
fetchData(filters); | ||
}; | ||
|
||
const handleCleanFilters = () => { | ||
setFilters(initialFilterFormValues); | ||
fetchData(); | ||
resetPagination(); | ||
}; | ||
|
||
return ( | ||
<DropdownButton title="Filters" variant="outline-primary"> | ||
<Form className="row justify-content-center px-3 py-2"> | ||
<Form.Group as={Col} className="mb-0"> | ||
<Form.Control | ||
type="text" | ||
floatingLabel="Name" | ||
name="instructorName" | ||
placeholder="Enter Instructor Name" | ||
value={filters.instructorName} | ||
onChange={handleInputChange} | ||
className="mb-3 mr-0" | ||
/> | ||
<Form.Control | ||
type="text" | ||
floatingLabel="Email" | ||
name="instructorEmail" | ||
placeholder="Enter Instructor Email" | ||
value={filters.instructorEmail} | ||
onChange={handleInputChange} | ||
className="mb-3 mr-0" | ||
/> | ||
<Form.Control | ||
type="text" | ||
floatingLabel="Class Name" | ||
name="ccxId" | ||
placeholder="Enter Class Name" | ||
value={filters.ccxId} | ||
onChange={handleInputChange} | ||
className="mb-4 mr-0" | ||
/> | ||
<div className="d-flex justify-content-between"> | ||
<Button onClick={handleApplyFilters}>Apply Filters</Button> | ||
<Button onClick={handleCleanFilters} variant="outline-primary">Clear</Button> | ||
</div> | ||
</Form.Group> | ||
</Form> | ||
</DropdownButton> | ||
); | ||
}; | ||
|
||
InstructorsFilters.propTypes = { | ||
fetchData: PropTypes.func.isRequired, | ||
resetPagination: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default InstructorsFilters; |
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