@Test @FlakyTest(tolerance = TOLERANCE) public void testEditFragment_changeOrder() { MainActivity activity = mActivityRule.getActivity(); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); onView(withId(R.id.textview1)).perform(click()); onView(withId(R.id.edit_text_order)).perform(replaceText("3"), closeSoftKeyboard()); onView(withId(R.id.button_ok)).perform(click()); TextView first = (TextView) flexboxLayout.getReorderedChildAt(0); TextView second = (TextView) flexboxLayout.getReorderedChildAt(1); TextView third = (TextView) flexboxLayout.getReorderedChildAt(2); assertThat(first.getText().toString(), is("2")); assertThat(second.getText().toString(), is("3")); assertThat(third.getText().toString(), is("1")); }
boolean isRepetitive = false; if (description.getAnnotation(FlakyTest.class) != null) { runCount = description.getAnnotation(FlakyTest.class).tolerance(); } else if (description.getAnnotation(RepetitiveTest.class) != null) { runCount = description.getAnnotation(RepetitiveTest.class).numIterations();
@Test @FlakyTest(tolerance = TOLERANCE) public void testOrderAttribute_fromLayoutXml() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_order_test); } }); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertNotNull(flexboxLayout); assertThat(flexboxLayout.getChildCount(), is(4)); // order: -1, index 1 assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2))); // order: 0, index 2 assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3))); // order: 1, index 3 assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(4))); // order: 2, index 0 assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(1))); }
boolean isRepetitive = false; if (description.getAnnotation(FlakyTest.class) != null) { runCount = description.getAnnotation(FlakyTest.class).tolerance(); } else if (description.getAnnotation(RepetitiveTest.class) != null) { runCount = description.getAnnotation(RepetitiveTest.class).numIterations();
@Test @FlakyTest(tolerance = TOLERANCE) public void testRemoveFlexItem() { MainActivity activity = mActivityRule.getActivity(); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); int beforeCount = flexboxLayout.getChildCount(); onView(withId(R.id.remove_fab)).perform(click()); assertThat(flexboxLayout.getChildCount(), is(beforeCount - 1)); }
@Test @FlakyTest(tolerance = TOLERANCE) public void testAddFlexItem() { MainActivity activity = mActivityRule.getActivity(); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); int beforeCount = flexboxLayout.getChildCount(); onView(withId(R.id.add_fab)).perform(click()); assertThat(flexboxLayout.getChildCount(), is(beforeCount + 1)); }
@Test @FlakyTest(tolerance = TOLERANCE) public void testOrderAttribute_fromCode() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity();
@Test @FlakyTest(tolerance = TOLERANCE) public void testLoadFromLayoutXml() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_simple); } }); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE)); assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER)); assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER)); assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER)); assertThat(flexboxLayout.getChildCount(), is(1)); View child = flexboxLayout.getChildAt(0); FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) child.getLayoutParams(); assertThat(lp.order, is(2)); assertThat(lp.flexGrow, is(1f)); assertThat(lp.alignSelf, is(FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH)); }
@Test @FlakyTest(tolerance = TOLERANCE) public void testEditFragment_changeFlexBasisPercent() { MainActivity activity = mActivityRule.getActivity(); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); onView(withId(R.id.textview1)).perform(click()); onView(withId(R.id.edit_text_flex_basis_percent)).perform(replaceText("50"), closeSoftKeyboard()); onView(withId(R.id.button_ok)).perform(click()); TextView first = (TextView) activity.findViewById(R.id.textview1); TextView second = (TextView) activity.findViewById(R.id.textview2); TextView third = (TextView) activity.findViewById(R.id.textview3); assertNotNull(first); assertNotNull(second); assertNotNull(third); assertThat(first.getWidth(), is(flexboxLayout.getWidth() / 2)); } }
@Test @FlakyTest(tolerance = TOLERANCE) public void testConfigurationChange() { MainActivity activity = mActivityRule.getActivity(); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); onView(withId(R.id.add_fab)).perform(click()); onView(withId(R.id.add_fab)).perform(click()); int beforeCount = flexboxLayout.getChildCount(); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); // Verify the flex items are restored across the configuration change. assertThat(flexboxLayout.getChildCount(), is(beforeCount)); }
@Test @SuppressWarnings("unchecked") @FlakyTest(tolerance = TOLERANCE) public void testAlignContentSpinner() { MainActivity activity = mActivityRule.getActivity();
@Test @FlakyTest(tolerance = TOLERANCE) public void testEditFragment_changeFlexGrow() { MainActivity activity = mActivityRule.getActivity(); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertNotNull(flexboxLayout); onView(withId(R.id.textview1)).perform(click()); onView(withId(R.id.edit_text_flex_grow)).perform(replaceText("1"), closeSoftKeyboard()); onView(withId(R.id.button_ok)).perform(click()); TextView first = (TextView) activity.findViewById(R.id.textview1); TextView second = (TextView) activity.findViewById(R.id.textview2); TextView third = (TextView) activity.findViewById(R.id.textview3); assertNotNull(first); assertNotNull(second); assertNotNull(third); assertThat(first.getWidth(), is(flexboxLayout.getWidth() - second.getWidth() - third.getWidth())); }
@Test @SuppressWarnings("unchecked") @FlakyTest(tolerance = TOLERANCE) public void testFlexWrapSpinner() { MainActivity activity = mActivityRule.getActivity();
@Test @SuppressWarnings("unchecked") @FlakyTest(tolerance = TOLERANCE) public void testJustifyContentSpinner() { MainActivity activity = mActivityRule.getActivity();
@Test @SuppressWarnings("unchecked") @FlakyTest(tolerance = TOLERANCE) public void testAlignItemsSpinner() { MainActivity activity = mActivityRule.getActivity();
@Test @SuppressWarnings("unchecked") @FlakyTest(tolerance = TOLERANCE) public void testFlexDirectionSpinner() { MainActivity activity = mActivityRule.getActivity();
@Test @FlakyTest(tolerance = TOLERANCE) public void testFlexItem_match_parent() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_flex_item_match_parent); } }); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); TextView text1 = (TextView) activity.findViewById(R.id.text1); TextView text2 = (TextView) activity.findViewById(R.id.text2); TextView text3 = (TextView) activity.findViewById(R.id.text3); assertThat(text1.getWidth(), is(flexboxLayout.getWidth())); assertThat(text2.getWidth(), is(flexboxLayout.getWidth())); assertThat(text3.getWidth(), is(flexboxLayout.getWidth())); assertThat(flexboxLayout.getHeight(), is(text1.getHeight() + text2.getHeight() + text3.getHeight())); }
@Test @FlakyTest(tolerance = TOLERANCE) public void testFlexItem_match_parent_flexDirection_column() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_flex_item_match_parent_direction_column); FlexboxLayout flexboxLayout = (FlexboxLayout) activity .findViewById(R.id.flexbox_layout); flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN); } }); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); TextView text1 = (TextView) activity.findViewById(R.id.text1); TextView text2 = (TextView) activity.findViewById(R.id.text2); TextView text3 = (TextView) activity.findViewById(R.id.text3); assertThat(text1.getHeight(), is(flexboxLayout.getHeight())); assertThat(text2.getHeight(), is(flexboxLayout.getHeight())); assertThat(text3.getHeight(), is(flexboxLayout.getHeight())); assertThat(flexboxLayout.getWidth(), is(text1.getWidth() + text2.getWidth() + text3.getWidth())); }
@Test @FlakyTest(tolerance = TOLERANCE) public void testAlignItems_baseline() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_align_items_baseline_test); } }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); TextView textView1 = (TextView) activity.findViewById(R.id.text1); TextView textView2 = (TextView) activity.findViewById(R.id.text2); TextView textView3 = (TextView) activity.findViewById(R.id.text3); int topPluBaseline1 = textView1.getTop() + textView1.getBaseline(); int topPluBaseline2 = textView2.getTop() + textView2.getBaseline(); int topPluBaseline3 = textView3.getTop() + textView3.getBaseline(); assertThat(topPluBaseline1, is(topPluBaseline2)); assertThat(topPluBaseline2, is(topPluBaseline3)); }
@Test @FlakyTest(tolerance = TOLERANCE) public void testAlignItems_baseline_wrapReverse() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_align_items_baseline_test); FlexboxLayout flexboxLayout = (FlexboxLayout) activity .findViewById(R.id.flexbox_layout); flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE); } }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); TextView textView1 = (TextView) activity.findViewById(R.id.text1); TextView textView2 = (TextView) activity.findViewById(R.id.text2); TextView textView3 = (TextView) activity.findViewById(R.id.text3); int bottomPluBaseline1 = textView1.getBottom() + textView1.getBaseline(); int bottomPluBaseline2 = textView2.getBottom() + textView2.getBaseline(); int bottomPluBaseline3 = textView3.getBottom() + textView3.getBaseline(); assertThat(bottomPluBaseline1, is(bottomPluBaseline2)); assertThat(bottomPluBaseline2, is(bottomPluBaseline3)); }