Class NumberFieldTester<T extends AbstractNumberField<T,V>,V extends Number>

java.lang.Object
com.vaadin.browserless.ComponentTester<T>
com.vaadin.flow.component.textfield.NumberFieldTester<T,V>
Type Parameters:
T - component type
V - value type
All Implemented Interfaces:
Clickable<T>

public class NumberFieldTester<T extends AbstractNumberField<T,V>,V extends Number> extends ComponentTester<T>
Tester for NumberField components.
Since:
1.0
  • Constructor Details

    • NumberFieldTester

      public NumberFieldTester(T component)
      Wrap given component for testing.
      Parameters:
      component - target component
  • Method Details

    • setValue

      public void setValue(V value)
      Set the given value for the component, as the user would type it.

      A value that violates the component's constraints ? outside min - max, off the step scale, or the empty value on a required field ? is committed all the same, because the browser commits it too and simply leaves the field invalid. Assert that outcome with isValid() instead of expecting this method to throw.

      Parameters:
      value - value to set
      Throws:
      IllegalStateException - if the component is not usable
    • clear

      public void clear()
      Empties the field, as when the user deletes its contents (or clicks the clear button, where one is shown).

      Emptying is something the user can always do, so it needs no clear button: a field may legitimately end up invalid ? a required field, for instance ? once emptied.

      Throws:
      IllegalStateException - if the component is not usable
    • clickClearButton

      public void clickClearButton()
      Empties the field by clicking its clear button, as the user would.

      Unlike clear(), which models selecting the contents and deleting them and is therefore always available, this requires the clear button to be visible ? a hidden clear button is not something the user can click.

      Throws:
      IllegalStateException - if the component is not usable, or its clear button is not visible
    • isValid

      public boolean isValid()
      Checks whether the field is currently valid, running the component's own default validator ? required, min, max and, when it is explicitly set, the step scale ? and honouring an invalid state set from the outside, as a Binder or a custom validator does.

      A field can hold a value that does not satisfy its constraints ? the user can type one, setValue(Number) commits it as the browser does, and the value can also be set on the server or stepped from an unaligned value ? so a test asserting on validation state checks this instead of expecting a value to be refused.

      Returns:
      true if the field is not marked invalid and its current value satisfies the constraints of the field
    • stepUp

      public void stepUp()
      Simulates the user clicking the step up button once.

      The step buttons are only rendered when AbstractNumberField.setStepButtonsVisible(boolean) is enabled, so stepping a field without them throws an IllegalStateException.

      Throws:
      IllegalStateException - if the component is not usable, the step buttons are not visible, or the new value would be outside the min - max range
    • stepUp

      public void stepUp(int times)
      Simulates the user clicking the step up button the given number of times.

      Each click sets the value on its own, so one value change event is fired per click, as in the browser. If a click cannot be performed, the value keeps the steps that were applied before it.

      Parameters:
      times - how many times the step up button is clicked, must be a positive integer
      Throws:
      IllegalArgumentException - if times is not positive
      IllegalStateException - if the component is not usable, the step buttons are not visible, or the new value would be outside the min - max range
    • stepDown

      public void stepDown()
      Simulates the user clicking the step down button once.

      The step buttons are only rendered when AbstractNumberField.setStepButtonsVisible(boolean) is enabled, so stepping a field without them throws an IllegalStateException.

      Throws:
      IllegalStateException - if the component is not usable, the step buttons are not visible, or the new value would be outside the min - max range
    • stepDown

      public void stepDown(int times)
      Simulates the user clicking the step down button the given number of times.

      Each click sets the value on its own, so one value change event is fired per click, as in the browser. If a click cannot be performed, the value keeps the steps that were applied before it.

      Parameters:
      times - how many times the step down button is clicked, must be a positive integer
      Throws:
      IllegalArgumentException - if times is not positive
      IllegalStateException - if the component is not usable, the step buttons are not visible, or the new value would be outside the min - max range