001package react4j;
002
003/**
004 * Utility class for interacting with React4j in tests.
005 */
006public final class ReactTestUtil
007{
008  private ReactTestUtil()
009  {
010  }
011
012  /**
013   * Reset the state of React config to either production or development state.
014   *
015   * @param productionMode true to set it to production mode configuration, false to set it to development mode config.
016   */
017  public static void resetConfig( final boolean productionMode )
018  {
019    if ( ReactConfig.isProductionEnvironment() )
020    {
021      throw new IllegalStateException( "Unable to reset config as React is in production mode" );
022    }
023
024    if ( productionMode )
025    {
026      disableViewNames();
027      noCheckInvariants();
028      minimizeInputKeys();
029      noValidateInputValues();
030      noStoreDebugDataAsState();
031    }
032    else
033    {
034      enableViewNames();
035      checkInvariants();
036      noMinimizeInputKeys();
037      validateInputValues();
038      storeDebugDataAsState();
039    }
040    Contexts.setContextProvider( new Contexts.DefaultContextProvider() );
041    Contexts.clear();
042  }
043
044  /**
045   * Set the `react4j.enable_view_names` setting to {@code true}.
046   */
047  public static void enableViewNames()
048  {
049    setViewEnableNames( true );
050  }
051
052  /**
053   * Set the `react4j.enable_view_names` setting to {@code false}.
054   */
055  public static void disableViewNames()
056  {
057    setViewEnableNames( false );
058  }
059
060  /**
061   * Configure the `react4j.enable_view_names` setting.
062   *
063   * @param setting the setting.
064   */
065  public static void setViewEnableNames( final boolean setting )
066  {
067    ReactConfig.setEnableViewNames( setting );
068  }
069
070  /**
071   * Set the `react4j.minimize_input_keys` setting to {@code true}.
072   */
073  public static void minimizeInputKeys()
074  {
075    ReactConfig.setMinimizeInputKeys( true );
076  }
077
078  /**
079   * Set the `react4j.minimize_input_keys` setting to {@code false}.
080   */
081  public static void noMinimizeInputKeys()
082  {
083    ReactConfig.setMinimizeInputKeys( false );
084  }
085
086  /**
087   * Set the `react4j.validate_input_values` setting to {@code true}.
088   */
089  public static void validateInputValues()
090  {
091    ReactConfig.setShouldValidateInputValues( true );
092  }
093
094  /**
095   * Set the `react4j.validate_input_values` setting to {@code false}.
096   */
097  public static void noValidateInputValues()
098  {
099    ReactConfig.setShouldValidateInputValues( false );
100  }
101
102  /**
103   * Set the `react4j.store_debug_data_as_state` setting to {@code true}.
104   */
105  public static void storeDebugDataAsState()
106  {
107    ReactConfig.setShouldStoreDebugDataAsState( true );
108  }
109
110  /**
111   * Set the `react4j.store_debug_data_as_state` setting to {@code false}.
112   */
113  public static void noStoreDebugDataAsState()
114  {
115    ReactConfig.setShouldStoreDebugDataAsState( false );
116  }
117
118  /**
119   * Set the `react4j.check_invariants` setting to {@code true}.
120   */
121  public static void checkInvariants()
122  {
123    ReactConfig.setCheckInvariants( true );
124  }
125
126  /**
127   * Set the `react4j.check_invariants` setting to {@code false}.
128   */
129  public static void noCheckInvariants()
130  {
131    ReactConfig.setCheckInvariants( false );
132  }
133}