From 358daa1f3e1e94e3b736f1f68d6c01896e851974 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Thu, 18 Jul 2024 14:07:00 +1000 Subject: [PATCH] Make sure dev-ui relocation are added to the importmap Signed-off-by: Phillip Kruger --- .../deployment/BuildTimeContentProcessor.java | 2 +- .../vertx/http/devui/DevUIImportmapTest.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devui/DevUIImportmapTest.java diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/BuildTimeContentProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/BuildTimeContentProcessor.java index cd17d2ce3a4fc..21b8a52b7bcc6 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/BuildTimeContentProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/BuildTimeContentProcessor.java @@ -350,7 +350,7 @@ QuteTemplateBuildItem createIndexHtmlTemplate( if (currentImportMap.containsKey(to)) { String newTo = currentImportMap.get(to); - aggregator.addMapping(from, newTo); + currentImportMap.put(from, newTo); } else { log.warn("Could not relocate " + from + " as " + to + " does not exist in the importmap"); } diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devui/DevUIImportmapTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devui/DevUIImportmapTest.java new file mode 100644 index 0000000000000..61c377b9537c6 --- /dev/null +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devui/DevUIImportmapTest.java @@ -0,0 +1,55 @@ +package io.quarkus.vertx.http.devui; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.quarkus.test.QuarkusDevModeTest; +import io.restassured.RestAssured; +import io.restassured.response.Response; + +public class DevUIImportmapTest { + + @RegisterExtension + static final QuarkusDevModeTest config = new QuarkusDevModeTest() + .withEmptyApplication(); + + @Test + public void testImportMap() { + Response response = RestAssured.given() + .when() + .get("q/dev-ui/configuration-form-editor").then() + .statusCode(200) + .extract() + .response(); + + String htmlContent = response.asString(); + Pattern pattern = Pattern.compile("", Pattern.DOTALL); + Matcher matcher = pattern.matcher(htmlContent); + + assertThat("Script tag not found", matcher.find(), is(true)); + String importmapjson = matcher.group(1); + ObjectMapper mapper = new ObjectMapper(); + try { + Map> importsMap = mapper.readValue(importmapjson, Map.class); + Map importMap = importsMap.get("imports"); + assertThat("Normal mapping (@qomponent/qui-badge) not present in the importmap", + importMap.containsKey("@qomponent/qui-badge"), is(true)); + assertThat("Relocated mapping (qui-badge) not present in the importmap", + importMap.containsKey("qui-badge"), is(true)); + } catch (JsonProcessingException ex) { + throw new RuntimeException(ex); + } + + } + +}