Skip to content

Commit

Permalink
Fix test expectation
Browse files Browse the repository at this point in the history
Add file for cleanup
add test for file creation and generated content
  • Loading branch information
caalador committed Sep 12, 2024
1 parent 2a23488 commit 2ef97f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ private void cleanup() throws ExecutionFailedException {
FLOW_REACT_ADAPTER_TSX);
File frontendGeneratedFolderRoutesTsx = new File(
frontendGeneratedFolder, FrontendUtils.ROUTES_TSX);
File layoutsJson = new File(frontendGeneratedFolder, LAYOUTS_JSON);
FileUtils.deleteQuietly(flowTsx);
FileUtils.deleteQuietly(layoutsJson);
FileUtils.deleteQuietly(vaadinReactTsx);
FileUtils.deleteQuietly(reactAdapterTsx);
FileUtils.deleteQuietly(frontendGeneratedFolderRoutesTsx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.router.Layout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLayout;
import com.vaadin.flow.server.ExecutionFailedException;
import com.vaadin.flow.server.frontend.scanner.ClassFinder;
import com.vaadin.tests.util.MockOptions;
Expand Down Expand Up @@ -82,6 +84,27 @@ public void reactFilesAreWrittenToFrontend()
"routes.tsx").exists());
Assert.assertFalse("Missing ./frontend/routes.tsx",
new File(frontend, "routes.tsx").exists());
Assert.assertTrue(
"Missing ./frontend/" + FrontendUtils.GENERATED
+ "layouts.json",
new File(new File(frontend, FrontendUtils.GENERATED),
"layouts.json").exists());
}

@Test
public void layoutsJson_containsExpectedPaths()
throws ExecutionFailedException, IOException {
Mockito.when(options.getClassFinder().getAnnotatedClasses(Layout.class))
.thenReturn(Collections.singleton(TestLayout.class));

TaskGenerateReactFiles task = new TaskGenerateReactFiles(options);
task.execute();

String layoutsContent = FileUtils.readFileToString(
new File(options.getFrontendGeneratedFolder(), "layouts.json"));

Assert.assertEquals("[{\"path\":\"/test\"}]", layoutsContent);

}

@Test
Expand Down Expand Up @@ -555,4 +578,9 @@ public void routesContainExport_oneSingleExport_exceptionThrown()
@Route("test")
private class TestRoute extends Component {
}

@Tag("div")
@Layout("/test")
private class TestLayout extends Component implements RouterLayout {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.internal.Template;
import com.vaadin.flow.router.HasErrorParameter;
import com.vaadin.flow.router.Layout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.LoadDependenciesOnStartup;
import com.vaadin.flow.server.PWA;
Expand Down Expand Up @@ -69,7 +70,8 @@ public void applicableClasses_knownClasses() {
CssImport.Container.class, Theme.class, NoTheme.class,
HasErrorParameter.class, PWA.class, AppShellConfigurator.class,
Template.class, LoadDependenciesOnStartup.class,
Component.class, TypeScriptBootstrapModifier.class);
Component.class, TypeScriptBootstrapModifier.class,
Layout.class);

for (Class<?> clz : classes) {
assertTrue("should be a known class " + clz.getName(),
Expand Down

0 comments on commit 2ef97f8

Please sign in to comment.