Skip to content

Commit

Permalink
Merge pull request #113 from edx/aakbar/PROD-2354
Browse files Browse the repository at this point in the history
refactor: add test coverage to various files
  • Loading branch information
Ali-D-Akbar authored May 6, 2021
2 parents 19c28dd + 91a53af commit ae5888a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/users/UserPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ describe('User Page', () => {
throw error;
});
};
it('when user identifier is empty', () => {
const emptyUsername = '';
location.search = `?username=${emptyUsername}`;
const wrapper = mount(<UserPageWrapper location={location} />);

const searchInput = wrapper.find('input[name="userIdentifier"]');
const alert = wrapper.find('.alert');

expect(searchInput).toHaveLength(1);
expect(alert).toHaveLength(0);
});
it('when user identifier is invalid', () => {
const invalidUsername = 'invalid username';
location.search = `?username=${invalidUsername}`;
Expand Down Expand Up @@ -81,6 +92,7 @@ describe('User Page', () => {

const alert = wrapper.find('.alert');
expect(alert).toHaveLength(1);
expect(document.title).toEqual('Support Tools | edX');
expect(alert.text()).toEqual(expectedAlert);
});
it('when user email is not found', async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/users/enrollments/EnrollmentForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('Enrollment Change form', () => {
const apiMock = jest.spyOn(api, 'postEnrollmentChange').mockImplementationOnce(() => Promise.resolve({}));
expect(apiMock).toHaveBeenCalledTimes(0);

wrapper.find('select#reason').simulate('change', { target: { value: 'Other' } });
wrapper.find('select#mode').simulate('change', { target: { value: 'verified' } });
wrapper.find('textarea#comments').simulate('change', { target: { value: 'test mode change' } });
wrapper.find('button.btn-primary').simulate('click');
expect(apiMock).toHaveBeenCalledTimes(1);
Expand Down
13 changes: 13 additions & 0 deletions src/users/enrollments/Enrollments.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,17 @@ describe('Course Enrollments Listing', () => {
expect(sortButton.disabled).toBeFalsy();
});
});

it('Sorting Columns Button work correctly', () => {
const dataTable = wrapper.find('table.table');
const tableHeaders = dataTable.find('thead tr th');

tableHeaders.forEach(header => {
const sortButton = header.find('button.btn-header');
sortButton.simulate('click');
expect(wrapper.find('svg.fa-sort-down')).toHaveLength(1);
sortButton.simulate('click');
expect(wrapper.find('svg.fa-sort-up')).toHaveLength(1);
});
});
});
2 changes: 2 additions & 0 deletions src/users/entitlements/CreateEntitlementForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe('Create Entitlement Form', () => {
const apiMock = jest.spyOn(api, 'postEntitlement').mockImplementationOnce(() => Promise.resolve({}));
expect(apiMock).toHaveBeenCalledTimes(0);

wrapper.find('input#courseUuid').simulate('change', { target: { value: 'b4f19c72-784d-4110-a3ba-318666a7db1a' } });
wrapper.find('select#mode').simulate('change', { target: { value: 'professional' } });
wrapper.find('textarea#comments').simulate('change', { target: { value: 'creating new entitlement' } });
const submitButton = wrapper.find('button.btn-primary');
expect(submitButton.prop('disabled')).toBeFalsy();
Expand Down
22 changes: 22 additions & 0 deletions src/users/entitlements/Entitlements.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ describe('Entitlements Listing', () => {
expect(collapsible.text()).toEqual('Entitlements (0)');
});

it('Sorting Columns Button Enabled by default', () => {
const dataTable = wrapper.find('table.table');
const tableHeaders = dataTable.find('thead tr th');

tableHeaders.forEach(header => {
const sortButton = header.find('button.btn-header');
expect(sortButton.disabled).toBeFalsy();
});
});

it('Sorting Columns Button work correctly', () => {
const dataTable = wrapper.find('table.table').hostNodes();
const sortButtons = dataTable.find('thead tr th button.btn-header');

sortButtons.forEach(sortButton => {
sortButton.simulate('click');
expect(wrapper.find('svg.fa-sort-down')).toHaveLength(1);
sortButton.simulate('click');
expect(wrapper.find('svg.fa-sort-up')).toHaveLength(1);
});
});

it('Support Details data', () => {
wrapper = mount(<EntitlementsPageWrapper {...entitlementsData} />);
const tableRowsLengths = [2, 0];
Expand Down
1 change: 0 additions & 1 deletion src/users/licenses/Licenses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export default function Licenses({
)}
columns={columns}
tableSortable
defaultSortedColumn="status"
defaultSortDirection="desc"
/>
</Collapsible>
Expand Down
13 changes: 13 additions & 0 deletions src/users/licenses/Licenses.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ describe('User Licenses Listing', () => {
});
});

it('Sorting Columns Button work correctly', () => {
const dataTable = wrapper.find('table.table');
const tableHeaders = dataTable.find('thead tr th');

tableHeaders.forEach(header => {
const sortButton = header.find('button.btn-header');
sortButton.simulate('click');
expect(wrapper.find('svg.fa-sort-down')).toHaveLength(1);
sortButton.simulate('click');
expect(wrapper.find('svg.fa-sort-up')).toHaveLength(1);
});
});

it('Table Header Lenght', () => {
const dataTable = wrapper.find('table.table');
const tableHeaders = dataTable.find('thead tr th');
Expand Down
29 changes: 28 additions & 1 deletion src/utils/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isEmail, isValidUsername, formatDate } from './index';
import {
isEmail, isValidUsername, formatDate, sort,
} from './index';

describe('Test Utils', () => {
describe('test user identifier', () => {
Expand Down Expand Up @@ -43,4 +45,29 @@ describe('Test Utils', () => {
expect(formatDate()).toEqual('N/A');
});
});

describe('Sort', () => {
const sortDict1 = {
name: 'string',
id: { value: 1 },
list: ['array value 1', 'array value 2'],
};
const sortDict2 = {
name: 'string2',
id: { value: 2 },
list: ['array value 3', 'array value 4'],
};
it('sorts in ascending order', () => {
expect(sort(sortDict1, sortDict2, 'id', 'asc')).toEqual(-1);
expect(sort(sortDict2, sortDict1, 'id', 'asc')).toEqual(1);
});
it('sorts in descending order', () => {
expect(sort(sortDict1, sortDict2, 'id', 'desc')).toEqual(1);
expect(sort(sortDict2, sortDict1, 'id', 'desc')).toEqual(-1);
});
it('when the values are equal', () => {
expect(sort(sortDict1, sortDict1, 'id', 'asc')).toEqual(0);
expect(sort(sortDict1, sortDict1, 'id', 'asc')).toEqual(0);
});
});
});

0 comments on commit ae5888a

Please sign in to comment.