use of com.vaadin.flow.component.Tag in project flow by vaadin.
the class BootstrapHandlerTest method body_size_adds_styles_for_body.
// 2344
@Test
public void body_size_adds_styles_for_body() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(BodySizeAnnotated.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
Optional<Element> styleTag = allElements.stream().filter(element -> element.tagName().equals("style")).findFirst();
Assert.assertTrue("Expected a style element in head.", styleTag.isPresent());
Assert.assertTrue("The first style tag should start with body style from @BodySize", styleTag.get().toString().startsWith("<style type=\"text/css\">body {height:100vh;width:100vw;margin:0;}"));
}
use of com.vaadin.flow.component.Tag in project flow by vaadin.
the class BootstrapHandlerTest method no_body_size_or_page_configurator_still_adds_margin_for_body.
// 2344
@Test
public void no_body_size_or_page_configurator_still_adds_margin_for_body() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(RootNavigationTarget.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
Optional<Element> styleTag = allElements.stream().filter(element -> element.tagName().equals("style")).findFirst();
Assert.assertTrue("Expected a style element in head.", styleTag.isPresent());
Assert.assertTrue("The first style tag should start with body style containing margin", styleTag.get().toString().startsWith("<style type=\"text/css\">body {margin:0;}"));
}
use of com.vaadin.flow.component.Tag in project flow by vaadin.
the class TemplateInitializer method injectClientSideElement.
private void injectClientSideElement(String tagName, String id, Field field) {
Class<?> fieldType = field.getType();
Tag tag = fieldType.getAnnotation(Tag.class);
if (tag != null && !tagName.equalsIgnoreCase(tag.value())) {
String msg = String.format("Class '%s' has field '%s' whose type '%s' is annotated with " + "tag '%s' but the element defined in the HTML " + "template with id '%s' has tag name '%s'", templateClass.getName(), field.getName(), fieldType.getName(), tag.value(), id, tagName);
throw new IllegalStateException(msg);
}
attachExistingElementById(tagName, id, field);
}
use of com.vaadin.flow.component.Tag in project flow by vaadin.
the class TemplateInitializerTest method setUp.
@Before
public void setUp() throws NoSuchFieldException {
String parentTemplateId = InTemplateClass.class.getAnnotation(Tag.class).value();
assertThat("Both classes should have the same '@Tag' annotation", OutsideTemplateClass.class.getAnnotation(Tag.class).value(), is(parentTemplateId));
String inTemplateElementId = InTemplateClass.class.getField("element").getAnnotation(Id.class).value();
String outsideTemplateElementId = OutsideTemplateClass.class.getField("element").getAnnotation(Id.class).value();
templateParser = (clazz, tag) -> new TemplateData("", Jsoup.parse(String.format("<dom-module id='%s'><template>" + " <template><div id='%s'>Test</div></template>" + " <div id='%s'></div>" + " <div a='{{twoWay}}' b='{{invalid}} syntax' c='{{two.way}}'" + " d='{{invalidSyntax' e='{{withEvent::eventName}}' f='[[oneWay]]'></div>" + "</template></dom-module>", parentTemplateId, inTemplateElementId, outsideTemplateElementId)));
}
use of com.vaadin.flow.component.Tag in project flow by vaadin.
the class HtmlComponentSmokeTest method testStringConstructor.
private static void testStringConstructor(Class<? extends HtmlComponent> clazz) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
try {
String parameterValue = "Lorem";
Constructor<? extends HtmlComponent> constructor = clazz.getConstructor(String.class);
HtmlComponent instance = constructor.newInstance(parameterValue);
if (clazz.getAnnotation(Tag.class) == null) {
Assert.assertEquals(constructor + " should set the tag for a class without @Tag", parameterValue, instance.getElement().getTag());
} else {
Assert.assertEquals(constructor + " should set the text content for a class with @Tag", parameterValue, instance.getElement().getText());
}
} catch (NoSuchMethodException e) {
// No constructor to test
return;
}
}
Aggregations