sb.append(getLabel()).append(" ").append(dateWidget.generateHtml(context)); } else { sb.append(checkboxWidget.generateHtml(context));
@Test public void checkboxWidgetShouldProduceHtml() { CheckboxWidget cw = new CheckboxWidget(); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\"/><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); cw.setInitialValue("Something"); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" checked=\"true\"/><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); cw.setLabel("This is a label"); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" checked=\"true\"/><label for=\"w1\">This is a label</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }
@Test public void testHidden() throws Exception { CheckboxWidget cb = new CheckboxWidget(); cb.setLabel("checkboxTextLabel"); cb.setValue("checkboxValue"); cb.setInitialValue(cb); FormEntryContext formEntryContext = mock(FormEntryContext.class); when(formEntryContext.getFieldName(cb)).thenReturn("w1"); String html = cb.generateHtml(formEntryContext); assertThat(html, is("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"checkboxValue\" checked=\"true\"/><label for=\"w1\">checkboxTextLabel</label><input type=\"hidden\" name=\"_w1\"/>")); }
@Test public void testConstructorValue() throws Exception { CheckboxWidget cb = new CheckboxWidget("33"); cb.setLabel("checkboxTextLabel"); cb.setInitialValue(cb); FormEntryContext formEntryContext = mock(FormEntryContext.class); when(formEntryContext.getFieldName(cb)).thenReturn("w1"); String html = cb.generateHtml(formEntryContext); assertThat(cb.getValue(), is("33")); assertThat(cb.getLabel(), is("checkboxTextLabel")); }
ret.append(voidWidget.generateHtml(context));
@Test public void checkboxWidgetShouldProduceHtmlWithToggleSimple() { ToggleWidget toggleWidget = new ToggleWidget("hatColors"); CheckboxWidget cw = new CheckboxWidget("Has a hat?", "true", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" toggleHide=\"hatColors\"/><label for=\"w1\">Has a hat?</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }
@Test public void checkboxWidgetShouldProduceHtmlWithToggleDim() { ToggleWidget toggleWidget = new ToggleWidget("{id: 'hatColors', style: 'dim'}"); CheckboxWidget cw = new CheckboxWidget("Has a hat?", "true", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" toggleDim=\"hatColors\"/><label for=\"w1\">Has a hat?</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }
@Test public void checkboxWidgetShouldProduceHtmlWithToggleHide() { ToggleWidget toggleWidget = new ToggleWidget("{id: 'hatColors', style: 'hide'}"); CheckboxWidget cw = new CheckboxWidget("Has a hat?", "true", toggleWidget.getTargetId(), toggleWidget.isToggleDim()); context.registerWidget(cw); Assert.assertEquals("<input type=\"checkbox\" id=\"w1\" name=\"w1\" value=\"true\" toggleHide=\"hatColors\"/><label for=\"w1\">Has a hat?</label><input type=\"hidden\" name=\"_w1\"/>", cw.generateHtml(context)); }