use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldFailWithoutName.
@Test
public void shouldFailWithoutName() throws Exception {
// when
try {
new FormComponentPattern(new ComponentDefinition());
Assert.fail();
} catch (IllegalArgumentException ignored) {
// Success
}
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveValidInstance.
@Test
@SuppressWarnings("unchecked")
public void shouldHaveValidInstance() throws Exception {
// given
InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
TranslationService translationService = mock(TranslationService.class);
ApplicationContext applicationContext = mock(ApplicationContext.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setTranslationService(translationService);
componentDefinition.setApplicationContext(applicationContext);
componentDefinition.setViewDefinition(viewDefinition);
AbstractComponentPattern pattern = new FormComponentPattern(componentDefinition);
ViewEventListenerHook viewEventListenerHook = mock(ViewEventListenerHook.class);
given(viewEventListenerHook.getEventName()).willReturn("save");
pattern.addCustomEvent(viewEventListenerHook);
// when
ComponentState state = pattern.createComponentState(viewDefinitionState);
// then
assertTrue(state instanceof FormComponent);
EventHandlerHolder eventHandlerHolder = (EventHandlerHolder) getField(state, "eventHandlerHolder");
Map<String, List<EventHandlerHolder.EventHandler>> eventHandlers = (Map<String, List<EventHandlerHolder.EventHandler>>) getField(eventHandlerHolder, "eventHandlers");
List<EventHandlerHolder.EventHandler> handlers = eventHandlers.get("save");
assertNotNull(handlers);
assertEquals(2, handlers.size());
assertEquals(viewEventListenerHook, handlers.get(1));
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveName.
@Test
public void shouldHaveName() throws Exception {
// given
ComponentPattern pattern = new FormComponentPattern(getComponentDefinition("testName", null));
// when
String name = pattern.getName();
// then
Assert.assertEquals("testName", name);
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerPatternTest method shouldHaveChildren.
@Test
public void shouldHaveChildren() throws Exception {
// given
AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
ComponentPattern child1 = new TextInputComponentPattern(getComponentDefinition("test1", parent, null));
ComponentPattern child2 = new TextInputComponentPattern(getComponentDefinition("test2", parent, null));
parent.addChild(child1);
parent.addChild(child2);
// when
Map<String, ComponentPattern> children = parent.getChildren();
// then
Assert.assertEquals(2, children.size());
Assert.assertEquals(child1, children.get("test1"));
Assert.assertEquals(child2, children.get("test2"));
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerPatternTest method shouldReturnNullWhenChildNotExist.
@Test
public void shouldReturnNullWhenChildNotExist() throws Exception {
// given
AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
// when
ComponentPattern child = parent.getChild("test3");
// then
Assert.assertNull(child);
}
Aggregations