@@ -640,7 +640,7 @@ describe('Home page', () => {
640640 cy . get ( '#expression-editor-base-dialog' ) . should ( 'exist' ) ;
641641
642642 // Variables section
643- cy . get ( 'lhc-variables > h2' ) . should ( 'contain' , 'Item Variables' ) ;
643+ cy . get ( 'lhc-variables > h2' ) . should ( 'contain' , 'Form Variables' ) ;
644644 cy . get ( '#variables-section .variable-row' ) . should ( 'have.length' , 0 ) ;
645645
646646 // Add a new variable 'a_fhir_exp'
@@ -707,9 +707,70 @@ describe('Home page', () => {
707707 cy . get ( '@variable4' ) . eq ( 1 ) . should ( 'have.text' , 'Easy Path Expression' ) ;
708708 cy . get ( '@variable4' ) . eq ( 2 ) . should ( 'have.text' , "1" ) ;
709709 } ) ;
710+
711+ it ( 'should not allow saving a form-level variable with a missing value and display validation error' , ( ) => {
712+ // Click the 'Create/edit variables' button and add two new variables
713+ cy . get ( 'button#editVariables' ) . click ( ) ;
714+ cy . get ( 'lhc-expression-editor' ) . shadow ( ) . within ( ( ) => {
715+ cy . get ( '#expression-editor-base-dialog' ) . should ( 'exist' ) ;
716+
717+ // Variables section
718+ cy . get ( 'lhc-variables > h2' ) . should ( 'contain' , 'Form Variables' ) ;
719+ cy . get ( '#variables-section .variable-row' ) . should ( 'have.length' , 0 ) ;
720+ cy . get ( 'lhc-variables div.no-variables' ) . should ( 'contain.text' , 'There are currently no variables for this form.' ) ;
721+
722+ // Add a new variable 'a'
723+ cy . get ( '#add-variable' ) . click ( ) ;
724+ cy . get ( '#variables-section .variable-row' ) . should ( 'have.length' , 1 ) ;
725+ cy . get ( '#variable-label-0' ) . clear ( ) . type ( 'a' ) ;
726+ cy . get ( '#variable-type-0' ) . select ( 'Easy Path Expression' ) ;
727+ cy . get ( 'input#simple-expression-0' ) . type ( '10' ) ;
728+
729+ // Add a new variable 'b'
730+ cy . get ( '#add-variable' ) . click ( ) ;
731+ cy . get ( '#variables-section .variable-row' ) . should ( 'have.length' , 2 ) ;
732+ cy . get ( '#variable-label-1' ) . clear ( ) . type ( 'b' ) ;
733+ cy . get ( '#variable-type-1' ) . select ( 'Easy Path Expression' ) ;
734+ // Intentioanlly not filling the value
735+
736+ // Save (Export)
737+ cy . get ( '#export' ) . click ( ) ;
738+
739+ // The validation should fail and display the error.
740+ cy . get ( 'input#simple-expression-1' )
741+ . should ( 'have.class' , 'field-error' )
742+ . should ( 'have.class' , 'ng-invalid' ) ;
743+
744+ // Check for error message in lhc-question with ng-reflect-index="1"
745+ cy . get ( 'lhc-syntax-converter#variable-expression-1' ) . within ( ( ) => {
746+ cy . get ( 'div#expression-error > p' ) . should ( 'contain.text' , 'Expression is required.' ) ;
747+ } ) ;
748+
749+ // The Save button should be disabled
750+ cy . get ( 'button#export' ) . should ( 'have.class' , 'disabled' ) ;
751+
752+ // Populate the missing value
753+ cy . get ( 'input#simple-expression-1' ) . type ( '11' ) ;
754+
755+ // The error should go away.
756+ cy . get ( 'input#simple-expression-1' )
757+ . should ( 'not.have.class' , 'field-error' )
758+ . should ( 'not.have.class' , 'ng-invalid' ) ;
759+
760+ // Check for error message in lhc-question with ng-reflect-index="1"
761+ cy . get ( 'lhc-syntax-converter#variable-expression-1' ) . within ( ( ) => {
762+ cy . get ( 'div#expression-error' ) . should ( 'not.exist' ) ;
763+ } ) ;
764+
765+ // Save (Export)
766+ cy . get ( '#export' ) . click ( ) ;
767+ } ) ;
768+ } ) ;
710769 } ) ;
711770 } ) ;
712771
772+
773+
713774 it ( 'should display variables at the Questionnaire level' , ( ) => {
714775 cy . get ( 'input[type="radio"][value="existing"]' ) . click ( ) ;
715776 cy . get ( 'input[type="radio"][value="local"]' ) . click ( ) ;
0 commit comments