From 96f0591d4502d89a4d150adfee492b577479b42e Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 3 May 2024 15:01:42 +0300 Subject: [PATCH] Fixes #32 Also added regression e2e test --- src/main/java/org/vaadin/tinymce/TinyMce.java | 20 +++++++++---------- .../org/vaadin/tinymce/MopoSmokeTest.java | 11 ++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/vaadin/tinymce/TinyMce.java b/src/main/java/org/vaadin/tinymce/TinyMce.java index 7277de8..3eb240a 100644 --- a/src/main/java/org/vaadin/tinymce/TinyMce.java +++ b/src/main/java/org/vaadin/tinymce/TinyMce.java @@ -37,7 +37,9 @@ import elemental.json.JsonObject; import elemental.json.JsonValue; +import java.util.Arrays; import java.util.UUID; +import java.util.stream.Collectors; /** * A Rich Text editor, based on TinyMCE Web Component. @@ -354,21 +356,17 @@ public TinyMce configureMenubar(boolean basicTinyMCE, Menubar... menubars) { createBasicTinyMce(); } - JsonArray jsonArray = config.get("menubar"); - int initialIndex = 0; + String newconfig = Arrays.stream(menubars).map(m -> m.menubarLabel).collect(Collectors.joining(" ")); - if (jsonArray != null) { - initialIndex = jsonArray.length(); + String menubar; + if (config.hasKey("menubar")) { + menubar = config.getString("menubar"); + menubar = menubar + " " + newconfig; } else { - jsonArray = Json.createArray(); - } - - for (int i = 0; i < menubars.length; i++) { - jsonArray.set(initialIndex, menubars[i].menubarLabel); - initialIndex++; + menubar = newconfig; } - config.put("menubar", jsonArray); + config.put("menubar", menubar); return this; } diff --git a/src/test/java/org/vaadin/tinymce/MopoSmokeTest.java b/src/test/java/org/vaadin/tinymce/MopoSmokeTest.java index 11c0442..6fd5398 100644 --- a/src/test/java/org/vaadin/tinymce/MopoSmokeTest.java +++ b/src/test/java/org/vaadin/tinymce/MopoSmokeTest.java @@ -4,8 +4,10 @@ import com.microsoft.playwright.BrowserType; import com.microsoft.playwright.Page; import com.microsoft.playwright.Playwright; +import com.microsoft.playwright.assertions.PlaywrightAssertions; import in.virit.mopo.Mopo; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -53,4 +55,13 @@ public void smokeTest() { }); } + + @Test + public void menuConfig() throws InterruptedException { + String url = "http://localhost:" + port + "/menuconfig"; + page.navigate(url); + PlaywrightAssertions.assertThat(page.locator("button").getByText("File")).isVisible(); + Assertions.assertEquals(0, page.locator("button").getByText("Insert").count()); + } + }