@Test public void encounterTypeTag_shouldAutoSelectTheDefaultEncounterTypeIfAny() throws Exception { String htmlform = "<htmlform><encounterType default=\"07000be2-26b6-4cce-8b40-866d8435b613\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay() .indexOf("<option value=\"\">htmlformentry.chooseEncounterType</option>") > -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option selected=\"true\" value=\"2\">Emergency</option>") > -1); } }
@Test public void encounterProviderTag_shouldDisplayEnterOptionIfTypeIsSetToAutocomplete() throws Exception { String htmlform = "<htmlform><encounterProvider type=\"autocomplete\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option value=\"\" selected=\"true\">htmlformentry.chooseAProvider</option>") == -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("placeholder=\"htmlformentry.form.value.placeholder\"") > -1); }
@Test public void encounterProviderTag_shouldDisplaySelectInputByDefaultIfAnIvalidTypeValueIsEntered() throws Exception { String htmlform = "<htmlform><encounterProvider type=\"invalid\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option value=\"\" selected=\"true\">htmlformentry.chooseAProvider</option>") > -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("placeholder=\"htmlformentry.form.value.placeholder\"") == -1); }
@Test public void encounterLocationTag_shouldDisplaySelectInputByDefaultIfAnIvalidTypeValueIsEntered() throws Exception { String htmlform = "<htmlform><encounterLocation type=\"invalid\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option value=\"\" selected=\"true\">htmlformentry.chooseALocation</option>") > -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("placeholder=\"htmlformentry.form.value.placeholder\"") == -1); }
@Test public void encounterProviderTag_shouldNotSelectAnythingByDefaultIfNothingIsSpecified() throws Exception { String htmlform = "<htmlform><encounterProvider/></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Matcher matcher = Pattern.compile("<option.+?value=\"(.+?)\".+?selected=\"true\".*?>").matcher(session.getHtmlToDisplay()); Assert.assertFalse(matcher.find()); }
@Test public void encounterLocationTag_shouldNotSelectAnythingByDefaultIfNothingIsSpecified() throws Exception { String htmlform = "<htmlform><encounterLocation /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Matcher matcher = Pattern.compile("<option.+?value=\"(.+?)\".+?selected=\"true\".*?>").matcher(session.getHtmlToDisplay()); Assert.assertFalse(matcher.find()); }
@Test public void encounterLocationTag_shouldSupportDefaultSelectByDeafultLocation() throws Exception { String htmlform = "<htmlform><encounterLocation default=\"SystemDefault\"/></htmlform>"; FormEntrySession session = new FormEntrySession(null,htmlform,null); log.debug(session.getHtmlToDisplay()); TestUtil.assertFuzzyContains("<option value=\"1\" selected=\"true\">Unknown Location</option>", session.getHtmlToDisplay()); }
@Test public void shouldSetDefaultDatetimeValue() throws Exception { String htmlform = "<htmlform><obs conceptId=\"1119\" defaultDatetime=\"2011-02-02-00-00\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("2011-02-02")); }
@Test public void shouldSupportCheckboxForNumericObs() throws Exception { String htmlform = "<htmlform><obs conceptId=\"2\" answer=\"8\" answerLabel=\"Eight\" style=\"checkbox\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("<input type=\"checkbox\" id=\"w2\" name=\"w2\" value=\"8.0\"/>")); }
@Test public void shouldSetDefaultBooleanValueToFalse() throws Exception { LogicUtil.registerDefaultRules(); String htmlform = "<htmlform><obs conceptId=\"4\" defaultValue=\"false\" style=\"no_yes_dropdown\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("<option value=\"false\" selected=\"true\">")); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfSpecifiedInvalidState() throws Exception { String htmlform = "<htmlform><workflowState workflowId=\"100\" stateId=\"invalid\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfNoStatesAndStateLabels() throws Exception { String startState = "Transition to start state"; String htmlform = "<htmlform><workflowState workflowId=\"100\" stateLabels=\"" + startState + "\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfStateLabelsAndStateLabel() throws Exception { String startState = "Transition to start state"; String htmlform = "<htmlform><workflowState workflowId=\"100\" stateId=\"" + START_STATE + "\" stateLabel=\"" + startState + "\" stateLabels=\"" + startState + "\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test public void shouldDisplayOnlySpecifiedStateAndDefaultToCheckbox() throws Exception { String htmlform = "<htmlform><workflowState workflowId=\"100\" stateId=\"" + START_STATE + "\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertPresent(session, START_STATE); assertNotPresent(session, MIDDLE_STATE); assertNotPresent(session, END_STATE); Assert.assertTrue("Checkbox result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("checkbox")); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfTooManyStateLabels() throws Exception { transitionToState(START_STATE); String startState = "Transition to start state"; String htmlform = "<htmlform><workflowState workflowId=\"100\" stateIds=\"" + START_STATE + "," + END_STATE + "\" stateLabels=\"" + startState + ",someState,someOtherState\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test @Verifies(value = "should close br tags", method = "doStartTag(FormEntrySession,PrintWriter,Node,Node)") public void doStartTag_shouldCloseBrTags() throws Exception { LogicUtil.registerDefaultRules(); String htmlform = "<htmlform><section><span></span><br/><h1></h1></section></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); String html = session.getHtmlToDisplay(); Assert.assertTrue("<br/> should be closed with one tag", html.contains("<br/>")); Assert.assertTrue("<span> and other tags can be open", html.contains("<span></span>")); Assert.assertTrue("<h1> and other tags can be open", html.contains("<h1></h1>")); }
@Test @Verifies(value = "should return correct xml after apply excludeIf tag", method = "applyExcludes(FormEntrySession,String)") public void applyExcludes_shouldReturnCorrectXmlAfterApplyExcludeIfTag() throws Exception { LogicUtil.registerDefaultRules(); String htmlform = "<htmlform><excludeIf logicTest=\"GENDER = F\">This shows a logic test for a woman</excludeIf><excludeIf logicTest=\"GENDER = M\">This shows a logic test for a man</excludeIf></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); Assert.assertEquals("<div class=\"htmlform\">This shows a logic test for a woman</div>", session.getHtmlToDisplay()); }
@Test public void shouldDisplayLocationValuePropertyAccessor() throws Exception { String htmlform = "<htmlform><encounterLocation/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); session.getHtmlToDisplay(); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['encounterLocation.value'\\]", session.getFieldAccessorJavascript()); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['encounterLocation.error'\\]", session.getFieldAccessorJavascript()); }
@Test public void shouldDisplayDatePropertyAccessorUsingCustomName() throws Exception { String htmlform = "<htmlform><encounterDate id=\"myEncounter\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); session.getHtmlToDisplay(); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.value'\\]", session.getFieldAccessorJavascript()); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.error'\\]", session.getFieldAccessorJavascript()); }
@Test public void shouldDisplayEncounterTypeValuePropertyAccessorUsingCustomName() throws Exception { String htmlform = "<htmlform><encounterType id=\"myEncounter\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); session.getHtmlToDisplay(); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.value'\\]", session.getFieldAccessorJavascript()); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.error'\\]", session.getFieldAccessorJavascript()); }