Search in sources :

Example 1 with LitTemplateParser

use of com.vaadin.flow.component.littemplate.LitTemplateParser 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 LitTemplateParser

use of com.vaadin.flow.component.littemplate.LitTemplateParser 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 LitTemplateParser

use of com.vaadin.flow.component.littemplate.LitTemplateParser in project flow by vaadin.

the class LitTemplateParserImplTest method getTemplateContent_localFileNotFound_returnsNull.

@Test
public void getTemplateContent_localFileNotFound_returnsNull() {
    Mockito.when(configuration.getStringProperty(Mockito.anyString(), Mockito.anyString())).thenReturn("META-INF/resources/foo-bar.json");
    LitTemplateParser instance = LitTemplateParserImpl.getInstance();
    Assert.assertNull(instance.getTemplateContent(FooView.class, "foo-view", service));
}
Also used : LitTemplateParser(com.vaadin.flow.component.littemplate.LitTemplateParser) Test(org.junit.Test)

Example 4 with LitTemplateParser

use of com.vaadin.flow.component.littemplate.LitTemplateParser in project flow by vaadin.

the class LitTemplateParserImplTest method severalJsModuleAnnotations_parserSelectsByName.

@Test
public void severalJsModuleAnnotations_parserSelectsByName() {
    LitTemplateParser instance = LitTemplateParserImpl.getInstance();
    LitTemplateParser.TemplateData templateContent = instance.getTemplateContent(SeveralJsModuleAnnotations.class, "my-lit-element-view", service);
    Assert.assertEquals("Parent element ID not the expected one.", "my-lit-element-view", templateContent.getTemplateElement().parent().id());
    // Two JS module annotations with almost the same content.
    // The first one contains a string "Tag name doesn't match the JS module
    // name", the second one doesn't contain this string.
    // The second module should be chosen since its name matches the tag
    // name
    Assert.assertThat(templateContent.getTemplateElement().html(), CoreMatchers.not(CoreMatchers.containsString("Tag name doesn't match the JS module name")));
}
Also used : TemplateData(com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData) LitTemplateParser(com.vaadin.flow.component.littemplate.LitTemplateParser) Test(org.junit.Test)

Example 5 with LitTemplateParser

use of com.vaadin.flow.component.littemplate.LitTemplateParser 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)

Aggregations

LitTemplateParser (com.vaadin.flow.component.littemplate.LitTemplateParser)8 Test (org.junit.Test)8 TemplateData (com.vaadin.flow.component.littemplate.LitTemplateParser.TemplateData)6