@@ -1449,6 +1449,145 @@ public void gridErrorsTest()
14491449 //TODO: make sure fields turn red as expected
14501450 }
14511451
1452+ /**
1453+ * Verifies the clinremarks Id field read-only + tooltip behavior wired in via the
1454+ * `CaseMgmt` metadata source (onprc_ehr/model/sources/CaseMgmt.js). The source is
1455+ * registered against both ClinicalReportFormType and BehaviorExamFormType, so this
1456+ * test exercises both forms through a shared helper.
1457+ */
1458+ @ Test
1459+ public void testClinremarksIdReadOnlyOnCaseCreated () throws Exception
1460+ {
1461+ goToEHRFolder ();
1462+
1463+ // Verify case open and open & immediately close. Test Exams/Cases and BSU Exam forms.
1464+ verifyClinremarksIdLockOnCaseCreated ("Exams/Cases" , "Clinical" , "Open Case" , CaseEntryPath .MANAGE_CASES_LINK );
1465+ verifyClinremarksIdLockOnCaseCreated ("BSU Exam" , "Behavior" , "Open & Immediately Close" , CaseEntryPath .MANAGE_CASES_LINK );
1466+
1467+ // Top and bottom buttons
1468+ verifyClinremarksIdLockOnCaseCreated ("Exams/Cases" , "Clinical" , "Open Case" , CaseEntryPath .OPEN_MANAGE_TOP );
1469+ verifyClinremarksIdLockOnCaseCreated ("BSU Exam" , "Behavior" , "Open Case" , CaseEntryPath .OPEN_MANAGE_BOTTOM );
1470+ }
1471+
1472+ /** How the test reaches the "create new case" dialog from the data entry form. */
1473+ private enum CaseEntryPath
1474+ {
1475+ /** [Manage Cases] link → "Open Case" split button → "Open <category> Case" menu item. */
1476+ MANAGE_CASES_LINK ,
1477+ /** "Open/Manage <category> Case" button in the Instructions panel at the top of the form. */
1478+ OPEN_MANAGE_TOP ,
1479+ /** "Open/Manage <category> Case" button in the form's docked footer toolbar. */
1480+ OPEN_MANAGE_BOTTOM
1481+ }
1482+
1483+ private void verifyClinremarksIdLockOnCaseCreated (String formLinkLabel , String caseCategory , String openButtonLabel , CaseEntryPath entryPath )
1484+ {
1485+ final String expectedTooltip = "Refresh the form to enter data for a different animal." ;
1486+
1487+ log ("Verifying clinremarks Id read-only on casecreated for form: " + formLinkLabel + " via '" + openButtonLabel + "' (entry: " + entryPath + ")" );
1488+ _helper .goToTaskForm (formLinkLabel , false );
1489+ _ext4Helper .clickExt4Tab ("SOAP" );
1490+
1491+ Ext4FieldRef idField = _helper .getExt4FieldForFormSection ("SOAP" , "Id" );
1492+ Assert .assertNotNull ("Could not locate Id field in SOAP section of form: " + formLinkLabel , idField );
1493+
1494+ idField .setValue (SUBJECTS [0 ]);
1495+
1496+ // Wait for the AnimalDetailsPanel to display the Id
1497+ Ext4FieldRef detailsId = _ext4Helper .queryOne ("displayfield[name=animalId]" , Ext4FieldRef .class );
1498+ Assert .assertNotNull ("AnimalDetailsPanel not rendered (form: " + formLinkLabel + ")" , detailsId );
1499+ waitFor (() -> SUBJECTS [0 ].equals (String .valueOf (detailsId .getValue ())),
1500+ "AnimalDetailsPanel did not display Id " + SUBJECTS [0 ] + " (form: " + formLinkLabel + ")" ,
1501+ WAIT_FOR_JAVASCRIPT );
1502+
1503+ Assert .assertNotEquals ("Id field should be editable before any case is created (form: " + formLinkLabel + ")" ,
1504+ Boolean .TRUE , idField .getEval ("readOnly" ));
1505+ Object preQtip = idField .getEval ("getEl().dom.getAttribute('data-qtip')" );
1506+ assertEquals ("Id field should have no tooltip before any case is created (form: " + formLinkLabel + ")" ,
1507+ "" , preQtip == null ? "" : preQtip .toString ());
1508+
1509+ // Open a real case from the data entry form so ManageCasesPanel fires the real casecreated event
1510+ createCaseFromForm (SUBJECTS [0 ], caseCategory , openButtonLabel , entryPath );
1511+
1512+ waitFor (() -> Boolean .TRUE .equals (idField .getEval ("readOnly" )),
1513+ "Id field did not become read-only after case was opened (form: " + formLinkLabel + ")" ,
1514+ WAIT_FOR_JAVASCRIPT );
1515+ Object postQtip = idField .getEval ("getEl().dom.getAttribute('data-qtip')" );
1516+ assertEquals ("Id field should carry the lock tooltip after case is opened (form: " + formLinkLabel + ")" ,
1517+ expectedTooltip , postQtip == null ? "" : postQtip .toString ());
1518+
1519+ _helper .discardForm ();
1520+ }
1521+
1522+ /**
1523+ * Opens a case for {@code animalId} from the data entry form via the given {@code entryPath}, then
1524+ * closes the resulting Manage Cases window. {@code openButtonLabel} is one of the OpenCaseWindow submit
1525+ * buttons: "Open Case" (just open) or "Open & Immediately Close" (open and immediately close permanently).
1526+ */
1527+ private void createCaseFromForm (String animalId , String caseCategory , String openButtonLabel , CaseEntryPath entryPath )
1528+ {
1529+ Locator .XPathLocator manageCasesWindow = Ext4Helper .Locators .window ("Manage Cases: " + animalId );
1530+ triggerCreateCaseDialog (manageCasesWindow , caseCategory , entryPath );
1531+
1532+ // ManageCasesPanel asks "Open New" vs "Edit Existing" first if an active case of this category
1533+ // already exists for the animal (ManageCasesPanel.js: showCreateWindow). Dismiss with "Open New".
1534+ Locator .XPathLocator existingCaseDialog = Ext4Helper .Locators .window ("Open Case" );
1535+ if (Boolean .TRUE .equals (waitFor (() -> isElementPresent (existingCaseDialog ), 2000 )))
1536+ {
1537+ waitAndClick (existingCaseDialog .append (Ext4Helper .Locators .ext4ButtonEnabled ("Open New" )));
1538+ waitForElementToDisappear (existingCaseDialog );
1539+ }
1540+
1541+ Locator .XPathLocator openCaseWindow = Ext4Helper .Locators .window ("Open Case: " + animalId );
1542+ waitForElement (openCaseWindow );
1543+
1544+ if ("Clinical" .equals (caseCategory ))
1545+ {
1546+ Ext4ComboRef vetField = Ext4ComboRef .getForLabel (this , "Assigned Vet" );
1547+ vetField .waitForStoreLoad ();
1548+ // Pick whichever vet the store has rather than hardcoding a display name; the test only needs the field populated
1549+ vetField .eval ("setValue(arguments[0])" , vetField .getFnEval ("return this.store.getAt(0).get(this.valueField)" ));
1550+ Ext4FieldRef .getForLabel (this , "Problem" ).setValue ("Behavioral" );
1551+ }
1552+ else if ("Behavior" .equals (caseCategory ))
1553+ {
1554+ Ext4FieldRef .getForLabel (this , "Subcategory" ).setValue ("Alopecia" );
1555+ }
1556+
1557+ waitAndClick (openCaseWindow .append (Ext4Helper .Locators .ext4ButtonEnabled (openButtonLabel )));
1558+ if ("Open & Immediately Close" .equals (openButtonLabel ))
1559+ {
1560+ waitAndClick (Ext4Helper .Locators .menuItem ("Close Permanently" ).notHidden ());
1561+ }
1562+ waitForElementToDisappear (openCaseWindow );
1563+
1564+ waitAndClick (manageCasesWindow .append (Ext4Helper .Locators .ext4ButtonEnabled ("Close" )));
1565+ waitForElementToDisappear (manageCasesWindow );
1566+ }
1567+
1568+ private void triggerCreateCaseDialog (Locator .XPathLocator manageCasesWindow , String caseCategory , CaseEntryPath entryPath )
1569+ {
1570+ switch (entryPath )
1571+ {
1572+ case MANAGE_CASES_LINK -> {
1573+ waitAndClick (Locator .linkWithText ("[Manage Cases]" ));
1574+ waitForElement (manageCasesWindow );
1575+ waitAndClick (manageCasesWindow .append (Ext4Helper .Locators .ext4ButtonEnabled ("Open Case" )));
1576+ waitAndClick (Ext4Helper .Locators .menuItem ("Open " + caseCategory + " Case" ).notHidden ());
1577+ }
1578+ case OPEN_MANAGE_TOP -> {
1579+ Locator .XPathLocator instructionsPanel = Locator .tagWithClass ("div" , "x4-panel" ).withChild (
1580+ Locator .tagWithClass ("div" , "x4-panel-header" ).withDescendant (
1581+ Locator .tagWithClass ("span" , "x4-panel-header-text" ).withText ("Instructions" )));
1582+ waitAndClick (instructionsPanel .append (Ext4Helper .Locators .ext4ButtonEnabled ("Open/Manage " + caseCategory + " Case" )));
1583+ }
1584+ case OPEN_MANAGE_BOTTOM -> {
1585+ Locator .XPathLocator footerToolbar = Locator .tagWithClass ("div" , "x4-toolbar-footer" );
1586+ waitAndClick (footerToolbar .append (Ext4Helper .Locators .ext4ButtonEnabled ("Open/Manage " + caseCategory + " Case" )));
1587+ }
1588+ }
1589+ }
1590+
14521591 @ Override
14531592 protected String getAnimalHistoryPath ()
14541593 {
0 commit comments