@@ -23,42 +23,12 @@ jest.mock('../../query/api', () => ({
2323} ) ) ;
2424
2525describe ( 'AddToPicklistMenuItem' , ( ) => {
26- const expectedText = 'Add to Picklist' ;
27- const queryModelWithoutSelections = makeTestQueryModel ( new SchemaQuery ( 'test' , 'query' ) ) ;
28- let queryModelWithSelections = makeTestQueryModel ( new SchemaQuery ( 'test' , 'query' ) ) ;
29- queryModelWithSelections = queryModelWithSelections . mutate ( {
30- rowCount : 2 ,
31- selections : new Set ( [ '1' , '2' ] ) ,
32- } ) ;
33-
34- test ( 'with queryModel' , async ( ) => {
35- renderWithAppContext ( < AddToPicklistMenuItem queryModel = { queryModelWithSelections } user = { TEST_USER_EDITOR } /> ) ;
36- const menuItem = document . querySelectorAll ( '.lk-menu-item' ) ;
37- expect ( menuItem ) . toHaveLength ( 1 ) ;
38- expect ( menuItem [ 0 ] ) . toHaveTextContent ( expectedText ) ;
39-
40- await validateMenuItemClick ( true ) ;
41- const picklistModal = document . querySelectorAll ( '.modal' ) ;
42- expect ( picklistModal ) . toHaveLength ( 1 ) ;
43- expect ( document . querySelector ( '.alert-info' ) ) . toHaveTextContent ( 'Adding 2 samples to selected picklist.' ) ;
44- } ) ;
26+ const schemaQuery = new SchemaQuery ( 'test' , 'query' ) ;
4527
46- test ( 'with selectedIds' , async ( ) => {
28+ test ( 'not Editor' , ( ) => {
4729 renderWithAppContext (
48- < AddToPicklistMenuItem queryModel = { queryModelWithoutSelections } sampleIds = { [ 1 ] } user = { TEST_USER_EDITOR } />
30+ < AddToPicklistMenuItem schemaQuery = { schemaQuery } selectedRowIds = { [ '1' , '2' ] } user = { TEST_USER_READER } />
4931 ) ;
50- const menuItem = document . querySelectorAll ( '.lk-menu-item' ) ;
51- expect ( menuItem ) . toHaveLength ( 1 ) ;
52- expect ( menuItem [ 0 ] ) . toHaveTextContent ( expectedText ) ;
53-
54- await validateMenuItemClick ( true ) ;
55- const picklistModal = document . querySelectorAll ( '.modal' ) ;
56- expect ( picklistModal ) . toHaveLength ( 1 ) ;
57- expect ( document . querySelector ( '.alert-info' ) ) . toHaveTextContent ( 'Adding 1 sample to selected picklist.' ) ;
58- } ) ;
59-
60- test ( 'not Editor' , ( ) => {
61- renderWithAppContext ( < AddToPicklistMenuItem sampleIds = { [ 1 ] } user = { TEST_USER_READER } /> ) ;
6232 expect ( document . querySelectorAll ( '.lk-menu-item' ) ) . toHaveLength ( 0 ) ;
6333 } ) ;
6434
@@ -73,37 +43,22 @@ describe('AddToPicklistMenuItem', () => {
7343 } ) ;
7444 }
7545
76- test ( 'modal open on click, queryModel without selections ' , async ( ) => {
46+ test ( 'modal opens when there are selectedRowIds ' , async ( ) => {
7747 renderWithAppContext (
78- < AddToPicklistMenuItem queryModel = { queryModelWithoutSelections } user = { TEST_USER_EDITOR } />
48+ < AddToPicklistMenuItem schemaQuery = { schemaQuery } selectedRowIds = { [ 1 ] } user = { TEST_USER_EDITOR } />
7949 ) ;
80- await validateMenuItemClick ( false ) ;
81- } ) ;
82-
83- test ( 'modal open on click, queryModel with selections' , async ( ) => {
84- renderWithAppContext ( < AddToPicklistMenuItem queryModel = { queryModelWithSelections } user = { TEST_USER_EDITOR } /> ) ;
8550 await validateMenuItemClick ( true ) ;
8651 } ) ;
8752
88- test ( 'modal open on click, sampleIds ' , async ( ) => {
53+ test ( 'modal does not open when there are no selectedRowIds ' , async ( ) => {
8954 renderWithAppContext (
90- < AddToPicklistMenuItem queryModel = { queryModelWithoutSelections } sampleIds = { [ 1 ] } user = { TEST_USER_EDITOR } />
55+ < AddToPicklistMenuItem schemaQuery = { schemaQuery } selectedRowIds = { [ ] } user = { TEST_USER_EDITOR } />
9156 ) ;
92- await validateMenuItemClick ( true ) ;
57+ await validateMenuItemClick ( false ) ;
9358 } ) ;
9459
95- test ( 'sample with status' , async ( ) => {
96- let model = makeTestQueryModel ( new SchemaQuery ( 'test' , 'query' ) ) ;
97- model = model . mutate ( {
98- rows : {
99- '1' : {
100- RowId : { value : 1 } ,
101- [ SAMPLE_STATE_TYPE_COLUMN_NAME ] : { value : 'Locked' } ,
102- } ,
103- } ,
104- orderedRows : [ '1' ] ,
105- } ) ;
106- renderWithAppContext ( < AddToPicklistMenuItem queryModel = { model } sampleIds = { [ 1 ] } user = { TEST_USER_EDITOR } /> ) ;
107- await validateMenuItemClick ( true ) ;
60+ test ( 'modal does not open when selectedRowIds is undefined' , async ( ) => {
61+ renderWithAppContext ( < AddToPicklistMenuItem schemaQuery = { schemaQuery } user = { TEST_USER_EDITOR } /> ) ;
62+ await validateMenuItemClick ( false ) ;
10863 } ) ;
10964} ) ;
0 commit comments