ContractInputToWidgetMapper { public Element toElement(ContractInput contractInput, List<List<Element>> rows) { return contractInput.isMultiple() ? toMultipleComponent(contractInput, rows) : toSimpleComponent(contractInput); } @Inject  ContractInputToWidgetMapper(DimensionFactory dimensionFactory, JacksonObjectMapper objectMapperWrapper); Element toElement(ContractInput contractInput, List<List<Element>> rows); Element toDocument(LeafContractInput contractInput); Container toContainer(NodeContractInput nodeContractInput, List<List<Element>> rows); Component createSubmitButton(ButtonAction actionType); Component createSubmitErrorAlert(); boolean canCreateComponent(ContractInput contractInput); Component createRemoveButton(); Component createAddButton(ContractInput contractInput);  }
@Test public void should_map_input_name_to_a_widget_display_label() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Element element = contractInputToWidgetMapper .toElement(aStringContractInput("aComplicatedCamelCaseInputName"), Collections.<List<Element>> emptyList()); assertThat(element.getPropertyValues().get("label").getValue()).isEqualTo("A Complicated Camel Case Input Name"); }
@Test public void should_map_a_numeric_contract_input_to_an_input_with_number_type() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Element element = contractInputToWidgetMapper.toElement(aLongContractInput("timestamp"), Collections.<List<Element>> emptyList()); assertThat(element.getPropertyValues().get("type").getValue()).isEqualTo("number"); }
@Test public void should_map_a_non_numeric_contract_input_to_an_input_with_text_type() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Element element = contractInputToWidgetMapper.toElement(aStringContractInput("name"), Collections.<List<Element>> emptyList()); assertThat(element.getPropertyValues().get("type").getValue()).isEqualTo("text"); }
@Test public void should_keep_default_placeholder_input_when_contract_input_have_description() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); LeafContractInput contractInput = aStringContractInput("name"); contractInput.setDescription("name of the user"); Element element = contractInputToWidgetMapper.toElement(contractInput, Collections.<List<Element>> emptyList()); assertThat(element.getPropertyValues().get("placeholder").getValue()).isEqualTo(new PbInput().getPlaceholder()); }
@Test public void should_string_contract_input_has_value_configured_on_sentData() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Element element = contractInputToWidgetMapper.toElement(aStringContractInput("firstName"), Collections.<List<Element>> emptyList()); PropertyValue valueParameter = element.getPropertyValues().get("value"); assertThat(valueParameter.getType()).isEqualTo("variable"); assertThat(valueParameter.getValue()).isEqualTo("formInput.firstName"); }
@Test public void should_configure_value_property_of_container_with_$item_when_generating_a_multiple_string_in_a_multiple_node_contract_input() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); ContractInput contractInput = aContractInput("names").mulitple().withType(String.class.getName()).build(); aNodeContractInput("employee").mulitple() .withInput(contractInput).build(); Element container = contractInputToWidgetMapper.toElement(contractInput, new ArrayList<List<Element>>()); assertThat(container).isInstanceOf(Container.class); PropertyValue repeatedCollectionPropetyValue = container.getPropertyValues().get("repeatedCollection"); assertThat(repeatedCollectionPropetyValue.getType()).isEqualTo("variable"); assertThat(repeatedCollectionPropetyValue.getValue()).isEqualTo("$item.names"); }
@Test public void should_string_contract_input_create_an_input_widget_id() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Component element = (Component) contractInputToWidgetMapper.toElement(aStringContractInput("firstName"), Collections.<List<Element>> emptyList()); assertThat(element.getId()).isEqualTo("pbInput"); }
@Test public void should_read_only_string_contract_input_create_an_text_widget_id() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Component element = (Component) contractInputToWidgetMapper.toElement(aReadOnlyStringContractInput("firstName"), Collections.<List<Element>> emptyList()); assertThat(element.getId()).isEqualTo("pbText"); assertThat(element.getPropertyValues().get("allowHtml").getValue()).isEqualTo(true); }
@Test public void should_map_simple_numeric_input_to_an_input_widget_id() throws Exception { ContractInputToWidgetMapper contractInputToWidgetMapper = makeContractInputToWidgetMapper(); Component element = (Component) contractInputToWidgetMapper.toElement(aLongContractInput("updateTime"), Collections.<List<Element>> emptyList()); assertThat(element.getId()).isEqualTo("pbInput"); }