Skip to content

Commit

Permalink
DROOLS-7618 : Project Editor: Long description should not freeze the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikkola committed Mar 26, 2024
1 parent a3e1eaf commit d03675f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,7 @@ public class LibraryConstants {

@TranslationKey(defaultValue = "")
public static final String InvalidProjectPath = "InvalidProjectPath";

@TranslationKey(defaultValue = "")
public static String DescriptionTooLong = "DescriptionTooLong";
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public interface View extends SectionView<GeneralSettingsPresenter> {
String getInvalidVersionMessage();

String getDuplicatedProjectNameMessage();

String getDescriptionTooLongMessage();
}


Expand Down Expand Up @@ -179,7 +181,10 @@ public Promise<Object> 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)
);
}

Expand All @@ -205,6 +210,16 @@ Promise<Boolean> validateStringIsNotEmpty(final String string,
});
}

private Promise<Object> validateDescriptionLength() {
return promises.create((resolve, reject) -> {
if(pom.getDescription() != null && pom.getDescription().length() > 3000){
reject.onInvoke(view.getDescriptionTooLongMessage());
} else {
resolve.onInvoke(true);
}
});
}

<T> Promise<Boolean> executeValidation(final Caller<T> caller,
final Function<T, Boolean> call,
final String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit d03675f

Please sign in to comment.