Add image buttons and exclusive launcher actions

This commit is contained in:
tongtong committed 2026-11-27 21:31:23 +08:00
1 parent 8d604a5807
commit 74c725e8d7
23 files changed
+871 -107

No files matched your search

@@ -34,6 +34,41 @@ class LayoutApiTest {
@TempDir Path dir;
@Test
void imageUploadCanBePublishedAndFetchedByDevice() throws Exception {
Path database = dir.resolve("images.sqlite");
MockMvc mvc = mvc(database);
var pixels = new java.awt.image.BufferedImage(2, 2, java.awt.image.BufferedImage.TYPE_INT_ARGB);
var output = new java.io.ByteArrayOutputStream();
javax.imageio.ImageIO.write(pixels, "png", output);
byte[] png = output.toByteArray();
mvc.perform(post("/api/admin/images").header("Authorization", DEVICE).content(png))
.andExpect(status().isUnauthorized());
var response = mvc.perform(post("/api/admin/images").header("Authorization", ADMIN)
.contentType("image/png").content(png)).andExpect(status().isOk()).andReturn().getResponse();
String id = mapper.readTree(response.getContentAsString()).path("id").stringValue();
mvc.perform(get("/api/images/" + id)).andExpect(status().isUnauthorized());
mvc(database).perform(get("/api/images/" + id).header("Authorization", DEVICE))
.andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith("image/png"))
.andExpect(content().bytes(png));
var current = mvc.perform(get(ADMIN_LAYOUT).header("Authorization", ADMIN))
.andReturn().getResponse();
String tag = current.getHeader("ETag");
var body = """
{"iconStyle":"system","pages":[{"items":[
{"id":"picture","type":"image","x":12,"y":150,"w":100,"h":100,
"payload":{"imageId":"%s","package":"org.example.app"}}
]}]}
""";
mvc.perform(put(ADMIN_LAYOUT).header("Authorization", ADMIN).header("If-Match", tag)
.contentType(MediaType.APPLICATION_JSON).content(body.formatted("0".repeat(64))))
.andExpect(status().is(422));
mvc.perform(put(ADMIN_LAYOUT).header("Authorization", ADMIN).header("If-Match", tag)
.contentType(MediaType.APPLICATION_JSON).content(body.formatted(id)))
.andExpect(status().isOk());
}
@Test
void layoutEventStreamRequiresDeviceToken() throws Exception {
MockMvc mvc = mvc(dir.resolve("events.sqlite"));