Skip to content

Commit

Permalink
Merge pull request #443 from openedx/kiram15/ENT-9554
Browse files Browse the repository at this point in the history
fix: adding typing delay to associated users table
  • Loading branch information
kiram15 authored Jan 24, 2025
2 parents afe3e47 + f06d55b commit 62f3e60
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
62 changes: 57 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "12.1.4",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/react-table": "^7.7.2",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const EnterpriseCustomerUserDetail = ({
<Hyperlink
destination={iconLink}
key={user?.email}
data-testId="icon-hyperlink"
data-testid="icon-hyperlink"
target="_blank"
showLaunchIcon={false}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { renderHook } from '@testing-library/react-hooks';
import { waitFor } from '@testing-library/react';

import LmsApiService from '../../../../../data/services/EnterpriseApiService';
import useCustomerUsersTableData from '../useCustomerUsersTableData';

jest.mock('../../../../../data/services/EnterpriseApiService');
const TEST_ENTERPRISE_UUID = 'test-enterprise-uuid';

describe('useCustomerUsersTableData', () => {
it('should only search if user input is more than 3 characters', async () => {
const args = {
enterpriseUuid: TEST_ENTERPRISE_UUID,
};
const { result } = renderHook(() => useCustomerUsersTableData(args));
const { enterpriseUsersTableData } = result.current;
expect(enterpriseUsersTableData).toEqual({ itemCount: 0, pageCount: 0, results: [] });

// shouldn't fetch because its only 2 characters
const searchArgs1 = {
filters: [{ id: 'details', value: 'vi' }],
sortBy: [{}],
};
result.current.fetchEnterpriseUsersData(searchArgs1);
await waitFor(() => {
expect(LmsApiService.fetchEnterpriseCustomerUsers).not.toHaveBeenCalled();
});

const searchArgs2 = {
filters: [{ id: 'details', value: 'jinx' }],
sortBy: [{}],
};
result.current.fetchEnterpriseUsersData(searchArgs2);
await waitFor(() => {
expect(LmsApiService.fetchEnterpriseCustomerUsers).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const useCustomerUsersTableData = (enterpriseUuid) => {
try {
setIsLoading(true);
const options = {};

args.sortBy.filter((sort) => {
const { id, desc } = sort;
if (id === 'administrator') {
Expand Down Expand Up @@ -56,8 +55,11 @@ const useCustomerUsersTableData = (enterpriseUuid) => {
setIsLoading(false);
}
};

if (enterpriseUuid) {
fetch();
if (!args.filters.length || args.filters[0].value.length > 2) {
fetch();
}
}
}, [enterpriseUuid]);

Expand Down

0 comments on commit 62f3e60

Please sign in to comment.