Add image buttons and exclusive launcher actions
This commit is contained in:
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"));
|
||||
|
||||
@@ -13,6 +13,28 @@ class LayoutValidatorTest {
|
||||
private final LayoutValidator validator = new LayoutValidator();
|
||||
private final JsonMapper mapper = JsonMapper.builder().build();
|
||||
|
||||
@Test
|
||||
void validatesSettingsActionsAndTypedExtras() throws Exception {
|
||||
var json = """
|
||||
{"pages":[{"items":[{"id":"wifi","type":"image","x":0,"y":200,"w":100,"h":100,
|
||||
"payload":{"imageId":"%s","settingsAction":"ACTION_WIFI_SETTINGS",
|
||||
"extras":[{"key":"example","type":"long","value":"9223372036854775807"}]}}]}]}
|
||||
""".formatted("a".repeat(64));
|
||||
var reader = tools.jackson.databind.json.JsonMapper.builder().build();
|
||||
var validator = new LayoutValidator();
|
||||
assertTrue(validator.validate(reader.readTree(json)).stream().noneMatch(i -> i.level().equals("error")));
|
||||
assertTrue(validator.validate(reader.readTree(json.replace("9223372036854775807", "9223372036854775808")))
|
||||
.stream().anyMatch(i -> i.path().endsWith(".extras")));
|
||||
assertTrue(validator.validate(reader.readTree(json.replace("ACTION_WIFI_SETTINGS", "ACTION_CALL")))
|
||||
.stream().anyMatch(i -> i.path().endsWith(".settingsAction")));
|
||||
var component = json.replace("\"settingsAction\":\"ACTION_WIFI_SETTINGS\"", """
|
||||
"launchMode":"component","componentName":"com.example.app/.MainActivity"
|
||||
""".strip());
|
||||
assertTrue(validator.validate(reader.readTree(component)).stream().noneMatch(i -> i.level().equals("error")));
|
||||
assertTrue(validator.validate(reader.readTree(component.replace("/.MainActivity", "")))
|
||||
.stream().anyMatch(i -> i.path().endsWith(".componentName")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void builtInLayoutHasNoErrors() throws Exception {
|
||||
try (var input = new ClassPathResource("launcher/default_layout.json").getInputStream()) {
|
||||
|
||||
Reference in new issue
Block a user