From d03675fa28391cb9e17a6e10d6c57abccd67d20e Mon Sep 17 00:00:00 2001 From: Toni Rikkola Date: Tue, 26 Mar 2024 20:49:42 +0200 Subject: [PATCH] DROOLS-7618 : Project Editor: Long description should not freeze the UI --- .../resources/i18n/LibraryConstants.java | 3 + .../GeneralSettingsPresenter.java | 17 ++++- .../generalsettings/GeneralSettingsView.java | 5 ++ .../i18n/LibraryConstants.properties | 1 + .../GeneralSettingsPresenterTest.java | 63 +++++++++++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) diff --git a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.java b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.java index 2b4f68bb87e..4c61ec00e3b 100644 --- a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.java +++ b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.java @@ -793,4 +793,7 @@ public class LibraryConstants { @TranslationKey(defaultValue = "") public static final String InvalidProjectPath = "InvalidProjectPath"; + + @TranslationKey(defaultValue = "") + public static String DescriptionTooLong = "DescriptionTooLong"; } diff --git a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenter.java b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenter.java index fe10ad24232..bb2a1294b1b 100644 --- a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenter.java +++ b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenter.java @@ -93,6 +93,8 @@ public interface View extends SectionView { String getInvalidVersionMessage(); String getDuplicatedProjectNameMessage(); + + String getDescriptionTooLongMessage(); } @@ -179,7 +181,10 @@ public Promise validate() { validateStringIsNotEmpty(pom.getGav().getVersion(), view.getEmptyVersionMessage()) .then(o -> executeValidation(s -> s.validateGAVVersion(pom.getGav().getVersion()), view.getInvalidVersionMessage())) - .catch_(this::showErrorAndReject) + .catch_(this::showErrorAndReject), + + + validateDescriptionLength().catch_(this::showErrorAndReject) ); } @@ -205,6 +210,16 @@ Promise validateStringIsNotEmpty(final String string, }); } + private Promise validateDescriptionLength() { + return promises.create((resolve, reject) -> { + if(pom.getDescription() != null && pom.getDescription().length() > 3000){ + reject.onInvoke(view.getDescriptionTooLongMessage()); + } else { + resolve.onInvoke(true); + } + }); + } + Promise executeValidation(final Caller caller, final Function call, final String errorMessage) { diff --git a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsView.java b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsView.java index 737a2da1326..bb7d532b2e8 100644 --- a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsView.java +++ b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsView.java @@ -279,6 +279,11 @@ public String getDuplicatedProjectNameMessage() { return translationService.format(LibraryConstants.DuplicatedProjectName); } + @Override + public String getDescriptionTooLongMessage() { + return translationService.format(LibraryConstants.DescriptionTooLong); + } + @Override public String getTitle() { return title.textContent; diff --git a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/resources/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.properties b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/resources/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.properties index d2365287a13..47ef83ca2e2 100644 --- a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/resources/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.properties +++ b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/main/resources/org/kie/workbench/common/screens/library/client/resources/i18n/LibraryConstants.properties @@ -605,3 +605,4 @@ ViewDeploymentDetails=View deployment details Archetypes=Archetypes ArchetypesDescription=Select all archetypes that will be available as templates for new projects, as well as a default one. This configuration is only applicable to this space. InvalidProjectPath=No project found in the informed path. +DescriptionTooLong=Description is too long. \ No newline at end of file diff --git a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/test/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenterTest.java b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/test/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenterTest.java index 32f4b582a9d..591924e5e95 100644 --- a/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/test/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenterTest.java +++ b/kie-wb-common-screens/kie-wb-common-library/kie-wb-common-library-client/src/test/java/org/kie/workbench/common/screens/library/client/settings/sections/generalsettings/GeneralSettingsPresenterTest.java @@ -295,6 +295,69 @@ public void testValidateWithOneError() { never()).isProjectNameValid(any()); } + @Test + public void testValidateDescriptionDescriptionOk() { + + generalSettingsPresenter.pom = new POM("", + null, + "", + new GAV()); + + doReturn("DescriptionTooLong").when(view).getDescriptionTooLongMessage(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 3000; i++) { + builder.append("x"); + } + generalSettingsPresenter.setDescription(builder.toString()); + + generalSettingsPresenter.validate().then(i -> { + Assert.fail("Promise should've not been resolved!"); + return promises.resolve(); + }); + + verify(generalSettingsPresenter, never()).showErrorAndReject(eq("DescriptionTooLong")); + } + @Test + public void testValidateDescriptionDescriptionNull() { + + generalSettingsPresenter.pom = new POM("", + null, + "", + new GAV()); + + doReturn("DescriptionTooLong").when(view).getDescriptionTooLongMessage(); + + generalSettingsPresenter.validate().then(i -> { + Assert.fail("Promise should've not been resolved!"); + return promises.resolve(); + }); + + verify(generalSettingsPresenter, never()).showErrorAndReject(eq("DescriptionTooLong")); + } + + @Test + public void testValidateDescriptionDescriptionTooLong() { + + generalSettingsPresenter.pom = new POM("", + null, + "", + new GAV()); + + doReturn("DescriptionTooLong").when(view).getDescriptionTooLongMessage(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 3001; i++) { + builder.append("x"); + } + generalSettingsPresenter.setDescription(builder.toString()); + + generalSettingsPresenter.validate().then(i -> { + Assert.fail("Promise should've not been resolved!"); + return promises.resolve(); + }); + + verify(generalSettingsPresenter).showErrorAndReject(eq("DescriptionTooLong")); + } + @Test public void testShowErrorAndRejectWithException() { final RuntimeException testException = new RuntimeException("Test message");