@@ -8,15 +8,14 @@ import { QueryColumn } from '../../../public/QueryColumn';
88import { makeTestQueryModel } from '../../../public/QueryModel/testUtils' ;
99import { SchemaQuery } from '../../../public/SchemaQuery' ;
1010
11- import { mountWithAppServerContext } from '../../test/enzymeTestHelpers' ;
12- import { DisableableMenuItem } from '../samples/DisableableMenuItem' ;
13-
1411import { TestTypeDataType , TestTypeDataTypeWithEntityFilter } from '../../../test/data/constants' ;
1512
1613import { FieldFilter } from '../search/models' ;
1714
1815import { SCHEMAS } from '../../schemas' ;
1916
17+ import { renderWithAppContext } from '../../test/reactTestLibraryHelpers' ;
18+
2019import {
2120 FindDerivativesMenuItem ,
2221 getFieldFilter ,
@@ -87,6 +86,7 @@ const QUERY_INFO = QueryInfo.fromJsonForTests({
8786const MODEL = makeTestQueryModel ( new SchemaQuery ( 'samples' , 'query' , VIEW_NAME ) , QUERY_INFO ) . mutate ( {
8887 baseFilters : [ Filter . create ( 'a' , null , Filter . Types . ISBLANK ) ] ,
8988 filterArray : [ Filter . create ( 'b' , null , Filter . Types . ISBLANK ) ] ,
89+ rowCount : 1 ,
9090} ) ;
9191
9292describe ( 'FindDerivativesButton' , ( ) => {
@@ -96,11 +96,18 @@ describe('FindDerivativesButton', () => {
9696 } ;
9797
9898 test ( 'default props' , ( ) => {
99- const wrapper = mountWithAppServerContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } asSubMenu /> ) ;
100- expect ( wrapper . find ( DisableableMenuItem ) ) . toHaveLength ( 1 ) ;
101- expect ( wrapper . find ( DisableableMenuItem ) . prop ( 'disabled' ) ) . toBe ( false ) ;
102- expect ( wrapper . find ( DisableableMenuItem ) . prop ( 'disabledMessage' ) ) . toContain ( ' ()' ) ;
103- wrapper . unmount ( ) ;
99+ renderWithAppContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } asSubMenu /> ) ;
100+ expect ( document . querySelectorAll ( '.lk-menu-item' ) ) . toHaveLength ( 1 ) ;
101+ expect ( document . querySelectorAll ( '.lk-menu-item.disabled' ) ) . toHaveLength ( 0 ) ;
102+ } ) ;
103+
104+ test ( 'disable menu item for grid with no rows' , ( ) => {
105+ const model2 = MODEL . mutate ( {
106+ rowCount : 0 ,
107+ } ) ;
108+ renderWithAppContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } model = { model2 } asSubMenu /> ) ;
109+ expect ( document . querySelectorAll ( '.lk-menu-item' ) ) . toHaveLength ( 1 ) ;
110+ expect ( document . querySelectorAll ( '.lk-menu-item.disabled' ) ) . toHaveLength ( 1 ) ;
104111 } ) ;
105112
106113 test ( 'invalidFilterNames from search, disabled button' , ( ) => {
@@ -110,22 +117,18 @@ describe('FindDerivativesButton', () => {
110117 Filter . create ( '*' , 'test' , Filter . Types . CONTIANS ) ,
111118 ] ,
112119 } ) ;
113- const wrapper = mountWithAppServerContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } model = { model2 } /> ) ;
114- expect ( wrapper . find ( DisableableMenuItem ) ) . toHaveLength ( 1 ) ;
115- expect ( wrapper . find ( DisableableMenuItem ) . prop ( 'disabled' ) ) . toBe ( true ) ;
116- expect ( wrapper . find ( DisableableMenuItem ) . prop ( 'disabledMessage' ) ) . toContain ( ' (Search Filter)' ) ;
117- wrapper . unmount ( ) ;
120+ renderWithAppContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } model = { model2 } /> ) ;
121+ expect ( document . querySelectorAll ( '.lk-menu-item' ) ) . toHaveLength ( 1 ) ;
122+ expect ( document . querySelectorAll ( '.lk-menu-item.disabled' ) ) . toHaveLength ( 1 ) ;
118123 } ) ;
119124
120125 test ( 'invalidFilterNames from MVFK, disabled button' , ( ) => {
121126 const model2 = MODEL . mutate ( {
122127 filterArray : [ Filter . create ( 'e' , null , Filter . Types . ISBLANK ) ] ,
123128 } ) ;
124- const wrapper = mountWithAppServerContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } model = { model2 } /> ) ;
125- expect ( wrapper . find ( DisableableMenuItem ) ) . toHaveLength ( 1 ) ;
126- expect ( wrapper . find ( DisableableMenuItem ) . prop ( 'disabled' ) ) . toBe ( true ) ;
127- expect ( wrapper . find ( DisableableMenuItem ) . prop ( 'disabledMessage' ) ) . toContain ( ' (FieldE)' ) ;
128- wrapper . unmount ( ) ;
129+ renderWithAppContext ( < FindDerivativesMenuItem { ...DEFAULT_PROPS } model = { model2 } /> ) ;
130+ expect ( document . querySelectorAll ( '.lk-menu-item' ) ) . toHaveLength ( 1 ) ;
131+ expect ( document . querySelectorAll ( '.lk-menu-item.disabled' ) ) . toHaveLength ( 1 ) ;
129132 } ) ;
130133} ) ;
131134
@@ -160,43 +163,43 @@ describe('getFieldFilter', () => {
160163} ) ;
161164
162165describe ( 'getSessionSearchFilterProps' , ( ) => {
163- test ( 'no filters' , ( ) => {
164- const props = getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] ) ;
166+ test ( 'no filters' , async ( ) => {
167+ const props = await getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] ) ;
165168 expect ( props ) . toHaveLength ( 1 ) ;
166169 expect ( props [ 0 ] . filterArray ) . toHaveLength ( 0 ) ;
167170 expect ( props [ 0 ] . dataTypeDisplayName ) . toBe ( 'query' ) ;
168171 expect ( props [ 0 ] . entityDataType ) . toBe ( SampleTypeDataType ) ;
169172 } ) ;
170173
171- test ( 'with model title' , ( ) => {
174+ test ( 'with model title' , async ( ) => {
172175 const model2 = MODEL . mutate ( { title : 'TestingTitle' } ) ;
173- const props = getSessionSearchFilterProps ( SampleTypeDataType , model2 , [ ] ) ;
176+ const props = await getSessionSearchFilterProps ( SampleTypeDataType , model2 , [ ] ) ;
174177 expect ( props ) . toHaveLength ( 1 ) ;
175178 expect ( props [ 0 ] . dataTypeDisplayName ) . toBe ( 'TestingTitle' ) ;
176179 } ) ;
177180
178- test ( 'with filters' , ( ) => {
179- const props = getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [
181+ test ( 'with filters' , async ( ) => {
182+ const props = await getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [
180183 Filter . create ( 'a' , 'val1' ) ,
181184 Filter . create ( 'b' , 'val2' ) ,
182185 ] ) ;
183186 expect ( props ) . toHaveLength ( 1 ) ;
184187 expect ( props [ 0 ] . filterArray ) . toHaveLength ( 2 ) ;
185188 } ) ;
186189
187- test ( 'baseFilter, without baseModel' , ( ) => {
188- const props = getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] , undefined , undefined , [
190+ test ( 'baseFilter, without baseModel' , async ( ) => {
191+ const props = await getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] , undefined , undefined , [
189192 Filter . create ( 'a' , 'Something' ) ,
190193 ] ) ;
191194 expect ( props ) . toHaveLength ( 1 ) ;
192195 expect ( props [ 0 ] . filterArray ) . toHaveLength ( 1 ) ;
193196 } ) ;
194197
195- test ( 'baseFilter, with baseModel for sample type' , ( ) => {
198+ test ( 'baseFilter, with baseModel for sample type' , async ( ) => {
196199 const baseModel = MODEL . mutate ( {
197200 schemaQuery : new SchemaQuery ( 'samples' , 'query2' ) ,
198201 } ) ;
199- const props = getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] , SampleTypeDataType , baseModel , [
202+ const props = await getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] , SampleTypeDataType , baseModel , [
200203 Filter . create ( 'a' , 'Something' ) ,
201204 ] ) ;
202205 expect ( props ) . toHaveLength ( 2 ) ;
@@ -206,11 +209,11 @@ describe('getSessionSearchFilterProps', () => {
206209 expect ( props [ 1 ] . filterArray ) . toHaveLength ( 0 ) ;
207210 } ) ;
208211
209- test ( 'baseFilter, with baseModel for data class' , ( ) => {
212+ test ( 'baseFilter, with baseModel for data class' , async ( ) => {
210213 const baseModel = MODEL . mutate ( {
211214 schemaQuery : new SchemaQuery ( 'exp.data' , 'query3' ) ,
212215 } ) ;
213- const props = getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] , DataClassDataType , baseModel , [
216+ const props = await getSessionSearchFilterProps ( SampleTypeDataType , MODEL , [ ] , DataClassDataType , baseModel , [
214217 Filter . create ( 'a' , 'Something' ) ,
215218 ] ) ;
216219 expect ( props ) . toHaveLength ( 2 ) ;
0 commit comments