Skip to content

Commit 62f3e60

Browse files
authored
Merge pull request #443 from openedx/kiram15/ENT-9554
fix: adding typing delay to associated users table
2 parents afe3e47 + f06d55b commit 62f3e60

File tree

5 files changed

+101
-8
lines changed

5 files changed

+101
-8
lines changed

package-lock.json

Lines changed: 57 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@testing-library/dom": "^9.3.4",
6969
"@testing-library/jest-dom": "^5.17.0",
7070
"@testing-library/react": "12.1.4",
71+
"@testing-library/react-hooks": "^8.0.1",
7172
"@testing-library/user-event": "^14.5.2",
7273
"@types/react-table": "^7.7.2",
7374
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",

src/Configuration/Customers/CustomerDetailView/EnterpriseCustomerUserDetail.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const EnterpriseCustomerUserDetail = ({
1818
<Hyperlink
1919
destination={iconLink}
2020
key={user?.email}
21-
data-testId="icon-hyperlink"
21+
data-testid="icon-hyperlink"
2222
target="_blank"
2323
showLaunchIcon={false}
2424
>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { renderHook } from '@testing-library/react-hooks';
2+
import { waitFor } from '@testing-library/react';
3+
4+
import LmsApiService from '../../../../../data/services/EnterpriseApiService';
5+
import useCustomerUsersTableData from '../useCustomerUsersTableData';
6+
7+
jest.mock('../../../../../data/services/EnterpriseApiService');
8+
const TEST_ENTERPRISE_UUID = 'test-enterprise-uuid';
9+
10+
describe('useCustomerUsersTableData', () => {
11+
it('should only search if user input is more than 3 characters', async () => {
12+
const args = {
13+
enterpriseUuid: TEST_ENTERPRISE_UUID,
14+
};
15+
const { result } = renderHook(() => useCustomerUsersTableData(args));
16+
const { enterpriseUsersTableData } = result.current;
17+
expect(enterpriseUsersTableData).toEqual({ itemCount: 0, pageCount: 0, results: [] });
18+
19+
// shouldn't fetch because its only 2 characters
20+
const searchArgs1 = {
21+
filters: [{ id: 'details', value: 'vi' }],
22+
sortBy: [{}],
23+
};
24+
result.current.fetchEnterpriseUsersData(searchArgs1);
25+
await waitFor(() => {
26+
expect(LmsApiService.fetchEnterpriseCustomerUsers).not.toHaveBeenCalled();
27+
});
28+
29+
const searchArgs2 = {
30+
filters: [{ id: 'details', value: 'jinx' }],
31+
sortBy: [{}],
32+
};
33+
result.current.fetchEnterpriseUsersData(searchArgs2);
34+
await waitFor(() => {
35+
expect(LmsApiService.fetchEnterpriseCustomerUsers).toHaveBeenCalled();
36+
});
37+
});
38+
});

src/Configuration/Customers/data/hooks/useCustomerUsersTableData.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const useCustomerUsersTableData = (enterpriseUuid) => {
1919
try {
2020
setIsLoading(true);
2121
const options = {};
22-
2322
args.sortBy.filter((sort) => {
2423
const { id, desc } = sort;
2524
if (id === 'administrator') {
@@ -56,8 +55,11 @@ const useCustomerUsersTableData = (enterpriseUuid) => {
5655
setIsLoading(false);
5756
}
5857
};
58+
5959
if (enterpriseUuid) {
60-
fetch();
60+
if (!args.filters.length || args.filters[0].value.length > 2) {
61+
fetch();
62+
}
6163
}
6264
}, [enterpriseUuid]);
6365

0 commit comments

Comments
 (0)