Skip to content

Commit

Permalink
Merge branch 'main' into feat/big-decimal-field/remove-validated-event
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Oct 17, 2023
2 parents 997e98b + d0534af commit eebf3c8
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ <P> TextFieldBase(TValue initialValue, TValue defaultValue,
super("value", defaultValue, elementPropertyType, presentationToModel,
modelToPresentation);
if ((getElement().getProperty("value") == null
|| !isInitialValueOptional) && initialValue != null) {
|| !isInitialValueOptional)) {
setPresentationValue(initialValue);
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ <P> TextFieldBase(TValue initialValue, TValue defaultValue,
super("value", defaultValue, elementPropertyType, presentationToModel,
modelToPresentation);
if ((getElement().getProperty("value") == null
|| !isInitialValueOptional) && initialValue != null) {
|| !isInitialValueOptional)) {
setPresentationValue(initialValue);
}
}
Expand Down Expand Up @@ -377,7 +377,7 @@ <P> TextFieldBase(TValue initialValue, TValue defaultValue,
boolean acceptNullValues, boolean isInitialValueOptional) {
super("value", defaultValue, acceptNullValues);
if ((getElement().getProperty("value") == null
|| !isInitialValueOptional) && initialValue != null) {
|| !isInitialValueOptional)) {
setPresentationValue(initialValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@
package com.vaadin.flow.component.textfield.tests;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaLabel;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.shared.HasTooltip;
import com.vaadin.flow.component.shared.InputField;
import com.vaadin.flow.component.textfield.BigDecimalField;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.ThemeList;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.math.BigDecimal;
import java.util.Locale;
Expand Down Expand Up @@ -52,9 +60,41 @@ public void setValueNull() {

@Override
@Test
public void initialValuePropertyValue() {
assertEquals(field.getEmptyValue(),
field.getElement().getProperty("value"));
public void initialValueIsNotSpecified_valuePropertyHasEmptyString() {
BigDecimalField bigDecimalField = new BigDecimalField();
Assert.assertNull(bigDecimalField.getValue());
Assert.assertEquals("",
bigDecimalField.getElement().getProperty("value"));
}

@Override
@Test
public void initialValueIsNull_valuePropertyHasEmptyString() {
}

@Override
@Test
public void createElementWithValue_createComponentInstanceFromElement_valuePropertyMatchesValue() {
Element element = new Element("vaadin-big-decimal-field");
element.setProperty("value", "1");
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);

Instantiator instantiator = Mockito.mock(Instantiator.class);

Mockito.when(service.getInstantiator()).thenReturn(instantiator);

Mockito.when(instantiator.createComponent(BigDecimalField.class))
.thenAnswer(invocation -> new BigDecimalField());

BigDecimalField bigDecimalField = Component.from(element,
BigDecimalField.class);
Assert.assertEquals("1",
bigDecimalField.getElement().getProperty("value"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@
package com.vaadin.flow.component.textfield.tests;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaLabel;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.shared.HasAllowedCharPattern;
import com.vaadin.flow.component.shared.HasTooltip;
import com.vaadin.flow.component.shared.InputField;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.ThemeList;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -52,9 +60,39 @@ public void setValueNull() {
}

@Test
public void initialValuePropertyValue() {
public void initialValueIsNotSpecified_valuePropertyHasEmptyString() {
EmailField emailField = new EmailField();
assertEquals(emailField.getEmptyValue(),
Assert.assertEquals("", emailField.getValue());
Assert.assertEquals("", emailField.getElement().getProperty("value"));
}

@Test
public void initialValueIsNull_valuePropertyHasEmptyString() {
EmailField emailField = new EmailField((String) null);
Assert.assertEquals("", emailField.getValue());
Assert.assertEquals("", emailField.getElement().getProperty("value"));
}

@Test
public void createElementWithValue_createComponentInstanceFromElement_valuePropertyMatchesValue() {
Element element = new Element("vaadin-email-field");
element.setProperty("value", "[email protected]");
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);

Instantiator instantiator = Mockito.mock(Instantiator.class);

Mockito.when(service.getInstantiator()).thenReturn(instantiator);

Mockito.when(instantiator.createComponent(EmailField.class))
.thenAnswer(invocation -> new EmailField());

EmailField emailField = Component.from(element, EmailField.class);
Assert.assertEquals("[email protected]",
emailField.getElement().getProperty("value"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@
package com.vaadin.flow.component.textfield.tests;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaLabel;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.shared.HasTooltip;
import com.vaadin.flow.component.shared.InputField;
import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.ThemeList;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class IntegerFieldTest extends TextFieldTest {
Expand Down Expand Up @@ -59,9 +66,39 @@ public void assertStepGreaterThanZero() {

@Override
@Test
public void initialValuePropertyValue() {
assertEquals(field.getEmptyValue(),
field.getElement().getProperty("value"));
public void initialValueIsNotSpecified_valuePropertyHasEmptyString() {
IntegerField integerField = new IntegerField();
Assert.assertNull(integerField.getValue());
Assert.assertEquals("", integerField.getElement().getProperty("value"));
}

@Override
@Test
public void initialValueIsNull_valuePropertyHasEmptyString() {
}

@Override
@Test
public void createElementWithValue_createComponentInstanceFromElement_valuePropertyMatchesValue() {
Element element = new Element("vaadin-integer-field");
element.setProperty("value", "1");
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);

Instantiator instantiator = Mockito.mock(Instantiator.class);

Mockito.when(service.getInstantiator()).thenReturn(instantiator);

Mockito.when(instantiator.createComponent(IntegerField.class))
.thenAnswer(invocation -> new IntegerField());

IntegerField integerField = Component.from(element, IntegerField.class);
Assert.assertEquals("1",
integerField.getElement().getProperty("value"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
*/
package com.vaadin.flow.component.textfield.tests;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaLabel;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.shared.HasAllowedCharPattern;
import com.vaadin.flow.component.shared.HasTooltip;
import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.ThemeList;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.Arrays;

Expand Down Expand Up @@ -51,9 +59,38 @@ public void setValueNull() {

@Override
@Test
public void initialValuePropertyValue() {
assertEquals(field.getEmptyValue(),
field.getElement().getProperty("value"));
public void initialValueIsNotSpecified_valuePropertyHasEmptyString() {
NumberField numberField = new NumberField();
Assert.assertNull(numberField.getValue());
Assert.assertEquals("", numberField.getElement().getProperty("value"));
}

@Override
@Test
public void initialValueIsNull_valuePropertyHasEmptyString() {
}

@Override
@Test
public void createElementWithValue_createComponentInstanceFromElement_valuePropertyMatchesValue() {
Element element = new Element("vaadin-number-field");
element.setProperty("value", "1");
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);

Instantiator instantiator = Mockito.mock(Instantiator.class);

Mockito.when(service.getInstantiator()).thenReturn(instantiator);

Mockito.when(instantiator.createComponent(NumberField.class))
.thenAnswer(invocation -> new NumberField());

NumberField numberField = Component.from(element, NumberField.class);
Assert.assertEquals("1", numberField.getElement().getProperty("value"));
}

@Test(expected = IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
package com.vaadin.flow.component.textfield.tests;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasAriaLabel;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.shared.HasAllowedCharPattern;
import com.vaadin.flow.component.shared.InputField;
import com.vaadin.flow.component.textfield.PasswordField;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.dom.ThemeList;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -51,9 +59,42 @@ public void setValueNull() {
}

@Test
public void initialValuePropertyValue() {
public void initialValueIsNotSpecified_valuePropertyHasEmptyString() {
PasswordField passwordField = new PasswordField();
assertEquals(passwordField.getEmptyValue(),
Assert.assertEquals("", passwordField.getValue());
Assert.assertEquals("",
passwordField.getElement().getProperty("value"));
}

@Test
public void initialValueIsNull_valuePropertyHasEmptyString() {
PasswordField passwordField = new PasswordField((String) null);
Assert.assertEquals("", passwordField.getValue());
Assert.assertEquals("",
passwordField.getElement().getProperty("value"));
}

@Test
public void createElementWithValue_createComponentInstanceFromElement_valuePropertyMatchesValue() {
Element element = new Element("vaadin-password-field");
element.setProperty("value", "test");
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);

Instantiator instantiator = Mockito.mock(Instantiator.class);

Mockito.when(service.getInstantiator()).thenReturn(instantiator);

Mockito.when(instantiator.createComponent(PasswordField.class))
.thenAnswer(invocation -> new PasswordField());

PasswordField passwordField = Component.from(element,
PasswordField.class);
Assert.assertEquals("test",
passwordField.getElement().getProperty("value"));
}

Expand Down
Loading

0 comments on commit eebf3c8

Please sign in to comment.