Skip to content

Commit f4300ce

Browse files
committed
fix: adding test
1 parent 7a9423d commit f4300ce

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
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
@@ -40,6 +40,7 @@
4040
"@fortawesome/free-solid-svg-icons": "5.15.1",
4141
"@fortawesome/react-fontawesome": "^0.1.14",
4242
"@openedx/paragon": "21.13.1",
43+
"@testing-library/react-hooks": "^8.0.1",
4344
"axios": "^1.7.7",
4445
"babel-polyfill": "6.26.0",
4546
"classnames": "2.2.6",

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: 0 additions & 1 deletion
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') {

0 commit comments

Comments
 (0)