diff --git a/src/users/UserPage.test.jsx b/src/users/UserPage.test.jsx index c51a0c39c..af1df399f 100644 --- a/src/users/UserPage.test.jsx +++ b/src/users/UserPage.test.jsx @@ -54,6 +54,17 @@ describe('User Page', () => { throw error; }); }; + it('when user identifier is empty', () => { + const emptyUsername = ''; + location.search = `?username=${emptyUsername}`; + const wrapper = mount(); + + 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}`; @@ -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 () => { diff --git a/src/users/enrollments/EnrollmentForm.test.jsx b/src/users/enrollments/EnrollmentForm.test.jsx index df5015945..9bf615728 100644 --- a/src/users/enrollments/EnrollmentForm.test.jsx +++ b/src/users/enrollments/EnrollmentForm.test.jsx @@ -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); diff --git a/src/users/enrollments/Enrollments.test.jsx b/src/users/enrollments/Enrollments.test.jsx index 7bd688f14..68421d317 100644 --- a/src/users/enrollments/Enrollments.test.jsx +++ b/src/users/enrollments/Enrollments.test.jsx @@ -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); + }); + }); }); diff --git a/src/users/entitlements/CreateEntitlementForm.test.jsx b/src/users/entitlements/CreateEntitlementForm.test.jsx index cdb034b29..97dd3859c 100644 --- a/src/users/entitlements/CreateEntitlementForm.test.jsx +++ b/src/users/entitlements/CreateEntitlementForm.test.jsx @@ -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(); diff --git a/src/users/entitlements/Entitlements.test.jsx b/src/users/entitlements/Entitlements.test.jsx index 58c8484d9..48bd11ccb 100644 --- a/src/users/entitlements/Entitlements.test.jsx +++ b/src/users/entitlements/Entitlements.test.jsx @@ -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(); const tableRowsLengths = [2, 0]; diff --git a/src/users/licenses/Licenses.jsx b/src/users/licenses/Licenses.jsx index 8b6b23cb6..2f7493137 100644 --- a/src/users/licenses/Licenses.jsx +++ b/src/users/licenses/Licenses.jsx @@ -114,7 +114,6 @@ export default function Licenses({ )} columns={columns} tableSortable - defaultSortedColumn="status" defaultSortDirection="desc" /> diff --git a/src/users/licenses/Licenses.test.jsx b/src/users/licenses/Licenses.test.jsx index b0695cd3c..767291325 100644 --- a/src/users/licenses/Licenses.test.jsx +++ b/src/users/licenses/Licenses.test.jsx @@ -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'); diff --git a/src/utils/index.test.js b/src/utils/index.test.js index 5b57ab7f7..8ccb208e2 100644 --- a/src/utils/index.test.js +++ b/src/utils/index.test.js @@ -1,4 +1,6 @@ -import { isEmail, isValidUsername, formatDate } from './index'; +import { + isEmail, isValidUsername, formatDate, sort, +} from './index'; describe('Test Utils', () => { describe('test user identifier', () => { @@ -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); + }); + }); });