forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#35841 from mkouba/qute-injectable-fragment
Qute: introduce InjectableFragment
- Loading branch information
Showing
4 changed files
with
157 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...java/io/quarkus/qute/deployment/typesafe/fragment/CheckedTemplateFragmentVariantTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.qute.deployment.typesafe.fragment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.qute.CheckedTemplate; | ||
import io.quarkus.qute.TemplateInstance; | ||
import io.quarkus.qute.Variant; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CheckedTemplateFragmentVariantTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Templates.class, Item.class) | ||
.addAsResource(new StringAsset( | ||
"{#each items}{#fragment id='item'}<p>{it.name}</p>{/fragment}{/each}"), | ||
"templates/CheckedTemplateFragmentVariantTest/items.html") | ||
.addAsResource(new StringAsset( | ||
"{#each items}{#fragment id='item'}{it.name}{/fragment}{/each}"), | ||
"templates/CheckedTemplateFragmentVariantTest/items.txt")); | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
public void testFragment() { | ||
TemplateInstance fragment = Templates.items$item(new Item("Foo")); | ||
List<Variant> variants = (List<Variant>) fragment.getAttribute(TemplateInstance.VARIANTS); | ||
assertEquals(2, variants.size()); | ||
|
||
assertEquals("<p>Foo</p>", | ||
fragment.setAttribute(TemplateInstance.SELECTED_VARIANT, Variant.forContentType("text/html")).render()); | ||
assertEquals("Foo", | ||
fragment.setAttribute(TemplateInstance.SELECTED_VARIANT, Variant.forContentType("text/plain")).render()); | ||
// A variant for application/json does not exist, use the default - html wins | ||
assertEquals("<p>Foo</p>", | ||
fragment.setAttribute(TemplateInstance.SELECTED_VARIANT, Variant.forContentType("application/json")).render()); | ||
} | ||
|
||
@CheckedTemplate | ||
public static class Templates { | ||
|
||
static native TemplateInstance items(List<Item> items); | ||
|
||
static native TemplateInstance items$item(Item it); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters