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.
- Loading branch information
Showing
16 changed files
with
297 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
import { getCoursesByInstitution } from 'features/Common/data/api'; | ||
|
||
jest.mock('@edx/frontend-platform/auth', () => ({ | ||
getAuthenticatedHttpClient: jest.fn(), | ||
})); | ||
|
||
jest.mock('@edx/frontend-platform', () => ({ | ||
getConfig: jest.fn(() => ({ | ||
LMS_BASE_URL: 'http://localhost:18000', | ||
COURSE_OPERATIONS_API_V2_BASE_URL: 'http://localhost:18000/pearson_course_operation/api/v2', | ||
})), | ||
})); | ||
|
||
describe('getCoursesByInstitution', () => { | ||
test('should call getAuthenticatedHttpClient with the correct parameters', () => { | ||
const httpClientMock = { | ||
get: jest.fn(), | ||
}; | ||
|
||
const institutionId = 1; | ||
|
||
getAuthenticatedHttpClient.mockReturnValue(httpClientMock); | ||
|
||
getCoursesByInstitution(institutionId); | ||
|
||
expect(getAuthenticatedHttpClient).toHaveBeenCalledTimes(1); | ||
expect(getAuthenticatedHttpClient).toHaveBeenCalledWith(); | ||
|
||
expect(httpClientMock.get).toHaveBeenCalledTimes(1); | ||
expect(httpClientMock.get).toHaveBeenCalledWith( | ||
'http://localhost:18000/pearson_course_operation/api/v2/courses/?institution_id=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,12 @@ | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
function getCoursesByInstitution(institutionId) { | ||
return getAuthenticatedHttpClient().get( | ||
`${getConfig().COURSE_OPERATIONS_API_V2_BASE_URL}/courses/?institution_id=${institutionId}`, | ||
); | ||
} | ||
|
||
export { | ||
getCoursesByInstitution, | ||
}; |
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 |
---|---|---|
|
@@ -11,27 +11,18 @@ describe('InstructorsFilters Component', () => { | |
<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'); | ||
const buttonApplyFilters = getByText('Apply'); | ||
|
||
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); | ||
|
@@ -47,35 +38,25 @@ describe('InstructorsFilters Component', () => { | |
<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'); | ||
const buttonClearFilters = getByText('Reset'); | ||
|
||
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); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
src/features/Instructors/InstructorsFilters/_test_/reducer.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,63 @@ | ||
import { | ||
FETCH_COURSES_DATA_FAILURE, | ||
FETCH_COURSES_DATA_REQUEST, | ||
FETCH_COURSES_DATA_SUCCESS, | ||
} from 'features/Instructors/actionTypes'; | ||
import { RequestStatus } from 'features/constants'; | ||
import reducer from 'features/Students/StudentsFilters/reducer'; | ||
|
||
describe('Student filter reducers', () => { | ||
const initialState = { | ||
courses: { | ||
data: [], | ||
status: RequestStatus.SUCCESS, | ||
error: null, | ||
}, | ||
}; | ||
|
||
test('should handle FETCH_COURSES_DATA_REQUEST', () => { | ||
const state = { | ||
...initialState, | ||
courses: { | ||
...initialState.courses, | ||
status: RequestStatus.LOADING, | ||
}, | ||
}; | ||
const action = { | ||
type: FETCH_COURSES_DATA_REQUEST, | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
|
||
test('should handle FETCH_COURSES_DATA_SUCCESS', () => { | ||
const state = { | ||
...initialState, | ||
courses: { | ||
...initialState.courses, | ||
status: RequestStatus.SUCCESS, | ||
data: [], | ||
}, | ||
}; | ||
const action = { | ||
type: FETCH_COURSES_DATA_SUCCESS, | ||
payload: [], | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
|
||
test('should handle FETCH_COURSES_DATA_FAILURE', () => { | ||
const state = { | ||
...initialState, | ||
courses: { | ||
...initialState.courses, | ||
status: RequestStatus.ERROR, | ||
error: '', | ||
}, | ||
}; | ||
const action = { | ||
type: FETCH_COURSES_DATA_FAILURE, | ||
payload: '', | ||
}; | ||
expect(reducer(state, action)).toEqual(state); | ||
}); | ||
}); |
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.