Search in sources :

Example 1 with ModelWithDataBindingBindingModel_

use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ in project epoxy by airbnb.

the class DataBindingModelIntegrationTest method createDataBindingModel.

@Test
public void createDataBindingModel() {
    SimpleEpoxyController controller = new SimpleEpoxyController();
    ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().stringValue("hello").id(1);
    controller.setModels(Collections.singletonList(firstModel));
    ControllerLifecycleHelper lifecycleHelper = new ControllerLifecycleHelper();
    EpoxyViewHolder viewHolder = lifecycleHelper.createViewHolder(controller.getAdapter(), 0);
    controller.getAdapter().onBindViewHolder(viewHolder, 0);
    DataBindingHolder dataBindingHolder = ((DataBindingHolder) viewHolder.objectToBind());
    assertNotNull(dataBindingHolder.getDataBinding());
    // Check that the requiredText was set on the view
    assertEquals(firstModel.stringValue(), ((Button) viewHolder.itemView).getText());
    ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().stringValue("hello again").id(1);
    controller.setModels(Collections.singletonList(secondModel));
    List<Object> payloads = DiffPayloadTestUtil.payloadsWithChangedModels(firstModel);
    controller.getAdapter().onBindViewHolder(viewHolder, 0, payloads);
    // Check that the requiredText was updated after the change payload
    assertEquals(secondModel.stringValue(), ((Button) viewHolder.itemView).getText());
}
Also used : DataBindingHolder(com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder) ModelWithDataBindingBindingModel_(com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_) Test(org.junit.Test)

Example 2 with ModelWithDataBindingBindingModel_

use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ in project epoxy by airbnb.

the class DataBindingModelIntegrationTest method typesWithOutHashCodeAreNotDiffed.

@Test
public void typesWithOutHashCodeAreNotDiffed() {
    SimpleEpoxyController controller = new SimpleEpoxyController();
    AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
    controller.getAdapter().registerAdapterDataObserver(observerMock);
    ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().clickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    }).id(1);
    controller.setModels(Collections.singletonList(firstModel));
    verify(observerMock).onItemRangeInserted(0, 1);
    ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().clickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    }).id(1);
    controller.setModels(Collections.singletonList(secondModel));
    verifyNoMoreInteractions(observerMock);
}
Also used : OnClickListener(android.view.View.OnClickListener) ModelWithDataBindingBindingModel_(com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_) View(android.view.View) AdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver) Test(org.junit.Test)

Example 3 with ModelWithDataBindingBindingModel_

use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ in project epoxy by airbnb.

the class DataBindingModelIntegrationTest method fullyCreateDataBindingModel.

@Test
public void fullyCreateDataBindingModel() {
    SimpleEpoxyController controller = new SimpleEpoxyController();
    ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().stringValue("hello").id(1);
    controller.setModels(Collections.singletonList(firstModel));
    ControllerLifecycleHelper lifecycleHelper = new ControllerLifecycleHelper();
    EpoxyViewHolder viewHolder = lifecycleHelper.createViewHolder(controller.getAdapter(), 0);
    controller.getAdapter().onBindViewHolder(viewHolder, 0);
    DataBindingHolder dataBindingHolder = ((DataBindingHolder) viewHolder.objectToBind());
    assertNotNull(dataBindingHolder.getDataBinding());
    // Check that the requiredText was set on the view
    assertEquals(firstModel.stringValue(), ((Button) viewHolder.itemView).getText());
    ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().stringValue("hello again").id(1);
    controller.setModels(Collections.singletonList(secondModel));
    List<Object> payloads = DiffPayloadTestUtil.payloadsWithChangedModels(firstModel);
    controller.getAdapter().onBindViewHolder(viewHolder, 0, payloads);
    // Check that the requiredText was updated after the change payload
    assertEquals(secondModel.stringValue(), ((Button) viewHolder.itemView).getText());
}
Also used : DataBindingHolder(com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder) ModelWithDataBindingBindingModel_(com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_) Test(org.junit.Test)

Example 4 with ModelWithDataBindingBindingModel_

use of com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_ in project epoxy by airbnb.

the class DataBindingModelIntegrationTest method typesWithHashCodeAreDiffed.

@Test
public void typesWithHashCodeAreDiffed() {
    SimpleEpoxyController controller = new SimpleEpoxyController();
    AdapterDataObserver observerMock = mock(AdapterDataObserver.class);
    controller.getAdapter().registerAdapterDataObserver(observerMock);
    ModelWithDataBindingBindingModel_ firstModel = new ModelWithDataBindingBindingModel_().stringValue("value1").id(1);
    controller.setModels(Collections.singletonList(firstModel));
    verify(observerMock).onItemRangeInserted(0, 1);
    ModelWithDataBindingBindingModel_ secondModel = new ModelWithDataBindingBindingModel_().stringValue("value2").id(1);
    controller.setModels(Collections.singletonList(secondModel));
    verify(observerMock).onItemRangeChanged(eq(0), eq(1), any());
    verifyNoMoreInteractions(observerMock);
}
Also used : ModelWithDataBindingBindingModel_(com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_) AdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver) Test(org.junit.Test)

Aggregations

ModelWithDataBindingBindingModel_ (com.airbnb.epoxy.integrationtest.ModelWithDataBindingBindingModel_)4 Test (org.junit.Test)4 AdapterDataObserver (androidx.recyclerview.widget.RecyclerView.AdapterDataObserver)2 DataBindingHolder (com.airbnb.epoxy.DataBindingEpoxyModel.DataBindingHolder)2 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1