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

Unit Test Case for useInferenceServices #2340

Merged
merged 2 commits into from
Jan 22, 2024

Conversation

uidoyen
Copy link
Contributor

@uidoyen uidoyen commented Jan 16, 2024

Closes: RHOAIENG-1852

Description

Unit test case for: frontend/src/pages/modelServing/useInferenceServices.ts

How Has This Been Tested?

npm run test

Test Impact

Screenshot 2024-01-20 at 1 26 01 AM

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Commits have been squashed into descriptive, self-contained units of work (e.g. 'WIP' and 'Implements feedback' style messages have been removed)
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit tests & storybook for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change (find relevant UX in the SMEs section).

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

Comment on lines 60 to 69
k8sListResourceMock.mockReturnValue(Promise.reject('error'));
const renderResult = testHook(useInferenceServices)('namespace');
expect(k8sListResourceMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual(standardUseFetchState([], false));
expect(renderResult).hookToHaveUpdateCount(1);

// // Wait for the hook to handle the error
await renderResult.waitForNextUpdate();
expect(renderResult).hookToStrictEqual(
standardUseFetchState([], false, new Error('No Inference Services found.')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reject with an instance of Error and assert that error is returned.

Suggested change
k8sListResourceMock.mockReturnValue(Promise.reject('error'));
const renderResult = testHook(useInferenceServices)('namespace');
expect(k8sListResourceMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual(standardUseFetchState([], false));
expect(renderResult).hookToHaveUpdateCount(1);
// // Wait for the hook to handle the error
await renderResult.waitForNextUpdate();
expect(renderResult).hookToStrictEqual(
standardUseFetchState([], false, new Error('No Inference Services found.')),
k8sListResourceMock.mockReturnValue(Promise.reject(new Error('error')));
const renderResult = testHook(useInferenceServices)('namespace');
expect(k8sListResourceMock).toHaveBeenCalledTimes(1);
expect(renderResult).hookToStrictEqual(standardUseFetchState([], false));
expect(renderResult).hookToHaveUpdateCount(1);
// // Wait for the hook to handle the error
await renderResult.waitForNextUpdate();
expect(renderResult).hookToStrictEqual(
standardUseFetchState([], false, new Error('error')),

Comment on lines 16 to 18
return getInferenceServiceContext(namespace, LABEL_SELECTOR_DASHBOARD_RESOURCE);
return getInferenceServiceContext(namespace, LABEL_SELECTOR_DASHBOARD_RESOURCE).catch(() => {
throw new Error('No Inference Services found.');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change along with the change to the test that mocks the error thrown.

@christianvogt
Copy link
Contributor

@uidoyen please add another test for the missing code coverage. You can assert that k8sListResourceMock has not been called when the NotReadyError use case is encountered.

@uidoyen uidoyen force-pushed the RHOAIENG-1852 branch 3 times, most recently from 589b3a8 to 4232433 Compare January 19, 2024 20:09
@uidoyen
Copy link
Contributor Author

uidoyen commented Jan 19, 2024

@uidoyen please add another test for the missing code coverage. You can assert that k8sListResourceMock has not been called when the NotReadyError use case is encountered.

@christianvogt Updated the test case based on your comment as well as the latest hook update.

@christianvogt
Copy link
Contributor

@uidoyen you don't have a test case for when namespace is not provided as a param to the hook.

@uidoyen
Copy link
Contributor Author

uidoyen commented Jan 22, 2024

@christianvogt added test case when namespace isn't provided. Can you please check it again?

@christianvogt
Copy link
Contributor

/lgtm
/approve

Copy link
Contributor

openshift-ci bot commented Jan 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: christianvogt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 20c72b3 into opendatahub-io:main Jan 22, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants