This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable client side validation on setRequiredIndicatorVisible (#202) (F…
…ixes #179)
- Loading branch information
Showing
5 changed files
with
196 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/com/vaadin/flow/component/combobox/test/RequiredComboboxIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2000-2018 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.component.combobox.test; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.component.combobox.testbench.ComboBoxElement; | ||
import com.vaadin.flow.testutil.AbstractComponentIT; | ||
import com.vaadin.flow.testutil.TestPath; | ||
import com.vaadin.testbench.TestBenchElement; | ||
|
||
@TestPath("required-combobox") | ||
public class RequiredComboboxIT extends AbstractComponentIT { | ||
|
||
@Test | ||
public void serverSideValidation_persistsOnBlur() { | ||
open(); | ||
|
||
ComboBoxElement comboBox = $(ComboBoxElement.class).first(); | ||
|
||
// Select an invalid item | ||
comboBox.openPopup(); | ||
executeScript( | ||
"arguments[0].selectedItem = arguments[0].filteredItems[0]", | ||
comboBox); | ||
|
||
// The validation shows errors | ||
assertValidationError(comboBox); | ||
|
||
TestBenchElement msg = $(TestBenchElement.class).id("message"); | ||
Assert.assertEquals("Value changed from 'null' to 'foo'", | ||
msg.getText()); | ||
|
||
// blur | ||
msg.click(); | ||
|
||
// validation error is still shown | ||
assertValidationError(comboBox); | ||
|
||
// change the item to a valid one | ||
comboBox.openPopup(); | ||
executeScript( | ||
"arguments[0].selectedItem = arguments[0].filteredItems[1]", | ||
comboBox); | ||
|
||
// no invalid attribute | ||
Assert.assertEquals(Boolean.FALSE.toString(), | ||
comboBox.getAttribute("invalid")); | ||
// the error message is not visible | ||
TestBenchElement error = comboBox.$("vaadin-text-field").first() | ||
.$(TestBenchElement.class).id("vaadin-text-field-error-0"); | ||
waitUntil(driver -> error.getSize().getHeight() == 0); | ||
} | ||
|
||
private void assertValidationError(ComboBoxElement comboBox) { | ||
Assert.assertEquals(Boolean.TRUE.toString(), | ||
comboBox.getAttribute("invalid")); | ||
|
||
TestBenchElement error = comboBox.$("vaadin-text-field").first() | ||
.$(TestBenchElement.class).id("vaadin-text-field-error-0"); | ||
Assert.assertTrue(error.getSize().getHeight() > 0); | ||
Assert.assertEquals("'foo' is invalid value", error.getText()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/com/vaadin/flow/component/combobox/test/RequiredComboboxPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2000-2018 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.component.combobox.test; | ||
|
||
import com.vaadin.flow.component.combobox.ComboBox; | ||
import com.vaadin.flow.component.combobox.bean.TestItem; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.data.binder.Binder; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("required-combobox") | ||
public class RequiredComboboxPage extends Div { | ||
|
||
public RequiredComboboxPage() { | ||
Div message = new Div(); | ||
message.setId("message"); | ||
|
||
Binder<TestItem> binder = new Binder<>(); | ||
|
||
ComboBox<String> comboBox = new ComboBox<>(); | ||
comboBox.setItems("foo", "bar"); | ||
comboBox.addValueChangeListener(event -> message | ||
.setText(String.format("Value changed from '%s' to '%s'", | ||
event.getOldValue(), event.getValue()))); | ||
|
||
binder.forField(comboBox).asRequired() | ||
.withValidator(value -> !"foo".equals(value), | ||
"'foo' is invalid value") | ||
.bind(TestItem::getName, TestItem::setName); | ||
TestItem item = new TestItem(0); | ||
binder.setBean(item); | ||
|
||
add(comboBox, message); | ||
} | ||
} |