Skip to content

Commit

Permalink
Make sure dev-ui relocation are added to the importmap
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Jul 18, 2024
1 parent 75cf0bf commit 358daa1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<script type=\"importmap\">(.*?)</script>", 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<String, Map<String, String>> importsMap = mapper.readValue(importmapjson, Map.class);
Map<String, String> 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);
}

}

}

0 comments on commit 358daa1

Please sign in to comment.