Skip to content

Commit

Permalink
Fixes #32
Browse files Browse the repository at this point in the history
Also added regression e2e test
  • Loading branch information
mstahv committed May 3, 2024
1 parent 05766b6 commit 96f0591
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/main/java/org/vaadin/tinymce/TinyMce.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/vaadin/tinymce/MopoSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

}

0 comments on commit 96f0591

Please sign in to comment.