Search in sources :

Example 11 with MainActivity

use of com.google.android.apps.flexbox.MainActivity in project flexbox-layout by google.

the class MainActivityTest method testJustifyContentSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testJustifyContentSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_justify_content));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int spaceBetweenPosition = spinnerAdapter.getPosition(activity.getString(R.string.space_between));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(spaceBetweenPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN));
    final int centerPosition = spinnerAdapter.getPosition(activity.getString(R.string.center));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(centerPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) NavigationView(android.support.design.widget.NavigationView) Spinner(android.widget.Spinner) MainActivity(com.google.android.apps.flexbox.MainActivity) Menu(android.view.Menu) ArrayAdapter(android.widget.ArrayAdapter) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 12 with MainActivity

use of com.google.android.apps.flexbox.MainActivity in project flexbox-layout by google.

the class MainActivityTest method testAlignItemsSpinner.

@Test
@SuppressWarnings("unchecked")
@FlakyTest
public void testAlignItemsSpinner() {
    MainActivity activity = mActivityRule.getActivity();
    FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
    assertNotNull(flexboxLayout);
    NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
    assertNotNull(navigationView);
    Menu menu = navigationView.getMenu();
    final Spinner spinner = (Spinner) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_align_items));
    ArrayAdapter<CharSequence> spinnerAdapter = (ArrayAdapter<CharSequence>) spinner.getAdapter();
    final int baselinePosition = spinnerAdapter.getPosition(activity.getString(R.string.baseline));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(baselinePosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_BASELINE));
    final int flexEndPosition = spinnerAdapter.getPosition(activity.getString(R.string.flex_end));
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(flexEndPosition);
        }
    });
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
}
Also used : FlexboxLayout(com.google.android.flexbox.FlexboxLayout) NavigationView(android.support.design.widget.NavigationView) Spinner(android.widget.Spinner) MainActivity(com.google.android.apps.flexbox.MainActivity) Menu(android.view.Menu) ArrayAdapter(android.widget.ArrayAdapter) FlakyTest(android.support.test.filters.FlakyTest) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

FlakyTest (android.support.test.filters.FlakyTest)12 MediumTest (android.support.test.filters.MediumTest)12 MainActivity (com.google.android.apps.flexbox.MainActivity)12 FlexboxLayout (com.google.android.flexbox.FlexboxLayout)12 Test (org.junit.Test)12 NavigationView (android.support.design.widget.NavigationView)5 Menu (android.view.Menu)5 ArrayAdapter (android.widget.ArrayAdapter)5 Spinner (android.widget.Spinner)5 TextView (android.widget.TextView)4