use of io.jmix.ui.util.OperationResult in project jmix by jmix-framework.
the class StandardEditor method commitChanges.
/**
* Validates screen and commits data context.
*
* @return operation result
*/
protected OperationResult commitChanges() {
ValidationErrors validationErrors = validateScreen();
if (!validationErrors.isEmpty()) {
ScreenValidation screenValidation = getApplicationContext().getBean(ScreenValidation.class);
screenValidation.showValidationErrors(this, validationErrors);
return OperationResult.fail();
}
Runnable standardCommitAction = () -> {
EntitySet committedEntities = getScreenData().getDataContext().commit();
InstanceContainer<T> container = getEditedEntityContainer();
if (container instanceof HasLoader) {
DataLoader loader = ((HasLoader) container).getLoader();
if (loader instanceof InstanceLoader) {
@SuppressWarnings("rawtypes") InstanceLoader instanceLoader = (InstanceLoader) loader;
if (instanceLoader.getEntityId() == null) {
committedEntities.optional(getEditedEntity()).ifPresent(entity -> instanceLoader.setEntityId(EntityValues.getId(entity)));
}
}
}
fireEvent(AfterCommitChangesEvent.class, new AfterCommitChangesEvent(this));
};
BeforeCommitChangesEvent beforeEvent = new BeforeCommitChangesEvent(this, standardCommitAction);
fireEvent(BeforeCommitChangesEvent.class, beforeEvent);
if (beforeEvent.isCommitPrevented()) {
if (beforeEvent.getCommitResult() != null) {
return beforeEvent.getCommitResult();
}
return OperationResult.fail();
}
standardCommitAction.run();
return OperationResult.success();
}
use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.
the class CancelEditorInteractionTest method when_interactionIsPerformed_then_screenIsCanceledAndNothingIsCommitted.
@Test
void when_interactionIsPerformed_then_screenIsCanceledAndNothingIsCommitted(UiTestAPI uiTestAPI) {
// given:
StandardEditorTestAPI<Veterinarian, VeterinarianEdit> visitEdit = uiTestAPI.openStandardEditor(Veterinarian.class, VeterinarianEdit.class);
// and:
visitEdit.interact(enter(textInputField("firstNameField"), "Oak"));
// when:
final OperationResult operationResult = visitEdit.andThenGet(cancelEditor());
// then:
assertThat(operationResult).isEqualTo(OperationResult.success());
// and:
assertThat(dataManager.load(Veterinarian.class).all().list()).isEmpty();
}
use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.
the class CloseEditorInteractionTest method given_validForm_when_interactionIsPerformed_then_screenIsClosedAndSuccessIsReturned.
@Test
void given_validForm_when_interactionIsPerformed_then_screenIsClosedAndSuccessIsReturned(UiTestAPI uiTestAPI) {
// given:
StandardEditorTestAPI<Veterinarian, VeterinarianEdit> visitEdit = uiTestAPI.openStandardEditor(Veterinarian.class, VeterinarianEdit.class);
// and:
visitEdit.interact(enter(textInputField("firstNameField"), "Oak"));
// when:
final OperationResult operationResult = visitEdit.andThenGet(closeEditor());
// then:
assertThat(operationResult).isEqualTo(OperationResult.success());
}
use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.
the class CloseInputDialogInteractionTest method when_interactionIsPerformed_then_inputDialogIsClosedAndSuccessIsReturned.
@Test
void when_interactionIsPerformed_then_inputDialogIsClosedAndSuccessIsReturned(UiTestAPI uiTestAPI) {
// given:
final String pikachuIdentifier = "025";
final Pet pikachu = storePikachu(pikachuIdentifier);
// and:
openPetByIdInputDialog(uiTestAPI);
// when:
final InputDialogTestAPI openedInputDialog = uiTestAPI.getOpenedInputDialog();
// and:
final OperationResult operationResult = openedInputDialog.interact(enter(textInputField("id"), pikachuIdentifier)).andThenGet(closeInputDialogWith(InputDialog.INPUT_DIALOG_OK_ACTION));
// then:
assertThat(operationResult).isEqualTo(OperationResult.success());
// and: after the input dialog, the Pet editor is opened
final StandardEditorTestAPI<Pet, PetEdit> openedPetEditor = uiTestAPI.getOpenedEditorScreen(PetEdit.class);
final Pet pet = openedPetEditor.get(editedEntity());
assertThat(pet).isEqualTo(pikachu);
}
use of io.jmix.ui.util.OperationResult in project jmix-sneferu by mariodavid.
the class CreateVisitTest method aVisitCanBeCreated_whenAllFieldsAreFilled.
@Test
void aVisitCanBeCreated_whenAllFieldsAreFilled(UiTestAPI uiTestAPI) {
// given:
final Pet pikachu = dataManager.create(Pet.class);
pikachu.setName("Pikachu");
pikachu.setIdentificationNumber("025");
final Pet savedPikachu = dataManager.save(pikachu);
// and:
final StandardLookupTestAPI<Visit, VisitBrowse> visitBrowse = uiTestAPI.openStandardLookup(Visit.class, VisitBrowse.class);
visitBrowse.interact(click(button("createBtn")));
// when:
final StandardEditorTestAPI<Visit, VisitEdit> visitEdit = uiTestAPI.getOpenedEditorScreen(VisitEdit.class);
OperationResult outcome = (OperationResult) visitEdit.interact(enter(dateField("visitStartField"), LocalDateTime.now())).interact(enter(textField("descriptionField"), "Regular Visit")).interact(select(comboBox("typeField"), VisitType.REGULAR_CHECKUP)).interact(select(entityComboBox("petField"), savedPikachu)).andThenGet(closeEditor());
// then:
assertThat(outcome).isEqualTo(OperationResult.success());
// and:
assertThat(uiTestAPI.isActive(visitEdit)).isFalse();
}
Aggregations