-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test case for useQueryRangeResourceData
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
frontend/src/api/prometheus/__tests__/useQueryRangeResourceData.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { TimeframeTitle } from '~/pages/modelServing/screens/types'; | ||
import useQueryRangeResourceData from '~/api/prometheus/useQueryRangeResourceData'; | ||
import { TimeframeStep, TimeframeTimeRange } from '~/pages/modelServing/screens/const'; | ||
import { testHook } from '~/__tests__/unit/testUtils/hooks'; | ||
import * as usePrometheusQueryRangeModule from '~/api/prometheus/usePrometheusQueryRange'; | ||
import { mockPrometheusQueryResponse } from '~/__mocks__/mockPrometheusQueryResponse'; | ||
|
||
describe('useQueryRangeResourceData', () => { | ||
const active = true; | ||
const query = 'testQuery'; | ||
const end = 123456; | ||
const timeframe: TimeframeTitle = TimeframeTitle.ONE_HOUR; | ||
const responsePredicate = jest.fn(); | ||
const namespace = 'testNamespace'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call usePrometheusQueryRange with correct arguments and restructure the returned data', async () => { | ||
const spy = jest.spyOn(usePrometheusQueryRangeModule, 'default'); | ||
const mockedResponse = { data: { result: mockPrometheusQueryResponse({}) } }; | ||
|
||
spy.mockReturnValue([ | ||
mockedResponse.data.result.data.result, | ||
true, | ||
undefined, | ||
expect.any(Function), | ||
false, | ||
]); | ||
|
||
const renderResult = testHook(useQueryRangeResourceData)( | ||
active, | ||
query, | ||
end, | ||
timeframe, | ||
responsePredicate, | ||
namespace, | ||
); | ||
|
||
expect(renderResult).hookToStrictEqual({ | ||
data: mockedResponse.data.result.data.result, | ||
loaded: true, | ||
error: undefined, | ||
refresh: expect.any(Function), | ||
pending: false, | ||
}); | ||
|
||
expect(renderResult).hookToHaveUpdateCount(1); | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
active, | ||
'/api/prometheus/serving', | ||
query, | ||
TimeframeTimeRange[timeframe], | ||
end, | ||
TimeframeStep[timeframe], | ||
responsePredicate, | ||
namespace, | ||
); | ||
|
||
// Restore the spy | ||
spy.mockRestore(); | ||
}); | ||
}); |