Skip to content

Commit

Permalink
Merge pull request #1430 from openedx/eahmadjaved/ENT-10020
Browse files Browse the repository at this point in the history
feat: update the groups dropdown filters data source to enterprise gr…
  • Loading branch information
jajjibhai008 authored Feb 25, 2025
2 parents 97f1445 + 54e9d02 commit da16b85
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 77 deletions.
6 changes: 3 additions & 3 deletions src/components/Admin/AdminSearchForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ class AdminSearchForm extends React.Component {
</option>
{groups.map(group => (
<option
value={group.enterprise_group_uuid}
key={group.enterprise_group_uuid}
value={group.uuid}
key={group.uuid}
>
{group.enterprise_group_name}
{group.name}
</option>
))}
</Form.Control>
Expand Down
84 changes: 14 additions & 70 deletions src/components/Admin/__snapshots__/Admin.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1686,11 +1686,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # cou
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -3348,11 +3344,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -5010,11 +5002,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders # of
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -6672,11 +6660,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders colla
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -8334,11 +8318,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders full
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -9996,11 +9976,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -11658,11 +11634,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders inact
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -13320,11 +13292,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders learn
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -14982,11 +14950,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders regis
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -16644,11 +16608,7 @@ exports[`<Admin /> renders correctly with dashboard analytics data renders top a
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -18355,11 +18315,7 @@ exports[`<Admin /> renders correctly with dashboard insights data renders dashbo
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -20017,11 +19973,7 @@ exports[`<Admin /> renders correctly with enterprise budgets data renders budget
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -21679,11 +21631,7 @@ exports[`<Admin /> renders correctly with enterprise groups data renders groups
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down Expand Up @@ -25153,11 +25101,7 @@ exports[`<Admin /> renders correctly with no dashboard insights data 1`] = `
>
All Groups
</option>
<option
value="7d6503dd-e40d-42b8-442b-37dd4c5450e3"
>
Test Group
</option>
<option />
</select>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { fetchPaginatedData } from '../../../../data/services/apiServiceUtils';
* @param {*} queryKey The queryKey from the associated `useQuery` call.
* @returns The enterprise group object
*/
const getAllFlexEnterpriseGroups = async ({ enterpriseId }) => {
export const getAllFlexEnterpriseGroups = async ({ enterpriseId }) => {
const { results } = await fetchPaginatedData(`${LmsApiService.enterpriseGroupListUrl}?enterprise_uuids=${enterpriseId}`);
const flexGroups = results.filter(result => result.groupType === 'flex');
return flexGroups;
Expand Down
6 changes: 3 additions & 3 deletions src/data/actions/enterpriseGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FETCH_ENTERPRISE_GROUPS_FAILURE,
CLEAR_ENTERPRISE_GROUPS,
} from '../constants/enterpriseGroups';
import EnterpriseDataApiService from '../services/EnterpriseDataApiService';
import { getAllFlexEnterpriseGroups } from '../../components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups';

const fetchEnterpriseGroupsRequest = () => ({ type: FETCH_ENTERPRISE_GROUPS_REQUEST });
const fetchEnterpriseGroupsSuccess = data => ({
Expand All @@ -20,9 +20,9 @@ const fetchEnterpriseGroupsFailure = error => ({
const fetchEnterpriseGroups = enterpriseId => (
(dispatch) => {
dispatch(fetchEnterpriseGroupsRequest());
return EnterpriseDataApiService.fetchEnterpriseGroups(enterpriseId)
return getAllFlexEnterpriseGroups({ enterpriseId })
.then((response) => {
dispatch(fetchEnterpriseGroupsSuccess(response.data));
dispatch(fetchEnterpriseGroupsSuccess(response));
})
.catch((error) => {
logError(error);
Expand Down
62 changes: 62 additions & 0 deletions src/data/actions/enterpriseGroups.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { fetchEnterpriseGroups, clearEnterpriseGroups } from './enterpriseGroups';
import { getAllFlexEnterpriseGroups } from '../../components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups';
import {
FETCH_ENTERPRISE_GROUPS_REQUEST,
FETCH_ENTERPRISE_GROUPS_SUCCESS,
FETCH_ENTERPRISE_GROUPS_FAILURE,
CLEAR_ENTERPRISE_GROUPS,
} from '../constants/enterpriseGroups';
import { axiosMock } from '../../setupTest';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

jest.mock('../../components/learner-credit-management/data/hooks/useAllFlexEnterpriseGroups');

describe('enterpriseGroups actions', () => {
afterEach(() => {
axiosMock.reset();
});

it('creates FETCH_ENTERPRISE_GROUPS_SUCCESS when fetching enterprise groups has been done', () => {
const enterpriseId = 'test-enterprise-id';
const mockResponse = { data: 'some data' };
getAllFlexEnterpriseGroups.mockResolvedValue(mockResponse);

const expectedActions = [
{ type: FETCH_ENTERPRISE_GROUPS_REQUEST },
{ type: FETCH_ENTERPRISE_GROUPS_SUCCESS, payload: { data: mockResponse } },
];
const store = mockStore({});

return store.dispatch(fetchEnterpriseGroups(enterpriseId)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});

it('creates FETCH_ENTERPRISE_GROUPS_FAILURE when fetching enterprise groups fails', () => {
const enterpriseId = 'test-enterprise-id';
const mockError = new Error('Failed to fetch');
getAllFlexEnterpriseGroups.mockRejectedValue(mockError);

const expectedActions = [
{ type: FETCH_ENTERPRISE_GROUPS_REQUEST },
{ type: FETCH_ENTERPRISE_GROUPS_FAILURE, payload: { error: mockError } },
];
const store = mockStore({});

return store.dispatch(fetchEnterpriseGroups(enterpriseId)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});

it('creates CLEAR_ENTERPRISE_GROUPS when clearing enterprise groups', () => {
const expectedAction = { type: CLEAR_ENTERPRISE_GROUPS };
const store = mockStore({});

store.dispatch(clearEnterpriseGroups());
expect(store.getActions()).toEqual([expectedAction]);
});
});

0 comments on commit da16b85

Please sign in to comment.