Skip to content

Commit

Permalink
Fix coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laimiux committed Sep 20, 2024
1 parent 1dcda1b commit 61ec8d1
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.instacart.formula

import android.os.Looper
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.rules.ActivityScenarioRule
Expand All @@ -16,7 +15,7 @@ import com.instacart.formula.android.FragmentEnvironment
import com.instacart.formula.android.FragmentStore
import com.instacart.formula.android.events.FragmentLifecycleEvent
import com.instacart.formula.test.TestBackCallbackRenderModel
import com.instacart.formula.test.TestKey
import com.instacart.testutils.android.TestKey
import com.instacart.formula.test.TestKeyWithId
import com.instacart.formula.test.TestFragmentActivity
import com.instacart.formula.test.TestLifecycleKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.instacart.formula.android.ActivityStore
import com.instacart.formula.android.FragmentStore
import com.instacart.formula.android.FragmentKey
import com.instacart.formula.test.TestKey
import com.instacart.testutils.android.TestKey
import com.instacart.formula.test.TestKeyWithId
import com.instacart.testutils.android.FormulaAndroidInteractor
import com.instacart.testutils.android.NoOpFeatureFactory
Expand All @@ -15,7 +15,6 @@ import com.instacart.testutils.android.withFormulaAndroid
import io.reactivex.rxjava3.observers.TestObserver
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.LooperMode

@RunWith(AndroidJUnit4::class)
class FragmentLifecycleStateTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.google.common.truth.Truth.assertThat
import com.instacart.formula.android.ActivityStore
import com.instacart.formula.android.FormulaFragment
import com.instacart.formula.android.FragmentStore
import com.instacart.formula.test.TestFragmentLifecycleCallback
import com.instacart.testutils.android.TestFragmentLifecycleCallback
import com.instacart.formula.test.TestLifecycleKey
import com.instacart.testutils.android.NoOpFeatureFactory
import com.instacart.testutils.android.TestFormulaActivity
Expand Down
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()
}
}
}
}
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)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.instacart.formula.test
package com.instacart.testutils.android

import android.os.Bundle
import android.view.View
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.instacart.formula.test
package com.instacart.testutils.android

import com.instacart.formula.android.FragmentKey
import kotlinx.parcelize.Parcelize
Expand Down

0 comments on commit 61ec8d1

Please sign in to comment.