-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
formula-android/src/test/java/com/instacart/formula/android/ViewFactoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.instacart.formula.android | ||
|
||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.common.truth.Truth.assertThat | ||
import com.instacart.testutils.android.NoOpFeatureFactory | ||
import com.instacart.testutils.android.TestFormulaActivity | ||
import com.instacart.testutils.android.TestKey | ||
import com.instacart.testutils.android.showFragment | ||
import com.instacart.testutils.android.withFormulaAndroid | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import com.instacart.testutils.android.R as TestR | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ViewFactoryTest { | ||
|
||
@Test fun fromLayout() { | ||
withFormulaAndroid( | ||
configure = { | ||
activity<TestFormulaActivity> { | ||
ActivityStore( | ||
fragmentStore = FragmentStore.init { | ||
val featureFactory = NoOpFeatureFactory( | ||
viewFactory = ViewFactory.fromLayout(TestR.layout.test_fragment_layout) { | ||
featureView { } | ||
} | ||
) | ||
bind(featureFactory) | ||
} | ||
) | ||
} | ||
} | ||
) { | ||
val fragmentKey = TestKey() | ||
|
||
val scenario = ActivityScenario.launch(TestFormulaActivity::class.java) | ||
scenario.showFragment(fragmentKey) | ||
scenario.onActivity { | ||
val fragment = it.supportFragmentManager.findFragmentByTag(fragmentKey.tag) | ||
assertThat(fragment).isNotNull() | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
formula-android/src/test/java/com/instacart/formula/android/views/ViewInstanceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.instacart.formula.android.views | ||
|
||
import android.view.View | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.common.truth.Truth.assertThat | ||
import com.instacart.formula.RenderView | ||
import com.instacart.formula.Renderer | ||
import com.instacart.formula.android.ViewInstance | ||
import com.instacart.testutils.android.TestFragmentActivity | ||
import com.instacart.testutils.android.TestFragmentLifecycleCallback | ||
import com.instacart.testutils.android.activity | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ViewInstanceTest { | ||
|
||
@Test | ||
fun `feature view with render view`() { | ||
val renderView = object : RenderView<Any> { | ||
override val render: Renderer<Any> = Renderer.create {} | ||
} | ||
val viewInstance = viewInstance() | ||
val featureView = viewInstance.featureView(renderView) | ||
assertThat(featureView.view).isEqualTo(viewInstance.view) | ||
assertThat(featureView.setOutput).isEqualTo(renderView.render) | ||
assertThat(featureView.lifecycleCallbacks).isEqualTo(null) | ||
} | ||
|
||
@Test | ||
fun `feature view with render view and lifecycle callbacks`() { | ||
val renderView = object : RenderView<Any> { | ||
override val render: Renderer<Any> = Renderer.create {} | ||
} | ||
val viewInstance = viewInstance() | ||
val callback = TestFragmentLifecycleCallback() | ||
val featureView = viewInstance.featureView(renderView, callback) | ||
assertThat(featureView.lifecycleCallbacks).isEqualTo(callback) | ||
} | ||
|
||
private fun viewInstance(): ViewInstance { | ||
val scenario = ActivityScenario.launch(TestFragmentActivity::class.java) | ||
val view = View(scenario.activity()) | ||
return InflatedViewInstance(view) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ula/test/TestFragmentLifecycleCallback.kt → .../android/TestFragmentLifecycleCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ava/com/instacart/formula/test/TestKey.kt → ...om/instacart/testutils/android/TestKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters