Skip to content

Commit

Permalink
fix: adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
kiram15 committed Jan 24, 2025
1 parent 7a9423d commit f06d55b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 7 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

0 comments on commit f06d55b

Please sign in to comment.