@@ -5,18 +5,22 @@ import userEvent from "@testing-library/user-event";
55import { CqlBuilderLookup } from "../../model/CqlBuilderLookup" ;
66import { cqlBuilderLookup } from "../__mocks__/MockCqlBuilderLookupsTypes" ;
77
8+ const props = {
9+ canEdit : true ,
10+ handleApplyDefinition : jest . fn ( ) ,
11+ handleDefinitionEdit : jest . fn ( ) ,
12+ handleDefinitionDelete : jest . fn ( ) ,
13+ cqlBuilderLookupsTypes : { } as CqlBuilderLookup ,
14+ isCQLUnchanged : true ,
15+ cql : "" ,
16+ setEditorVal : jest . fn ( ) ,
17+ resetCql : jest . fn ( ) ,
18+ getCqlDefinitionReturnTypes : jest . fn ( ) ,
19+ } ;
20+
821describe ( "DefinitionsSection" , ( ) => {
922 it ( "Should display definition section" , async ( ) => {
10- render (
11- < DefinitionsSection
12- canEdit = { true }
13- handleApplyDefinition = { jest . fn ( ) }
14- cqlBuilderLookupsTypes = { { } as CqlBuilderLookup }
15- handleDefinitionDelete = { jest . fn ( ) }
16- isCQLUnchanged
17- setIsCQLUnchanged
18- />
19- ) ;
23+ render ( < DefinitionsSection { ...props } /> ) ;
2024 const definition = await screen . findByTestId ( "definition-tab" ) ;
2125 const savedDefinitions = await screen . findByText ( "Saved Definitions (0)" ) ;
2226 expect ( definition ) . toBeInTheDocument ( ) ;
@@ -30,16 +34,7 @@ describe("DefinitionsSection", () => {
3034 } ) ;
3135
3236 it ( "Should display saved definition section" , async ( ) => {
33- render (
34- < DefinitionsSection
35- canEdit = { true }
36- handleApplyDefinition = { jest . fn ( ) }
37- handleDefinitionDelete = { jest . fn ( ) }
38- isCQLUnchanged
39- setIsCQLUnchanged
40- cqlBuilderLookupsTypes = { { } as unknown as CqlBuilderLookup }
41- />
42- ) ;
37+ render ( < DefinitionsSection { ...props } /> ) ;
4338 const definition = await screen . findByTestId ( "definition-tab" ) ;
4439 const savedDefinitions = await screen . findByText ( "Saved Definitions (0)" ) ;
4540 expect ( definition ) . toBeInTheDocument ( ) ;
@@ -59,12 +54,8 @@ describe("DefinitionsSection", () => {
5954 it ( "Should allow pagination for savedDefinitions" , async ( ) => {
6055 render (
6156 < DefinitionsSection
62- canEdit = { true }
63- handleApplyDefinition = { jest . fn ( ) }
57+ { ...props }
6458 cqlBuilderLookupsTypes = { cqlBuilderLookup }
65- handleDefinitionDelete = { jest . fn ( ) }
66- isCQLUnchanged
67- setIsCQLUnchanged
6859 />
6960 ) ;
7061 const definition = await screen . findByTestId ( "definition-tab" ) ;
@@ -99,12 +90,8 @@ describe("DefinitionsSection", () => {
9990 it ( "Should allow limit changes for savedDefinitions pagination" , async ( ) => {
10091 render (
10192 < DefinitionsSection
102- canEdit = { true }
103- handleApplyDefinition = { jest . fn ( ) }
93+ { ...props }
10494 cqlBuilderLookupsTypes = { cqlBuilderLookup }
105- handleDefinitionDelete = { jest . fn ( ) }
106- isCQLUnchanged
107- setIsCQLUnchanged
10895 />
10996 ) ;
11097 const definition = await screen . findByTestId ( "definition-tab" ) ;
@@ -152,15 +139,36 @@ describe("DefinitionsSection", () => {
152139 } ) ;
153140 } ) ;
154141
142+ it ( "Should not show edit/delete actions for measure if user does not have permission" , async ( ) => {
143+ render (
144+ < DefinitionsSection
145+ { ...props }
146+ cqlBuilderLookupsTypes = { cqlBuilderLookup }
147+ canEdit = { false }
148+ />
149+ ) ;
150+ // go to saved definitions tab
151+ const savedDefinitionsTab = screen . getByRole ( "tab" , {
152+ name : / S a v e d D e f i n i t i o n s / i,
153+ } ) ;
154+ expect ( savedDefinitionsTab ) . toBeInTheDocument ( ) ;
155+ userEvent . click ( savedDefinitionsTab ) ;
156+ const table = screen . getByRole ( "table" ) ;
157+ expect ( table ) . toBeInTheDocument ( ) ;
158+ expect ( screen . queryByTestId ( "definition-actions" ) ) . not . toBeInTheDocument ( ) ;
159+ } ) ;
160+
155161 it ( "Should render edit definition dialog on edit button click" , async ( ) => {
162+ const getCqlDefinitionReturnTypes = ( ) => {
163+ return {
164+ sdeSex : "PatientCharacteristicSex" ,
165+ } ;
166+ } ;
156167 render (
157168 < DefinitionsSection
158- canEdit = { true }
159- handleApplyDefinition = { jest . fn ( ) }
169+ { ...props }
160170 cqlBuilderLookupsTypes = { cqlBuilderLookup }
161- handleDefinitionDelete = { jest . fn ( ) }
162- isCQLUnchanged
163- setIsCQLUnchanged
171+ getCqlDefinitionReturnTypes = { getCqlDefinitionReturnTypes }
164172 />
165173 ) ;
166174 // go to saved definitions tab
@@ -182,5 +190,7 @@ describe("DefinitionsSection", () => {
182190 expect ( screen . getByTestId ( "definition-name-text-input" ) ) . toHaveValue (
183191 "SDE Sex"
184192 ) ;
193+ const returnType = screen . getByTestId ( "return-type" ) ;
194+ expect ( returnType ) . toHaveTextContent ( getCqlDefinitionReturnTypes ( ) . sdeSex ) ;
185195 } ) ;
186196} ) ;
0 commit comments