Search in sources :

Example 1 with TemplateData

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());
}
Also used : TemplateData(com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData) LitTemplateParser(com.vaadin.flow.component.littemplate.LitTemplateParser) Test(org.junit.Test)

Example 2 with TemplateData

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());
}
Also used : TemplateData(com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData) LitTemplateParser(com.vaadin.flow.component.littemplate.LitTemplateParser) Test(org.junit.Test)

Example 3 with TemplateData

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());
}
Also used : TemplateData(com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData) LitTemplateParser(com.vaadin.flow.component.littemplate.LitTemplateParser) Test(org.junit.Test)

Example 4 with TemplateData

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());
}
Also used : TemplateData(com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData) Element(org.jsoup.nodes.Element) ParserData(com.vaadin.flow.component.template.internal.ParserData) IdCollector(com.vaadin.flow.component.template.internal.IdCollector)

Example 5 with TemplateData

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());
}
Also used : TemplateData(com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData) LitTemplateParser(com.vaadin.flow.component.littemplate.LitTemplateParser) Test(org.junit.Test)

Aggregations

TemplateData (com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData)5 LitTemplateParser (com.vaadin.flow.component.littemplate.LitTemplateParser)4 Test (org.junit.Test)4 IdCollector (com.vaadin.flow.component.template.internal.IdCollector)1 ParserData (com.vaadin.flow.component.template.internal.ParserData)1 Element (org.jsoup.nodes.Element)1