-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate deprecated Table to DataTable for PastWeekPassedLearne…
…rsTable
- Loading branch information
1 parent
ec24029
commit 51acf35
Showing
5 changed files
with
450 additions
and
249 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 |
---|---|---|
|
@@ -8,46 +8,44 @@ import { IntlProvider } from '@edx/frontend-platform/i18n'; | |
import { mount } from 'enzyme'; | ||
|
||
import PastWeekPassedLearnersTable from '.'; | ||
import usePastWeekPassedLearners from './data/hooks/usePastWeekPassedLearners'; | ||
|
||
const enterpriseId = 'test-enterprise'; | ||
const mockStore = configureMockStore([thunk]); | ||
const store = mockStore({ | ||
portalConfiguration: { | ||
enterpriseId, | ||
}, | ||
table: { | ||
'completed-learners-week': { | ||
data: { | ||
count: 2, | ||
num_pages: 1, | ||
current_page: 1, | ||
results: [ | ||
{ | ||
id: 1, | ||
passed_date: '2018-09-23T16:27:34.690065Z', | ||
course_title: 'Dive into ReactJS', | ||
course_key: 'edX/ReactJS', | ||
user_email: '[email protected]', | ||
}, | ||
{ | ||
id: 5, | ||
passed_date: '2018-09-22T16:27:34.690065Z', | ||
course_title: 'Redux with ReactJS', | ||
course_key: 'edX/Redux_ReactJS', | ||
user_email: '[email protected]', | ||
}); | ||
|
||
}, | ||
], | ||
next: null, | ||
start: 0, | ||
previous: null, | ||
const mockUsePastWeekPassedLearners = { | ||
isLoading: false, | ||
pastWeekPassedLearners: { | ||
itemCount: 2, | ||
pageCount: 1, | ||
results: [ | ||
{ | ||
id: 1, | ||
passedDate: '2018-09-23T16:27:34.690065Z', | ||
courseTitle: 'Dive into ReactJS', | ||
courseKey: 'edX/ReactJS', | ||
userEmail: '[email protected]', | ||
}, | ||
{ | ||
id: 5, | ||
passedDate: '2018-09-22T16:27:34.690065Z', | ||
courseTitle: 'Redux with ReactJS', | ||
courseKey: 'edX/Redux_ReactJS', | ||
userEmail: '[email protected]', | ||
}, | ||
ordering: null, | ||
loading: false, | ||
error: null, | ||
}, | ||
], | ||
}, | ||
}); | ||
fetchPastWeekPassedLearners: jest.fn(), | ||
}; | ||
|
||
jest.mock('./data/hooks/usePastWeekPassedLearners', () => ( | ||
jest.fn().mockReturnValue({}) | ||
)); | ||
|
||
const PastWeekPassedLearnersWrapper = props => ( | ||
<MemoryRouter> | ||
|
@@ -62,7 +60,11 @@ const PastWeekPassedLearnersWrapper = props => ( | |
); | ||
|
||
describe('PastWeekPassedLearnersTable', () => { | ||
let wrapper; | ||
beforeEach(() => { | ||
usePastWeekPassedLearners.mockReturnValue(mockUsePastWeekPassedLearners); | ||
}); | ||
|
||
afterEach(() => jest.clearAllMocks()); | ||
|
||
it('renders table correctly', () => { | ||
const tree = renderer | ||
|
@@ -74,7 +76,6 @@ describe('PastWeekPassedLearnersTable', () => { | |
}); | ||
|
||
it('renders table with correct data', () => { | ||
const tableId = 'completed-learners-week'; | ||
const columnTitles = ['Email', 'Course Title', 'Passed Date']; | ||
const rowsData = [ | ||
[ | ||
|
@@ -89,23 +90,23 @@ describe('PastWeekPassedLearnersTable', () => { | |
], | ||
]; | ||
|
||
wrapper = mount(( | ||
const wrapper = mount(( | ||
<PastWeekPassedLearnersWrapper /> | ||
)); | ||
|
||
// Verify that table has correct number of columns | ||
expect(wrapper.find(`.${tableId} thead th`).length).toEqual(3); | ||
expect(wrapper.find('[role="table"] thead th').length).toEqual(3); | ||
|
||
// Verify only expected columns are shown | ||
wrapper.find(`.${tableId} thead th`).forEach((column, index) => { | ||
wrapper.find('[role="table"] thead th').forEach((column, index) => { | ||
expect(column.text()).toContain(columnTitles[index]); | ||
}); | ||
|
||
// Verify that table has correct number of rows | ||
expect(wrapper.find(`.${tableId} tbody tr`).length).toEqual(2); | ||
expect(wrapper.find('[role="table"] tbody tr').length).toEqual(2); | ||
|
||
// Verify each row in table has correct data | ||
wrapper.find(`.${tableId} tbody tr`).forEach((row, rowIndex) => { | ||
wrapper.find('[role="table"] tbody tr').forEach((row, rowIndex) => { | ||
row.find('td').forEach((cell, colIndex) => { | ||
expect(cell.text()).toEqual(rowsData[rowIndex][colIndex]); | ||
}); | ||
|
Oops, something went wrong.