@@ -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
@@ -123,12 +123,14 @@ describe('Labels', (): void => {
123123 labels,
124124 } ) ;
125125
126+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
127+
126128 jest . mocked ( useROI ) . mockReturnValue ( {
127129 roi,
128130 image : getMockedImage ( roi ) ,
129131 } ) ;
130132
131- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
133+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
132134
133135 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
134136
@@ -168,12 +170,14 @@ describe('Labels', (): void => {
168170 labels,
169171 } ) ;
170172
173+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
174+
171175 jest . mocked ( useROI ) . mockReturnValue ( {
172176 roi,
173177 image : getMockedImage ( roi ) ,
174178 } ) ;
175179
176- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
180+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
177181
178182 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
179183
@@ -211,12 +215,14 @@ describe('Labels', (): void => {
211215 labels,
212216 } ) ;
213217
218+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
219+
214220 jest . mocked ( useROI ) . mockReturnValue ( {
215221 roi,
216222 image : getMockedImage ( roi ) ,
217223 } ) ;
218224
219- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
225+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
220226
221227 expect ( screen . getByText ( 'Empty' ) ) . toBeInTheDocument ( ) ;
222228 expect ( screen . queryByText ( 'Empty (100%)' ) ) . not . toBeInTheDocument ( ) ;
@@ -228,7 +234,9 @@ describe('Labels', (): void => {
228234 } ) ;
229235 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ annotation ] , labels } ) ;
230236
231- renderApp ( annotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
237+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
238+
239+ renderApp ( annotation , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
232240
233241 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
234242
@@ -259,8 +267,9 @@ describe('Labels', (): void => {
259267 ] ;
260268 const mockedAnnotation = getMockedAnnotation ( { labels : mockedAnnotationLabels } ) ;
261269 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ mockedAnnotation ] , labels } ) ;
270+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
262271
263- renderApp ( mockedAnnotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
272+ renderApp ( mockedAnnotation , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
264273
265274 expect ( screen . getByText ( mockedLongLabels [ 0 ] . name ) ) . toHaveStyle ( 'text-overflow: ellipsis' ) ;
266275 } ) ;
@@ -276,8 +285,9 @@ describe('Labels', (): void => {
276285 ] ;
277286 const mockedAnnotation = getMockedAnnotation ( { labels : mockedAnnotationLabels } ) ;
278287 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ mockedAnnotation ] , labels } ) ;
288+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
279289
280- renderApp ( mockedAnnotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
290+ renderApp ( mockedAnnotation , { tasks : [ getMockedTask ( { labels } ) ] } ) ;
281291
282292 expect ( screen . getByText ( 'princess' ) ) . toBeInTheDocument ( ) ;
283293 } ) ;
@@ -287,8 +297,9 @@ describe('Labels', (): void => {
287297 labels : [ labelFromUser ( labels [ 0 ] ) , labelFromUser ( labels [ 1 ] ) , labelFromUser ( labels [ 3 ] ) ] ,
288298 } ) ;
289299 const annotationToolContext = fakeAnnotationToolContext ( { annotations : [ annotation ] , labels } ) ;
300+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
290301
291- renderApp ( annotation , annotationToolContext , { tasks : [ getMockedTask ( { labels } ) ] } , false ) ;
302+ renderApp ( annotation , { tasks : [ getMockedTask ( { labels } ) ] } , false ) ;
292303
293304 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
294305
@@ -332,13 +343,14 @@ describe('Labels', (): void => {
332343 const annotationToolContext = fakeAnnotationToolContext ( {
333344 annotations : [ annotation ] ,
334345 } ) ;
346+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
335347
336348 jest . mocked ( useROI ) . mockReturnValue ( {
337349 roi,
338350 image : getMockedImage ( roi ) ,
339351 } ) ;
340352
341- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
353+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
342354
343355 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
344356
@@ -362,8 +374,9 @@ describe('Labels', (): void => {
362374 const annotationToolContext = fakeAnnotationToolContext ( {
363375 annotations : [ annotation ] ,
364376 } ) ;
377+ jest . mocked ( useAnnotationToolContext ) . mockReturnValue ( annotationToolContext ) ;
365378
366- renderApp ( annotation , annotationToolContext , { tasks, selectedTask : tasks [ 0 ] } ) ;
379+ renderApp ( annotation , { tasks, selectedTask : tasks [ 0 ] } ) ;
367380
368381 expect ( screen . getByRole ( 'list' ) ) . toHaveAttribute ( 'id' , `${ annotation . id } -labels` ) ;
369382
0 commit comments