@@ -10,7 +10,6 @@ import {
10
10
} from '../../../src/components/EntityFinder/details/EntityDetailsList'
11
11
import EntityFinder , {
12
12
EntityFinderProps ,
13
- NO_VERSION_NUMBER ,
14
13
} from '../../../src/components/EntityFinder/EntityFinder'
15
14
import * as EntityTreeModule from '../../../src/components/EntityFinder/tree/EntityTree'
16
15
import { FinderScope } from '../../../src/components/EntityFinder/tree/EntityTree'
@@ -27,6 +26,7 @@ import {
27
26
import { Map } from 'immutable'
28
27
import * as useEntityBundleModule from '../../../src/synapse-queries/entity/useEntityBundle'
29
28
import SynapseClient from '../../../src/synapse-client'
29
+ import { getUseQuerySuccessMock } from '../../testutils/ReactQueryMockUtils'
30
30
31
31
jest . mock ( 'react-reflex' , ( ) => {
32
32
return {
@@ -42,14 +42,14 @@ jest.mock('react-reflex', () => {
42
42
43
43
const mockUseGetEntityBundle = jest . spyOn ( useEntityBundleModule , 'default' )
44
44
45
- const mockEntityTree = jest
45
+ jest
46
46
. spyOn ( EntityTreeModule , 'EntityTree' )
47
47
. mockImplementation ( ( { toggleSelection, setDetailsViewConfiguration } ) => {
48
48
invokeToggleSelectionViaTree = reference => {
49
- toggleSelection ( reference )
49
+ toggleSelection ! ( reference )
50
50
}
51
51
invokeSetConfigViaTree = configuration => {
52
- setDetailsViewConfiguration ( configuration )
52
+ setDetailsViewConfiguration ! ( configuration )
53
53
}
54
54
return < div role = "tree" > </ div >
55
55
} )
@@ -85,30 +85,34 @@ const defaultProps: EntityFinderProps = {
85
85
visibleTypesInTree : [ EntityType . PROJECT , EntityType . FOLDER ] ,
86
86
selectableTypes : Object . values ( EntityType ) ,
87
87
treeOnly : false ,
88
- selectedCopy : 'Chosen Entities' ,
89
88
}
90
89
91
90
function renderComponent ( propOverrides ?: Partial < EntityFinderProps > ) {
92
- return render (
91
+ const user = userEvent . setup ( )
92
+ render (
93
93
< SynapseTestContext >
94
94
< EntityFinder { ...defaultProps } { ...propOverrides } />
95
95
</ SynapseTestContext > ,
96
96
)
97
+
98
+ const searchInput = screen . getByRole ( 'textbox' )
99
+
100
+ return { user, searchInput }
97
101
}
98
102
99
103
describe ( 'EntityFinder tests' , ( ) => {
100
104
beforeEach ( ( ) => {
101
105
jest . clearAllMocks ( )
102
106
103
- mockUseGetEntityBundle . mockReturnValue ( {
104
- data : {
107
+ mockUseGetEntityBundle . mockReturnValue (
108
+ getUseQuerySuccessMock ( {
105
109
entity : {
106
110
id : 'syn123' ,
107
111
name : 'My file entity' ,
108
112
concreteType : 'org.sagebionetworks.repo.model.FileEntity' ,
109
113
} ,
110
- } ,
111
- } )
114
+ } ) ,
115
+ )
112
116
} )
113
117
114
118
describe ( 'single-select toggleSelection validation' , ( ) => {
@@ -328,7 +332,9 @@ describe('EntityFinder tests', () => {
328
332
await waitFor ( ( ) =>
329
333
expect ( mockDetailsList ) . toHaveBeenLastCalledWith (
330
334
expect . objectContaining ( {
331
- selected : Map ( [ [ reference . targetId , NO_VERSION_NUMBER ] ] ) ,
335
+ selected : Map ( [
336
+ [ reference . targetId , { targetId : reference . targetId } ] ,
337
+ ] ) ,
332
338
} ) ,
333
339
{ } ,
334
340
) ,
@@ -355,61 +361,24 @@ describe('EntityFinder tests', () => {
355
361
} )
356
362
357
363
describe ( 'Search' , ( ) => {
358
- it ( 'Updates the search button text when only one type is selectable' , async ( ) => {
359
- // Folders are the only selectable type, so only folders will appear in search.
360
- renderComponent ( { selectableTypes : [ EntityType . FOLDER ] } )
361
-
362
- // Search button text should match
363
- await screen . findByText ( 'Search for Folders' )
364
- } )
365
-
366
- it ( 'Updates the search button text when only table types are selectable' , async ( ) => {
367
- // Datasets and entity views are table types
368
- renderComponent ( {
369
- selectableTypes : [ EntityType . DATASET , EntityType . ENTITY_VIEW ] ,
364
+ it ( 'handles searching for terms' , async ( ) => {
365
+ const { user, searchInput } = renderComponent ( {
366
+ treeOnly : true ,
367
+ selectableTypes : [ EntityType . FILE ] ,
370
368
} )
371
369
372
- // Search button text should match
373
- await screen . findByText ( 'Search for Tables' )
374
- } )
375
-
376
- it ( 'clicking the search button opens the input field' , async ( ) => {
377
- renderComponent ( { treeOnly : true } )
378
-
379
370
// Tree should be visible before we start search. No table should be visible
380
- expect ( ( ) => screen . getByRole ( 'tree' ) ) . not . toThrowError ( )
381
- expect ( ( ) => screen . getByRole ( 'table' ) ) . toThrowError ( )
382
-
383
- // Don't show the search box before the button is clicked
384
- expect ( ( ) => screen . getByRole ( 'textbox' ) ) . toThrowError ( )
385
-
386
- await userEvent . click ( screen . getByText ( 'Search all of Synapse' ) )
387
- await waitFor ( ( ) => screen . getByRole ( 'textbox' ) )
388
-
389
- // The tree should be hidden when searching. The table of search results should be visible
390
- expect ( ( ) => screen . getByRole ( 'tree' ) ) . toThrowError ( )
391
- expect ( ( ) => screen . getByRole ( 'table' ) ) . not . toThrowError ( )
392
-
393
- // Close the search
394
- await userEvent . click ( screen . getByText ( 'Back to Browse' ) )
395
-
396
- // Tree should come back, table should be gone
397
- await waitFor ( ( ) => screen . getByRole ( 'tree' ) )
398
- expect ( ( ) => screen . getByRole ( 'table' ) ) . toThrowError ( )
399
-
400
- // Search input field should be gone too
401
- expect ( ( ) => screen . getByRole ( 'textbox' ) ) . toThrowError ( )
402
- } )
403
-
404
- it ( 'handles searching for terms' , async ( ) => {
405
- renderComponent ( { selectableTypes : [ EntityType . FILE ] } )
371
+ expect ( ( ) => screen . getByRole ( 'tree' ) ) . not . toThrow ( )
372
+ expect ( ( ) => screen . getByRole ( 'table' ) ) . toThrow ( )
406
373
407
374
const query = 'my search terms '
408
375
const queryTerms = [ 'my' , 'search' , 'terms' ]
409
- await userEvent . click ( screen . getByText ( 'Search for Files' ) )
410
- await waitFor ( ( ) => screen . getByRole ( 'textbox' ) )
411
- await userEvent . type ( screen . getByRole ( 'textbox' ) , query )
412
- await userEvent . type ( screen . getByRole ( 'textbox' ) , '{enter}' )
376
+ await user . type ( searchInput , query )
377
+ await user . type ( searchInput , '{enter}' )
378
+
379
+ // The tree should be hidden when searching. The table of search results should be visible
380
+ expect ( ( ) => screen . getByRole ( 'tree' ) ) . toThrow ( )
381
+ expect ( ( ) => screen . getByRole ( 'table' ) ) . not . toThrow ( )
413
382
414
383
await waitFor ( ( ) =>
415
384
expect ( mockDetailsList ) . toBeCalledWith (
@@ -453,19 +422,51 @@ describe('EntityFinder tests', () => {
453
422
{ } ,
454
423
) ,
455
424
)
425
+
426
+ // Clear the search results and verify we go back to the original view
427
+ await user . click ( screen . getByRole ( 'button' , { name : 'Clear Search' } ) )
428
+
429
+ // Tree should be visible once again and table should be hidden
430
+ expect ( ( ) => screen . getByRole ( 'tree' ) ) . not . toThrow ( )
431
+ expect ( ( ) => screen . getByRole ( 'table' ) ) . toThrow ( )
456
432
} )
457
433
458
434
it ( 'handles searching for a synId' , async ( ) => {
459
- renderComponent ( )
435
+ const { user , searchInput } = renderComponent ( )
460
436
461
437
const entityId = 'syn123'
462
438
const version = 2
463
439
464
- const entityHeaderResult = { results : [ { id : entityId } ] }
465
- const entityHeaderResultWithVersion : PaginatedResults <
466
- Partial < EntityHeader >
467
- > = {
468
- results : [ { id : entityId , versionNumber : version } ] ,
440
+ const entityHeaderResult : PaginatedResults < EntityHeader > = {
441
+ results : [
442
+ {
443
+ id : entityId ,
444
+ name : 'foo' ,
445
+ benefactorId : 123 ,
446
+ type : 'org.sagebionetworks.repo.model.FileEntity' ,
447
+ createdOn : '' ,
448
+ modifiedOn : '' ,
449
+ createdBy : '' ,
450
+ modifiedBy : '' ,
451
+ isLatestVersion : false ,
452
+ } ,
453
+ ] ,
454
+ }
455
+ const entityHeaderResultWithVersion : PaginatedResults < EntityHeader > = {
456
+ results : [
457
+ {
458
+ id : entityId ,
459
+ versionNumber : version ,
460
+ name : 'foo' ,
461
+ benefactorId : 123 ,
462
+ type : 'org.sagebionetworks.repo.model.FileEntity' ,
463
+ createdOn : '' ,
464
+ modifiedOn : '' ,
465
+ createdBy : '' ,
466
+ modifiedBy : '' ,
467
+ isLatestVersion : true ,
468
+ } ,
469
+ ] ,
469
470
}
470
471
471
472
when ( mockGetEntityHeaders )
@@ -479,10 +480,8 @@ describe('EntityFinder tests', () => {
479
480
)
480
481
. mockResolvedValue ( entityHeaderResultWithVersion )
481
482
482
- await userEvent . click ( screen . getByText ( 'Search all of Synapse' ) )
483
- await waitFor ( ( ) => screen . getByRole ( 'textbox' ) )
484
- await userEvent . type ( screen . getByRole ( 'textbox' ) , entityId )
485
- await userEvent . type ( screen . getByRole ( 'textbox' ) , '{enter}' )
483
+ await user . type ( searchInput , entityId )
484
+ await user . type ( searchInput , '{enter}' )
486
485
487
486
await waitFor ( ( ) =>
488
487
expect ( mockDetailsList ) . toBeCalledWith (
@@ -498,12 +497,9 @@ describe('EntityFinder tests', () => {
498
497
expect ( mockGetEntityHeaders ) . toBeCalledTimes ( 1 )
499
498
500
499
// Search with a version number
501
- await userEvent . clear ( screen . getByRole ( 'textbox' ) )
502
- await userEvent . type (
503
- screen . getByRole ( 'textbox' ) ,
504
- `${ entityId } .${ version } ` ,
505
- )
506
- await userEvent . type ( screen . getByRole ( 'textbox' ) , '{enter}' )
500
+ await user . clear ( searchInput )
501
+ await user . type ( searchInput , `${ entityId } .${ version } ` )
502
+ await user . type ( searchInput , '{enter}' )
507
503
await waitFor ( ( ) =>
508
504
expect ( mockDetailsList ) . toBeCalledWith (
509
505
expect . objectContaining ( {
0 commit comments