Search in sources :

Example 1 with ValidationService

use of org.linkki.core.binding.validation.ValidationService in project linkki by linkki-framework.

the class OkCancelDialogTest method testValidate_ShowsNoInitialMessages.

@Test
public void testValidate_ShowsNoInitialMessages() {
    MessageList messages = new MessageList();
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
}
Also used : ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 2 with ValidationService

use of org.linkki.core.binding.validation.ValidationService in project linkki by linkki-framework.

the class OkCancelDialogTest method testValidate_FiltersMessages.

@Test
public void testValidate_FiltersMessages() {
    ValidationMarker mandatoryFieldMarker = () -> true;
    Message message = Message.builder("error", ErrorLevel.ERROR).markers(mandatoryFieldMarker).create();
    MessageList messages = new MessageList(message);
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    // mandatory field validations are hidden initially
    assertThat(dialog.getValidationDisplayState(), is(ValidationDisplayState.HIDE_MANDATORY_FIELD_VALIDATIONS));
    MessageList dialogMessage = dialog.validate();
    assertTrue(dialogMessage.isEmpty());
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
    // mandatory field validations are shown after the first click on the OK button
    getOkButton(dialog).click();
    assertThat(dialog.getValidationDisplayState(), is(ValidationDisplayState.SHOW_ALL));
    dialogMessage = dialog.validate();
    assertThat(dialogMessage, contains(message));
    assertThat(dialog, is(displayingMessage("error")));
    assertThat(dialog, is(showingDisabledOkButton()));
}
Also used : Message(org.linkki.core.message.Message) ValidationMarker(org.linkki.util.validation.ValidationMarker) ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 3 with ValidationService

use of org.linkki.core.binding.validation.ValidationService in project linkki by linkki-framework.

the class OkCancelDialogTest method testValidate_ShowsErrorsAndWarning.

@Test
public void testValidate_ShowsErrorsAndWarning() {
    MessageList messages = new MessageList();
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    // MessageList with error and warning: error is displayed, button is disabled
    messages.add(Message.newWarning("warning", "warning"));
    messages.add(Message.newError("error", "error"));
    dialog.validate();
    assertThat(dialog, is(displayingMessage("error")));
    assertThat(dialog, is(showingDisabledOkButton()));
    // MessageList without entries: nothing is displayed, button is enabled
    messages.clear();
    dialog.validate();
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
    // MessageList with warning: warning is displayed, button is enabled
    messages.add(Message.newWarning("warning", "warning"));
    dialog.validate();
    assertThat(dialog, is(displayingMessage("warning")));
    assertThat(dialog, is(showingEnabledOkButton()));
}
Also used : ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ValidationService (org.linkki.core.binding.validation.ValidationService)3 MessageList (org.linkki.core.message.MessageList)3 Message (org.linkki.core.message.Message)1 ValidationMarker (org.linkki.util.validation.ValidationMarker)1