-
Notifications
You must be signed in to change notification settings - Fork 163
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
Added tests for MLMD hooks #2860
Added tests for MLMD hooks #2860
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2860 +/- ##
==========================================
+ Coverage 77.49% 78.73% +1.23%
==========================================
Files 1109 1101 -8
Lines 23394 23440 +46
Branches 5890 5907 +17
==========================================
+ Hits 18129 18455 +326
+ Misses 5265 4985 -280
... and 102 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
frontend/src/concepts/pipelines/apiHooks/mlmd/__tests__/useArtifactsFromMlmdContext.spec.ts
Outdated
Show resolved
Hide resolved
frontend/src/concepts/pipelines/apiHooks/mlmd/__tests__/useArtifactsFromMlmdContext.spec.ts
Outdated
Show resolved
Hide resolved
frontend/src/concepts/pipelines/apiHooks/mlmd/__tests__/useArtifactsFromMlmdContext.spec.ts
Outdated
Show resolved
Hide resolved
frontend/src/concepts/pipelines/apiHooks/mlmd/__tests__/useGetExecutionById.spec.ts
Outdated
Show resolved
Hide resolved
5b8bd4d
to
3954ecd
Compare
mockUseMlmdListContext.mockReturnValue({ | ||
pageToken: '', | ||
maxResultSize: 100, | ||
filterQuery: '', | ||
} as MlmdListContextProps); | ||
}); | ||
|
||
it('should fetch and return the artifacts list', async () => { | ||
mockGetArtifacts.mockResolvedValue({ | ||
getArtifactsList: () => mockArtifacts, | ||
getNextPageToken: () => 'next-page-token', | ||
} as GetArtifactsResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should assert that mockGetArtifacts
gets called with the correct parameters as defined in your list context.
const error = new Error('Cannot fetch events'); | ||
mockGetEventsByExecutionIDs.mockRejectedValue(error); | ||
|
||
const renderResult = testHook(useGetEventsByExecutionId)('1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odd that the param is of type string
but for useGetEventsByExecutionIds
it's of type number
. Why the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function expects a string. i just fixed the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's inconsistencies in the API types. That's something you should look into as part of another PR as you start to use the APIs more.
expect(renderResult.result.current).toStrictEqual( | ||
standardUseFetchState(mockEventsResponse, true), | ||
); | ||
expect(renderResult).hookToHaveUpdateCount(3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a warning that your hook is not receiving stable values. The update count jumps from 1 to 3.
The reason is because useGetEventsByExecutionId
creates a new array of numbers every time it is called. This new array is used a dependency within useGetEventsByExecutionIds
.
You need to use useMemo
on the new array.
mockUseMlmdListContext.mockReturnValue({ | ||
pageToken: '', | ||
maxResultSize: 100, | ||
filterQuery: '', | ||
} as MlmdListContextProps); | ||
}); | ||
|
||
it('should fetch and return the executions list', async () => { | ||
mockGetExecutions.mockResolvedValue({ | ||
getExecutionsList: () => mockExecutions, | ||
getNextPageToken: () => 'next-page-token', | ||
} as GetExecutionsResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as earlier. You should assert mockGetExecutions
gets called with the values coming from the mlmd list context.
it('should return an empty array if no events have artifact IDs', async () => { | ||
const renderResult = testHook(useGetLinkedArtifactsByEvents)([]); | ||
|
||
expect(renderResult.result.current).toStrictEqual(standardUseFetchState([])); | ||
expect(renderResult).hookToHaveUpdateCount(1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to wait for an update before you can assert the final value when using useFetchState
frontend/src/concepts/pipelines/apiHooks/mlmd/__tests__/useGetMlmdContextType.spec.ts
Show resolved
Hide resolved
frontend/src/concepts/pipelines/apiHooks/mlmd/__tests__/useMlmdContext.spec.ts
Show resolved
Hide resolved
}); | ||
|
||
it('should handle errors from getMlmdContext', async () => { | ||
const error = new Error('Cannot find specified context'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use a separate error message here just to not confuse with the same error that's defined in useMlmdContext
. Which also doesn't have a test case.
useMlmdContext: jest.fn(), | ||
})); | ||
|
||
describe('usePipelineRunMlmdContext', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering usePipelineRunMlmdContext
is just a wrapper on top of useMlmdContext
with the type set to MlmdContextTypes.RUN
, these test cases aren't very useful. In fact they stood out to me as being odd because they don't require waiting for an update since you've mocked the one call made to useMlmdContext
. Essentially all the tests do is test your mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will remove it
Refactor MlmdListContextProps to be exported fixes
3954ecd
to
bfb4845
Compare
@christianvogt addressed all comments |
/lgtm |
[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 |
closes: https://issues.redhat.com/browse/RHOAIENG-5510
Description
adds jest tests to all mlmd related hooks
How Has This Been Tested?
CI passes and make sure all mlmd hooks are covered
Test Impact
Adding coverage to mlmd hooks
Request review criteria:
Self checklist (all need to be checked):
If you have UI changes:
After the PR is posted & before it merges:
main