Skip to content

Commit b33f6a6

Browse files
committed
Improve testing.
1 parent 6a5e63a commit b33f6a6

File tree

3 files changed

+56
-42
lines changed

3 files changed

+56
-42
lines changed

.github/workflows/graaljs-micronaut-react-ssr.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ jobs:
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
3131
cache: 'maven'
3232

33-
- name: Build and run Micronaut app
33+
- name: Build, test, and run Micronaut app
3434
run: |
3535
cd graaljs/graaljs-micronaut-react-ssr
36-
./mvnw clean package -DskipTests
37-
./mvnw mn:run &
38-
39-
- name: Verify application is running
40-
run: |
41-
sleep 30
36+
./mvnw --no-transfer-progress clean package
37+
./mvnw --no-transfer-progress mn:run &
38+
mnpid="$!"
39+
sleep 10
4240
curl --fail-with-body --silent --dump-header - -o /dev/null http://localhost:8080
41+
kill $mnpid
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.org/license/UPL.
5+
*/
6+
7+
package com.example;
8+
9+
import io.micronaut.http.client.HttpClient;
10+
import io.micronaut.http.client.annotation.Client;
11+
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
12+
import jakarta.inject.Inject;
13+
import org.junit.jupiter.api.Test;
14+
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
18+
@MicronautTest
19+
public class ReactViewTest {
20+
@Inject
21+
@Client("/")
22+
HttpClient client;
23+
24+
@Test
25+
void rootViewRendersServerSide() {
26+
var html = client.toBlocking().exchange("/", String.class).body();
27+
28+
// Check that title is correctly rendered
29+
assertTrue(html.contains("<title>Recharts Examples</title>"), "Title not set correctly");
30+
31+
// Check the embedded rootProps and rootComponent in the script tag
32+
assertTrue(html.contains("\"rootProps\":{\"width\":500,\"title\":\"Recharts Examples\",\"height\":300,\"url\":\"/\"}"), "rootProps not set correctly");
33+
assertTrue(html.contains("\"rootComponent\":\"App\""), "rootComponent not set correctly");
34+
35+
// Check SVG elements
36+
assertEquals(11, countOccurrences(html, "<svg"), "Number of SVG elements incorrect");
37+
}
38+
39+
private static int countOccurrences(String str, String subStr) {
40+
int count = 0;
41+
int index = 0;
42+
43+
while ((index = str.indexOf(subStr, index)) != -1) {
44+
count++;
45+
index += subStr.length(); // Move past the last found substring
46+
}
47+
48+
return count;
49+
}
50+
}

graaljs/graaljs-micronaut-react-ssr/src/test/java/com/example/RootViewTest.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)