Skip to content

Commit

Permalink
#278 add more module test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
casid committed Sep 30, 2023
1 parent 7183854 commit 9edd8c9
Show file tree
Hide file tree
Showing 26 changed files with 75 additions and 3 deletions.
40 changes: 38 additions & 2 deletions jte/src/test/java/gg/jte/TemplateEngine_ModulesTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gg.jte;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

import java.nio.file.Path;

Expand All @@ -24,8 +25,29 @@ void twoModules() {
}

@Test
void threeModules() {
DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src/test/modules/three-modules/app"));
void twoModulesCycle() {
DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src/test/modules/two-modules-cycle/app"));
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);

Throwable throwable = catchThrowable(() -> templateEngine.render("page.jte", null, new StringOutput()));

assertThat(throwable).isInstanceOf(StackOverflowError.class); // TODO better error message :-D
}

@Test
void threeModulesDifferentAlias() {
DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src/test/modules/three-modules-different-alias/app"));
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);

StringOutput output = new StringOutput();
templateEngine.render("page.jte", null, output);

assertThat(output.toString().trim()).isEqualToNormalizingNewlines("<p>line chart (app)</p>\nline chart (core)");
}

@Test
void threeModulesSameAlias() {
DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src/test/modules/three-modules-same-alias/app"));
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);

StringOutput output = new StringOutput();
Expand All @@ -34,5 +56,19 @@ void threeModules() {
assertThat(output.toString().trim()).isEqualToNormalizingNewlines("<p>line chart (app)</p>\nline chart (core)");
}

@Test
void emptyTopLevelModule() {
DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src/test/modules/empty-top-level-module"));
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);

StringOutput output = new StringOutput();
templateEngine.render("checkout/page.jte", null, output);

assertThat(output.toString().trim()).isEqualToNormalizingNewlines("""
<style>important</style>
<p>line chart (checkout)</p>
line chart (core)""");
}

// TODO adjust precompileAll() and generateAll() to iterate over all module files as well!
}
3 changes: 3 additions & 0 deletions jte/src/test/modules/empty-top-level-module/.jteroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import apexcharts from apexcharts
@import checkout from checkout
@import core from core
2 changes: 2 additions & 0 deletions jte/src/test/modules/empty-top-level-module/checkout/.jteroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import core from ../core
@import apexcharts from ../apexcharts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@template.core.layout(content = @`@template.apexcharts.line-chart("checkout")`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@param String css
<style>${css}</style>
6 changes: 6 additions & 0 deletions jte/src/test/modules/empty-top-level-module/core/layout.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import gg.jte.Content

@param Content content

@template.component.css(css = "important")<p>${content}</p>
@template.apexcharts.line-chart("core")
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@param String name
line chart (${name})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import apexcharts from ../apexcharts
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@param String name
line chart (${name})
2 changes: 2 additions & 0 deletions jte/src/test/modules/three-modules-same-alias/app/.jteroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import core from ../core
@import apexcharts from ../apexcharts
1 change: 1 addition & 0 deletions jte/src/test/modules/three-modules-same-alias/app/page.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@template.core.layout(content = @`@template.apexcharts.line-chart("app")`)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import apexcharts from ../apexcharts
6 changes: 6 additions & 0 deletions jte/src/test/modules/three-modules-same-alias/core/layout.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import gg.jte.Content

@param Content content

<p>${content}</p>
@template.apexcharts.line-chart("core")
1 change: 1 addition & 0 deletions jte/src/test/modules/two-modules-cycle/app/.jteroot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import core from ../core
1 change: 1 addition & 0 deletions jte/src/test/modules/two-modules-cycle/app/page.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@template.core.layout(content = @`App Page`)
1 change: 1 addition & 0 deletions jte/src/test/modules/two-modules-cycle/core/.jteroot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import app from ../app
5 changes: 5 additions & 0 deletions jte/src/test/modules/two-modules-cycle/core/layout.jte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import gg.jte.Content

@param Content content

<p>${content}</p>
1 change: 0 additions & 1 deletion jte/src/test/modules/two-modules/core/.jteroot
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
@import apexcharts from ../apexcharts

0 comments on commit 9edd8c9

Please sign in to comment.