Skip to content

Commit 0ff384a

Browse files
committed
Merge branch 'LF-3413-cypress-tests' into 'master'
LF-3413 - Cypress tests for LF-3413, 3414, and 3415 changes in the Expression Editor See merge request lfor/formbuilder!122
2 parents 02fcf8d + 76ddae2 commit 0ff384a

5 files changed

Lines changed: 130 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This project follows [Semantic Versioning](http://semver.org/).
44

5+
## [10.3.8] 2025-09-26
6+
### Added
7+
- Added Cypress tests for form and item variables.
8+
59
## [10.3.7] 2025-09-25
610
### Fixed
711
- Lock in @ctrl/ngx-codemirror version to 7.0.0.

cypress/e2e/form-level/form-level.cy.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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();

cypress/e2e/item-level/variable.cy.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,55 @@ describe('Home page', () => {
445445

446446
});
447447
});
448+
449+
it('should not allow saving an item variable with a missing value and display validation error', () => {
450+
// Add a new item under the 'None'.
451+
cy.clickTreeNode('None');
452+
cy.contains('Add new item').scrollIntoView().click();
453+
cy.getItemTextField().clear().type('Variable validation');
454+
cy.selectDataType('integer');
455+
456+
// Click the 'Create/edit variables' button and add two new variables
457+
cy.get('button#editVariables').click();
458+
cy.get('lhc-expression-editor').shadow().within(() => {
459+
cy.get('#expression-editor-base-dialog').should('exist');
460+
461+
// Variables section
462+
cy.get('lhc-variables > h2').should('contain', 'Item Variables');
463+
cy.get('#variables-section .variable-row').should('have.length', 0);
464+
cy.get('lhc-variables div.no-variables').should('contain.text', 'There are currently no variables for this item.');
465+
466+
// Add a new variable 'a'
467+
cy.get('#add-variable').click();
468+
cy.get('#variables-section .variable-row').should('have.length', 1);
469+
cy.get('#variable-label-0').clear().type('a');
470+
cy.get('#variable-type-0').select('Easy Path Expression');
471+
cy.get('input#simple-expression-0').type('10');
472+
473+
// Add a new variable 'b'
474+
cy.get('#add-variable').click();
475+
cy.get('#variables-section .variable-row').should('have.length', 2);
476+
cy.get('#variable-label-1').clear().type('b');
477+
cy.get('#variable-type-1').select('Easy Path Expression');
478+
// Intentionally not filling the value
479+
480+
// Save (Export)
481+
cy.get('#export').click();
482+
483+
// The validation should fail and display the error.
484+
cy.get('input#simple-expression-1')
485+
.should('have.class', 'field-error')
486+
.should('have.class', 'ng-invalid');
487+
488+
// Check for error message in lhc-question with ng-reflect-index="1"
489+
cy.get('lhc-syntax-converter#variable-expression-1').within(() => {
490+
cy.get('div#expression-error > p').should('contain.text', 'Expression is required.');
491+
});
492+
493+
// The Save button should be disabled
494+
cy.get('button#export').should('have.class', 'disabled');
495+
});
496+
});
448497
});
449498
});
450499
});

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "formbuilder-lhcforms",
3-
"version": "10.3.7",
3+
"version": "10.3.8",
44
"description": "Build LHC-Forms and FHIR Questionnaires",
55
"homepage": "https://github.com/lhncbc/formbuilder-lhcforms",
66
"license": "SEE LICENSE IN LICENSE.md",
@@ -65,7 +65,7 @@
6565
"@fortawesome/free-regular-svg-icons": "^6.7.2",
6666
"@fortawesome/free-solid-svg-icons": "^6.7.2",
6767
"@fullcalendar/core": "^6.1.15",
68-
"@lhncbc/expression-editor": "^3.3.0",
68+
"@lhncbc/expression-editor": "~4.0.0",
6969
"@lhncbc/ngx-schema-form": "2.13.1-forked1",
7070
"@ng-bootstrap/ng-bootstrap": "^18.0.0",
7171
"@types/fhir": "^0.0.36",

0 commit comments

Comments
 (0)