@Test public void testMountedDrawableBounds() { final LithoView lithoView = mountComponent( mContext, new InlineLayoutSpec() { @Override protected Component onCreateLayout(ComponentContext c) { return create(c).widthPx(10).heightPx(10).build(); } }); assertThat(lithoView.getDrawables().get(0).getBounds()).isEqualTo(new Rect(0, 0, 10, 10)); }
private TextDrawable getMountedDrawableForText(CharSequence text) { return (TextDrawable) ComponentTestHelper.mountComponent( mContext, Text.create(mContext) .text(text) .build()) .getDrawables() .get(0); }
10); Drawable drawable1 = lithoView.getDrawables().get(0); Drawable drawable2 = lithoView.getDrawables().get(1); 10); drawable1 = lithoView.getDrawables().get(0); drawable2 = lithoView.getDrawables().get(1);
10); Drawable drawable = lithoView.getDrawables().get(0); assertThat(drawable.getBounds()).isEqualTo(new Rect(10, 0, 20, 10)); 10); drawable = lithoView.getDrawables().get(0); assertThat(drawable.getBounds()).isEqualTo(new Rect(20, 0, 30, 10));
@Test public void testRemountsWithNewInputOnSameLayout() { final LithoView lithoView = mountComponent( mContext, create(mContext) .color(BLACK) .build()); shadowOf(lithoView).callOnAttachedToWindow(); assertThat(lithoView.getDrawables()).hasSize(1); assertThat(((ColorDrawable) lithoView.getDrawables().get(0)).getColor()).isEqualTo(BLACK); lithoView.getComponentTree().setRoot( create(mContext) .color(YELLOW) .build()); assertThat(lithoView.getDrawables()).hasSize(1); assertThat(((ColorDrawable) lithoView.getDrawables().get(0)).getColor()).isEqualTo(YELLOW); } }
10); Drawable drawable = lithoView.getDrawables().get(0); assertThat(drawable.getBounds()).isEqualTo(new Rect(10, 0, 20, 10)); 10); drawable = lithoView.getDrawables().get(0); assertThat(drawable.getBounds()).isEqualTo(new Rect(20, 0, 30, 10));
private TextDrawable getMountedDrawableForTextWithColors( CharSequence text, int color, ColorStateList colorStateList) { Text.Builder builder = Text.create(mContext).text(text); if (color != 0) { builder.textColor(color); } if (colorStateList != null) { builder.textColorStateList(colorStateList); } return (TextDrawable) ComponentTestHelper.mountComponent( mContext, builder.build()) .getDrawables() .get(0); }
assertThat(lithoView.getDrawables().get(0).getBounds()).isEqualTo(new Rect(45, 45, 55, 55));
@Test public void testTouchOffsetChangeHandlerNotFired() { final boolean[] eventFired = new boolean[] {false}; EventHandler<TextOffsetOnTouchEvent> eventHandler = EventHandlerTestHelper.createMockEventHandler( TextOffsetOnTouchEvent.class, new EventHandlerTestHelper.MockEventHandler<TextOffsetOnTouchEvent, Void>() { @Override public Void handleEvent(TextOffsetOnTouchEvent event) { eventFired[0] = true; return null; } }); LithoView lithoView = ComponentTestHelper.mountComponent( mContext, Text.create(mContext) .text("Text2") .textOffsetOnTouchHandler(eventHandler) .build()); TextDrawable textDrawable = (TextDrawable) (lithoView.getDrawables().get(0)); MotionEvent actionUp = MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0); boolean handledActionUp = textDrawable.onTouchEvent(actionUp, lithoView); assertThat(handledActionUp).isFalse(); assertThat(eventFired[0]).isFalse(); MotionEvent actionDown = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 0, 0, 0); boolean handledActionMove = textDrawable.onTouchEvent(actionDown, lithoView); assertThat(handledActionMove).isFalse(); assertThat(eventFired[0]).isFalse(); }
@Test public void testTouchOffsetChangeHandlerFired() { final boolean[] eventFired = new boolean[] {false}; EventHandler<TextOffsetOnTouchEvent> eventHandler = EventHandlerTestHelper.createMockEventHandler( TextOffsetOnTouchEvent.class, new EventHandlerTestHelper.MockEventHandler<TextOffsetOnTouchEvent, Void>() { @Override public Void handleEvent(TextOffsetOnTouchEvent event) { eventFired[0] = true; return null; } }); LithoView lithoView = ComponentTestHelper.mountComponent( mContext, Text.create(mContext) .text("Some text") .textOffsetOnTouchHandler(eventHandler) .build()); TextDrawable textDrawable = (TextDrawable) (lithoView.getDrawables().get(0)); MotionEvent motionEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0); boolean handled = textDrawable.onTouchEvent(motionEvent, lithoView); // We don't consume touch events from TextTouchOffsetChange event assertThat(handled).isFalse(); assertThat(eventFired[0]).isTrue(); }