Skip to content
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

chore: Migrate deprecated Table to DataTable for PastWeekPassedLearner #1290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand All @@ -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 = [
[
Expand All @@ -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]);
});
Expand Down
Loading
Loading