use of com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData in project flow by vaadin.
the class LitTemplateParserImplTest method getTemplateContent_templateParsedGreedly_rootElementParsed.
@Test
public void getTemplateContent_templateParsedGreedly_rootElementParsed() {
Mockito.when(configuration.isProductionMode()).thenReturn(true);
LitTemplateParser instance = LitTemplateParserImpl.getInstance();
TemplateData templateContent = instance.getTemplateContent(MyGreedyLitElement.class, "my-greedy-element", service);
Assert.assertEquals("Parent element ID not the expected one.", "my-greedy-element", templateContent.getTemplateElement().parent().id());
Assert.assertEquals("Expected template element to have 2 children", 2, templateContent.getTemplateElement().childNodeSize());
Assert.assertEquals("Template element should have contained a div element with the id 'test'", "div", templateContent.getTemplateElement().getElementById("test").tag().toString());
}
use of com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData in project flow by vaadin.
the class LitTemplateParserImplTest method getTemplateContent_localFileTemplateExists_useLocalFileContent.
@Test
public void getTemplateContent_localFileTemplateExists_useLocalFileContent() {
LitTemplateParser instance = LitTemplateParserImpl.getInstance();
TemplateData templateContent = instance.getTemplateContent(MyLitElementView.class, "my-lit-element-view", service);
Assert.assertEquals("Parent element ID not the expected one.", "my-lit-element-view", templateContent.getTemplateElement().parent().id());
Assert.assertEquals("Expected template element to have 3 children", 3, templateContent.getTemplateElement().childNodeSize());
Assert.assertEquals("Template element should have contained a div element with the id 'label'", "div", templateContent.getTemplateElement().getElementById("label").tag().toString());
}
use of com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData in project flow by vaadin.
the class LitTemplateParserImplTest method getTemplateContent_rootElementParsed.
@Test
public void getTemplateContent_rootElementParsed() {
Mockito.when(configuration.isProductionMode()).thenReturn(true);
LitTemplateParser instance = LitTemplateParserImpl.getInstance();
TemplateData templateContent = instance.getTemplateContent(MyLitElement.class, "my-element", service);
Assert.assertEquals("Parent element ID not the expected one.", "my-element", templateContent.getTemplateElement().parent().id());
Assert.assertEquals("Expected template element to have 2 children", 2, templateContent.getTemplateElement().childNodeSize());
Assert.assertEquals("Template element should have contained a div element with the id 'test'", "div", templateContent.getTemplateElement().getElementById("test").tag().toString());
}
use of com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData in project flow by vaadin.
the class LitTemplateDataAnalyzer method parseTemplate.
/**
* Gets the template data for the template initializer.
*
* @return the template data
*/
ParserData parseTemplate() {
TemplateData templateData = parser.getTemplateContent(templateClass, tag, service);
if (templateData == null) {
getLogger().info("Couldn't parse template for {} class. " + "Only specific Lit template format is supported. Please check that your template definition" + " directly contains 'render' method which returns html`_template_content_`.", templateClass);
}
Element templateRoot = templateData == null ? null : templateData.getTemplateElement();
String modulePath = templateData == null ? null : templateData.getModulePath();
IdCollector idExtractor = new IdCollector(templateClass, modulePath, templateRoot);
idExtractor.collectInjectedIds(Collections.emptySet());
return new ParserData(idExtractor.getIdByField(), idExtractor.getTagById(), idExtractor.getAttributes());
}
use of com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData in project flow by vaadin.
the class LitTemplateParserImplTest method getTypescriptTemplateContent_templateExists_getTemplateContent.
@Test
public void getTypescriptTemplateContent_templateExists_getTemplateContent() {
LitTemplateParser instance = LitTemplateParserImpl.getInstance();
TemplateData templateContent = instance.getTemplateContent(MyForm.class, "my-form", service);
Assert.assertEquals("Parent element ID not the expected one.", "my-form", templateContent.getTemplateElement().parent().id());
Assert.assertEquals("Expected template element to have 2 children", 2, templateContent.getTemplateElement().childNodeSize());
Assert.assertEquals("Template element should have contained a div element with the id 'label'", "vaadin-text-field", templateContent.getTemplateElement().getElementById("nameField").tag().toString());
}
Aggregations