@@ -15,7 +15,8 @@ import { getMockedLabel, labels, mockedLongLabels } from '../../../../test-utils
1515import { getMockedTask , mockedTaskContextProps } from '../../../../test-utils/mocked-items-factory/mocked-tasks' ;
1616import { providersRender as render } from '../../../../test-utils/required-providers-render' ;
1717import { getMockedImage } from '../../../../test-utils/utils' ;
18- import { AnnotationToolContext } from '../../core/annotation-tool-context.interface' ;
18+ import { AnnotationSceneProvider } from '../../providers/annotation-scene-provider/annotation-scene-provider.component' ;
19+ import { useAnnotationToolContext } from '../../providers/annotation-tool-provider/annotation-tool-provider.component' ;
1920import { useROI } from '../../providers/region-of-interest-provider/region-of-interest-provider.component' ;
2021import { useTaskChain } from '../../providers/task-chain-provider/task-chain-provider.component' ;
2122import { TaskContextProps , useTask } from '../../providers/task-provider/task-provider.component' ;
@@ -44,26 +45,23 @@ jest.mock('../../providers/region-of-interest-provider/region-of-interest-provid
4445 } ) ) ,
4546} ) ) ;
4647
48+ jest . mock ( '../../providers/annotation-tool-provider/annotation-tool-provider.component' , ( ) => ( {
49+ ...jest . requireActual ( '../../providers/annotation-tool-provider/annotation-tool-provider.component' ) ,
50+ useAnnotationToolContext : jest . fn ( ) ,
51+ } ) ) ;
52+
4753describe ( 'Labels' , ( ) : void => {
4854 jest . mocked ( useTaskChain ) . mockImplementation ( ( ) => {
4955 return { inputs : [ ] , outputs : [ ] } ;
5056 } ) ;
5157
52- const renderApp = (
53- annotation : Annotation ,
54- annotationToolContext : AnnotationToolContext ,
55- tasksHook : Partial < TaskContextProps > = { } ,
56- showOptions = true
57- ) => {
58+ const renderApp = ( annotation : Annotation , tasksHook : Partial < TaskContextProps > = { } , showOptions = true ) => {
5859 jest . mocked ( useTask ) . mockReturnValue ( mockedTaskContextProps ( tasksHook ) ) ;
5960
6061 render (
61- < Labels
62- annotation = { annotation }
63- showOptions = { showOptions }
64- annotationToolContext = { annotationToolContext }
65- canEditAnnotationLabel
66- />
62+ < AnnotationSceneProvider annotations = { [ ] } labels = { [ ] } >
63+ < Labels annotation = { annotation } showOptions = { showOptions } canEditAnnotationLabel /> )
64+ </ AnnotationSceneProvider >
6765 ) ;
6866 } ;
6967
@@ -73,7 +71,9 @@ describe('Labels', (): void => {
7371 } ) ;
7472 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ annotation ] , labels } ) ;
7573
76- renderApp ( annotation , annotationToolContext ) ;
74+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
75+
76+ renderApp ( annotation ) ;
7777
7878 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
7979
@@ -128,7 +128,7 @@ describe('Labels', (): void => {
128128 image : getMockedImage ( roi ) ,
129129 } ) ;
130130
131- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
131+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
132132
133133 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
134134
@@ -168,12 +168,14 @@ describe('Labels', (): void => {
168168 labels,
169169 } ) ;
170170
171+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
172+
171173 jest . mocked ( useROI ) . mockReturnValue ( {
172174 roi,
173175 image : getMockedImage ( roi ) ,
174176 } ) ;
175177
176- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
178+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
177179
178180 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
179181
@@ -211,12 +213,14 @@ describe('Labels', (): void => {
211213 labels,
212214 } ) ;
213215
216+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
217+
214218 jest . mocked ( useROI ) . mockReturnValue ( {
215219 roi,
216220 image : getMockedImage ( roi ) ,
217221 } ) ;
218222
219- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
223+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
220224
221225 expect ( screen . getByText ( 'Empty' ) ) . toBeInTheDocument ( ) ;
222226 expect ( screen . queryByText ( 'Empty (100%)' ) ) . not . toBeInTheDocument ( ) ;
@@ -228,7 +232,7 @@ describe('Labels', (): void => {
228232 } ) ;
229233 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ annotation ] , labels } ) ;
230234
231- renderApp ( annotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
235+ renderApp ( annotation , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
232236
233237 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
234238
@@ -259,8 +263,9 @@ describe('Labels', (): void => {
259263 ] ;
260264 const mockedAnnotation = getMockedAnnotation ( { labels : mockedAnnotationLabels } ) ;
261265 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ mockedAnnotation ] , labels } ) ;
266+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
262267
263- renderApp ( mockedAnnotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
268+ renderApp ( mockedAnnotation , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
264269
265270 expect ( screen . getByText ( mockedLongLabels [ 0 ] . name ) ) . toHaveStyle ( 'text-overflow: ellipsis' ) ;
266271 } ) ;
@@ -276,8 +281,9 @@ describe('Labels', (): void => {
276281 ] ;
277282 const mockedAnnotation = getMockedAnnotation ( { labels : mockedAnnotationLabels } ) ;
278283 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ mockedAnnotation ] , labels } ) ;
284+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
279285
280- renderApp ( mockedAnnotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
286+ renderApp ( mockedAnnotation , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
281287
282288 expect ( screen . getByText ( 'princess' ) ) . toBeInTheDocument ( ) ;
283289 } ) ;
@@ -287,8 +293,9 @@ describe('Labels', (): void => {
287293 labels : [ labelFromUser ( labels [ 0 ] ) , labelFromUser ( labels [ 1 ] ) , labelFromUser ( labels [ 3 ] ) ] ,
288294 } ) ;
289295 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ annotation ] , labels } ) ;
296+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
290297
291- renderApp ( annotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } , false ) ;
298+ renderApp ( annotation , { tasks : [ getMockedTask ( { labels } ) ] } , false ) ;
292299
293300 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
294301
@@ -332,13 +339,14 @@ describe('Labels', (): void => {
332339 const annotationToolContext = fakeAnnotationToolContext ( {
333340 annotations : [ annotation ] ,
334341 } ) ;
342+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
335343
336344 jest . mocked ( useROI ) . mockReturnValue ( {
337345 roi,
338346 image : getMockedImage ( roi ) ,
339347 } ) ;
340348
341- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
349+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
342350
343351 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
344352
@@ -362,8 +370,9 @@ describe('Labels', (): void => {
362370 const annotationToolContext = fakeAnnotationToolContext ( {
363371 annotations : [ annotation ] ,
364372 } ) ;
373+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
365374
366- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
375+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
367376
368377 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
369378
0 commit comments