use of org.eclipse.sirius.components.forms.Group in project sirius-components by eclipse-sirius.
the class PageAssert method matchesRecursively.
public PageAssert matchesRecursively(Page page, IdPolicy idPolicy) {
if (page != null) {
this.isNotNull();
if (idPolicy == IdPolicy.WITH_ID) {
assertThat(this.actual.getId()).isEqualTo(page.getId());
}
assertThat(this.actual.getLabel()).isEqualTo(page.getLabel());
if (this.actual.getGroups().size() == page.getGroups().size()) {
int size = this.actual.getGroups().size();
for (int i = 0; i < size; i++) {
Group actualGroup = this.actual.getGroups().get(i);
Group group = page.getGroups().get(i);
assertThat(actualGroup).matchesRecursively(group, idPolicy);
}
}
}
return this;
}
use of org.eclipse.sirius.components.forms.Group in project sirius-components by eclipse-sirius.
the class EditSelectEventHandlerTests method testSelectEdition.
@Test
public void testSelectEdition() {
// $NON-NLS-1$
String id = "Select id";
// $NON-NLS-1$
var input = new EditSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "false");
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<String, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
SelectOption trueOption = // $NON-NLS-1$
SelectOption.newSelectOption("true").label(// $NON-NLS-1$
"True").build();
SelectOption falseOption = // $NON-NLS-1$
SelectOption.newSelectOption("false").label(// $NON-NLS-1$
"False").build();
Select select = Select.newSelect(id).label(// $NON-NLS-1$
"label").value(// $NON-NLS-1$
"true").newValueHandler(newValueHandler).options(List.of(trueOption, falseOption)).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(select)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(select);
}
};
EditSelectEventHandler handler = new EditSelectEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditSelectSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.Group in project sirius-components by eclipse-sirius.
the class EditTextfieldEventHandlerTests method testTextfieldEdition.
@Test
public void testTextfieldEdition() {
// $NON-NLS-1$
String id = "Textfield id";
// $NON-NLS-1$
var input = new EditTextfieldInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, "New value");
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<String, IStatus> newValueHandler = newValue -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
Textfield textfield = Textfield.newTextfield(id).label(// $NON-NLS-1$
"label").value(// $NON-NLS-1$
"Previous value").newValueHandler(newValueHandler).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(textfield)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(textfield);
}
};
EditTextfieldEventHandler handler = new EditTextfieldEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditTextfieldSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.Group in project sirius-components by eclipse-sirius.
the class DeleteListItemEventHandlerTests method testListItemDeletion.
@Test
public void testListItemDeletion() {
// $NON-NLS-1$
String listId = "List id";
// $NON-NLS-1$
String listItemId = "element id to delete";
// $NON-NLS-1$
String changeKind = "delete something";
// $NON-NLS-1$
String changeDescriptionParameterKey = "change_description_parameter_key";
Map<String, Object> parameters = new HashMap<>();
parameters.put(changeDescriptionParameterKey, listItemId);
var input = new DeleteListItemInput(UUID.randomUUID(), FORM_ID.toString(), UUID.randomUUID().toString(), listId, listItemId);
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Supplier<IStatus> deleteHandler = () -> {
hasBeenExecuted.set(true);
return new Success(changeKind, parameters);
};
// @formatter:off
ListItem listItem = ListItem.newListItem(listItemId).deletable(true).deleteHandler(deleteHandler).imageURL(// $NON-NLS-1$
"").kind(// $NON-NLS-1$
"Diagram").label(// $NON-NLS-1$
"empty representation").build();
List list = List.newList(listId).diagnostics(Collections.emptyList()).items(Collections.singletonList(listItem)).label(// $NON-NLS-1$
"").build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(Collections.singletonList(list)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(Collections.singletonList(group)).build();
Form form = Form.newForm(FORM_ID.toString()).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(Collections.singletonList(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(list);
}
};
DeleteListItemEventHandler handler = new DeleteListItemEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(changeKind);
Map<String, Object> changeDescriptionParameters = changeDescription.getParameters();
assertThat(changeDescriptionParameters.get(changeDescriptionParameterKey)).isEqualTo(listItemId);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(DeleteListItemSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
use of org.eclipse.sirius.components.forms.Group in project sirius-components by eclipse-sirius.
the class EditMultiSelectEventHandlerTests method testMultiSelectEdition.
@Test
public void testMultiSelectEdition() {
// $NON-NLS-1$
String id = "MultiSelect id";
// $NON-NLS-1$ //$NON-NLS-2$
var input = new EditMultiSelectInput(UUID.randomUUID(), UUID.randomUUID().toString(), FORM_ID, id, List.of("true", "false"));
AtomicBoolean hasBeenExecuted = new AtomicBoolean();
Function<List<String>, IStatus> newValuesHandler = newValues -> {
hasBeenExecuted.set(true);
return new Success();
};
// @formatter:off
SelectOption trueOption = // $NON-NLS-1$
SelectOption.newSelectOption("true").label(// $NON-NLS-1$
"True").build();
SelectOption falseOption = // $NON-NLS-1$
SelectOption.newSelectOption("false").label(// $NON-NLS-1$
"False").build();
MultiSelect multiSelect = MultiSelect.newMultiSelect(id).label(// $NON-NLS-1$
"label").values(List.of()).newValuesHandler(newValuesHandler).options(List.of(trueOption, falseOption)).diagnostics(List.of()).build();
Group group = // $NON-NLS-1$
Group.newGroup("groupId").label(// $NON-NLS-1$
"group label").widgets(List.of(multiSelect)).build();
Page page = // $NON-NLS-1$
Page.newPage("pageId").label(// $NON-NLS-1$
"page label").groups(List.of(group)).build();
Form form = Form.newForm(FORM_ID).targetObjectId(// $NON-NLS-1$
"targetObjectId").descriptionId(UUID.randomUUID()).label(// $NON-NLS-1$
"form label").pages(List.of(page)).build();
// @formatter:on
IFormQueryService formQueryService = new IFormQueryService.NoOp() {
@Override
public Optional<AbstractWidget> findWidget(Form form, String widgetId) {
return Optional.of(multiSelect);
}
};
EditMultiSelectEventHandler handler = new EditMultiSelectEventHandler(formQueryService, new ICollaborativeFormMessageService.NoOp(), new SimpleMeterRegistry());
assertThat(handler.canHandle(input)).isTrue();
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer();
One<IPayload> payloadSink = Sinks.one();
handler.handle(payloadSink, changeDescriptionSink, form, input);
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst();
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE);
IPayload payload = payloadSink.asMono().block();
assertThat(payload).isInstanceOf(EditMultiSelectSuccessPayload.class);
assertThat(hasBeenExecuted.get()).isTrue();
}
Aggregations