Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding typing delay to associated users table #443

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading