Skip to content

Commit 0284060

Browse files
committed
Fix unit tests
1 parent 03117ac commit 0284060

File tree

4 files changed

+8
-58
lines changed

4 files changed

+8
-58
lines changed

web_ui/src/pages/annotator/annotation/layers/layers-factory.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('LayersFactory', () => {
5959
selectedMediaItem,
6060
selectedMediaItemQuery: { isLoading: false },
6161
predictionsQuery: { data: undefined },
62+
explanationsQuery: { data: undefined },
6263
} as SelectedMediaItemProps);
6364

6465
const response = await annotatorRender(

web_ui/src/pages/annotator/providers/prediction-provider/use-prediction-roi-query.hook.test.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,9 @@ describe('usePredictionsRoiQuery', () => {
180180
expect.anything()
181181
);
182182
});
183-
184-
expect(mockedInferenceService.getExplanations).not.toHaveBeenCalled();
185183
});
186184

187-
describe('PredictionMode.ONLINE is sent as PredictionCache.NEVER, calls "getPredictions" and "getExplanations"', () => {
185+
describe('PredictionMode.ONLINE is sent as PredictionCache.NEVER, calls "getPredictions"', () => {
188186
it('successful responses', async () => {
189187
jest.mocked(useAnnotatorMode).mockImplementation(() => ({
190188
isActiveLearningMode: false,
@@ -209,15 +207,6 @@ describe('usePredictionsRoiQuery', () => {
209207
expect.anything()
210208
);
211209
});
212-
213-
expect(mockedInferenceService.getExplanations).toHaveBeenLastCalledWith(
214-
datasetIdentifier,
215-
selectedMediaItem,
216-
taskId,
217-
selectedInput,
218-
// AbortController
219-
expect.anything()
220-
);
221210
});
222211

223212
it('rejected requests are handle as empty', async () => {
@@ -226,7 +215,6 @@ describe('usePredictionsRoiQuery', () => {
226215
currentMode: ANNOTATOR_MODE.PREDICTION,
227216
}));
228217
jest.mocked(mockedInferenceService.getPredictions).mockRejectedValue('test error');
229-
jest.mocked(mockedInferenceService.getExplanations).mockRejectedValue('test error');
230218

231219
const { result } = renderPredictionsRoiQuery({
232220
selectedInput,

web_ui/src/pages/annotator/providers/selected-media-item-provider/use-predictions-query.hook.test.tsx

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ describe('usePredictionsQuery', (): void => {
4949

5050
beforeEach(() => {
5151
mockedInferenceService.getPredictions = jest.fn();
52-
mockedInferenceService.getExplanations = jest.fn();
5352
});
5453

5554
it('task-chain projects call the service with taskId ', async (): Promise<void> => {
@@ -69,15 +68,6 @@ describe('usePredictionsQuery', (): void => {
6968
expect(result.current).toBeDefined();
7069
});
7170

72-
expect(mockedInferenceService.getExplanations).toHaveBeenCalledWith(
73-
datasetIdentifier,
74-
mediaItem,
75-
taskId,
76-
undefined,
77-
78-
// AbortController
79-
expect.anything()
80-
);
8171
expect(mockedInferenceService.getPredictions).toHaveBeenCalledWith(
8272
datasetIdentifier,
8373
coreLabels,
@@ -97,7 +87,6 @@ describe('usePredictionsQuery', (): void => {
9787
});
9888

9989
await waitFor(() => {
100-
expect(mockedInferenceService.getExplanations).not.toHaveBeenCalled();
10190
expect(mockedInferenceService.getPredictions).toHaveBeenCalledWith(
10291
datasetIdentifier,
10392
coreLabels,
@@ -111,7 +100,7 @@ describe('usePredictionsQuery', (): void => {
111100
});
112101
});
113102

114-
it('PredictionMode LATEST is handle as PredictionCache.ALWAYS', async (): Promise<void> => {
103+
it('PredictionMode LATEST is handled as PredictionCache.ALWAYS', async (): Promise<void> => {
115104
const onSuccess = jest.fn();
116105

117106
renderHookWithProviders(
@@ -126,7 +115,6 @@ describe('usePredictionsQuery', (): void => {
126115
expect(onSuccess).toHaveBeenCalled();
127116
});
128117

129-
expect(mockedInferenceService.getExplanations).not.toHaveBeenCalled();
130118
expect(mockedInferenceService.getPredictions).toHaveBeenCalledWith(
131119
datasetIdentifier,
132120
coreLabels,
@@ -139,24 +127,19 @@ describe('usePredictionsQuery', (): void => {
139127
);
140128
});
141129

142-
it('PredictionMode.ONLINE is sent as PredictionCache.NEVER, getExplanations is called', async (): Promise<void> => {
130+
it('PredictionMode.ONLINE is handled as PredictionCache.NEVER', async (): Promise<void> => {
131+
const onSuccess = jest.fn();
132+
143133
renderHookWithProviders(
144-
() => usePredictionsQuery({ ...predictionArguments, predictionId: PredictionMode.ONLINE }),
134+
() => usePredictionsQuery({ ...predictionArguments, onSuccess, predictionId: PredictionMode.ONLINE }),
145135
{
146136
wrapper,
147137
providerProps: { ...initialProps },
148138
}
149139
);
150140

151141
await waitFor(() => {
152-
expect(mockedInferenceService.getExplanations).toHaveBeenCalledWith(
153-
datasetIdentifier,
154-
mediaItem,
155-
undefined,
156-
undefined,
157-
// AbortController
158-
expect.anything()
159-
);
142+
expect(onSuccess).toHaveBeenCalled();
160143
});
161144

162145
expect(mockedInferenceService.getPredictions).toHaveBeenCalledWith(
@@ -170,25 +153,4 @@ describe('usePredictionsQuery', (): void => {
170153
expect.anything()
171154
);
172155
});
173-
174-
it('does not call "getExplanations" for keypoint detection projects', async (): Promise<void> => {
175-
const mockedProjectService = createInMemoryProjectService();
176-
177-
mockedProjectService.getProject = async () =>
178-
getMockedProject({ tasks: [getMockedTask({ domain: DOMAIN.KEYPOINT_DETECTION })] });
179-
180-
renderHookWithProviders(
181-
() => usePredictionsQuery({ ...predictionArguments, predictionId: PredictionMode.ONLINE }),
182-
{
183-
wrapper,
184-
providerProps: { ...initialProps, projectService: mockedProjectService },
185-
}
186-
);
187-
188-
await waitFor(() => {
189-
expect(mockedInferenceService.getPredictions).toHaveBeenCalled();
190-
});
191-
192-
expect(mockedInferenceService.getExplanations).not.toHaveBeenCalled();
193-
});
194156
});

web_ui/src/pages/annotator/providers/selected-media-item-provider/use-predictions-query.hook.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export const usePredictionsQuery = ({
8484
};
8585
}
8686

87-
// Only fetch predictions here
8887
const annotations = await inferenceService.getPredictions(
8988
datasetIdentifier,
9089
coreLabels,

0 commit comments

Comments
 (0)