Skip to content

Commit

Permalink
ENT-7820 Learner Credit table sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jono-booth committed Jan 5, 2024
1 parent f00e83f commit 9556c33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/* eslint-disable react/prop-types */
import { renderWithRouter } from '@edx/frontend-enterprise-utils';
import { screen, waitFor } from '@testing-library/react';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import { camelCaseObject } from '@edx/frontend-platform';
import { DashboardContext, initialStateValue } from '../../../testData/Dashboard';
import DashboardDataTable from '../DashboardDataTable';
import { sampleDataTableData } from '../../../testData/constants';
import SubsidyApiService from '../../../../data/services/SubsidyApiService'

Check failure on line 8 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon

// Mock the debounce function
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));

// Mock the subsidy list
const mockGetAllSubsidiesData = sampleDataTableData(10);
jest.mock('../../../../data/services/SubsidyApiService', () => ({
getAllSubsidies: () => Promise.resolve({
data: mockGetAllSubsidiesData,
}),
}));
const apiMock = jest
.spyOn(SubsidyApiService, 'getAllSubsidies')
.mockImplementation(() => Promise.resolve({ data: mockGetAllSubsidiesData }));

// Mock the enterprise customers list
const mockCustomerData = camelCaseObject(mockGetAllSubsidiesData).results.map((subsidy) => ({
Expand Down Expand Up @@ -47,3 +46,24 @@ describe('DashboardDatatable', () => {
await waitFor(() => expect(screen.getByText('Enterprise Customer 1')).toBeTruthy());
});
});

describe('DashboardDatatable SortBy', ()=> {

Check failure on line 50 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing space before =>
it('sorts the data asc and desc', async ()=> {

Check failure on line 51 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing space before =>
renderWithRouter(<DashboardDatatableWrapper />);
const tableHeader = screen.getByText('Start date');

fireEvent.click(tableHeader);
await waitFor(() => expect(apiMock).toHaveBeenCalledWith(
expect.objectContaining({
sortBy: 'active_datetime'

Check failure on line 58 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing trailing comma
})

Check failure on line 59 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing trailing comma
));

fireEvent.click(tableHeader);
await waitFor(() => expect(apiMock).toHaveBeenCalledWith(
expect.objectContaining({
sortBy: '-active_datetime'

Check failure on line 65 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing trailing comma
})

Check failure on line 66 in src/Configuration/Provisioning/DashboardDataTable/tests/DashboardDataTable.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing trailing comma
));
});
});
10 changes: 7 additions & 3 deletions src/Configuration/Provisioning/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import LmsApiService from '../../../data/services/EnterpriseApiService';
import SubsidyApiService from '../../../data/services/SubsidyApiService';
import { isValidOpportunityProduct } from '../../../utils';
import { PREDEFINED_QUERY_DISPLAY_NAMES } from './constants';
import snakeCase from 'lodash.snakecase';

Check failure on line 10 in src/Configuration/Provisioning/data/utils.js

View workflow job for this annotation

GitHub Actions / tests

`lodash.snakecase` import should occur before import of `./dayjs`

export const indexOnlyPropType = {
index: PropTypes.number.isRequired,
Expand Down Expand Up @@ -650,10 +651,13 @@ export function sortDataTableData({ sortBy }) {
if (!sortByObject) {
return null;
}
if (sortByObject.id === 'isActive') {
return sortByObject.desc ? '-expirationDatetime' : 'expirationDatetime';
let sortString = sortByObject.id;
if ( sortString === 'isActive') {

Check failure on line 655 in src/Configuration/Provisioning/data/utils.js

View workflow job for this annotation

GitHub Actions / tests

There should be no space after this paren
sortString = 'expirationDatetime';

Check failure on line 656 in src/Configuration/Provisioning/data/utils.js

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 4 spaces but found 5
}
return sortByObject.desc ? `-${sortByObject.id}` : sortByObject.id;
sortString = snakeCase(sortString);
sortString = sortByObject.desc ? `-${sortString}` : sortString;
return sortString;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/data/services/SubsidyApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SubsidyApiService {
const subsidiesURL = `${getConfig().SUBSIDY_BASE_URL}/api/v1/subsidies/`;
const optionalUrlParams = new URLSearchParams(snakeCaseObject({
pageSize,
sortBy: sortBy ? snakeCase(sortBy) : 'uuid',
sortBy: sortBy ? sortBy : 'uuid',
...filteredData,
})).toString();
return SubsidyApiService.apiClient().get(`${subsidiesURL}?page=${pageIndex}&${optionalUrlParams}`);
Expand Down

0 comments on commit 9556c33

Please sign in to comment.