Skip to content

Commit

Permalink
Temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laimiux committed Sep 9, 2024
1 parent b568c21 commit 8ac794e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class ComposeViewFactory<RenderModel : Any> : ViewFactory<RenderModel>
return FeatureView(
view = view,
setOutput = outputRelay::accept,
lifecycleCallbacks = null,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.instacart.formula.test

import com.instacart.formula.android.BackCallback

data class TestBackCallbackRenderModel(
private val onBackPressed: () -> Unit,
val blockBackCallback: Boolean = false,
) : BackCallback {
override fun onBackPressed(): Boolean {
this.onBackPressed.invoke()
return blockBackCallback
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.instacart.formula.android.BackCallback
import com.instacart.formula.android.FormulaFragment
import com.instacart.formula.android.FragmentEnvironment
import com.instacart.formula.android.FragmentStore
import com.instacart.formula.test.TestBackCallbackRenderModel
import com.instacart.formula.test.TestKey
import com.instacart.formula.test.TestKeyWithId
import com.instacart.formula.test.TestFragmentActivity
Expand Down Expand Up @@ -275,6 +276,37 @@ class FormulaFragmentTest {
assertThat(updateThreads).containsExactly(Thread.currentThread())
}

@Test fun `back callback blocks navigation`() {
val key = TestKeyWithId(1)
navigateToTaskDetail(id = key.id)

Shadows.shadowOf(Looper.getMainLooper()).idle()

var onBackPressed = 0
sendStateUpdate(key, TestBackCallbackRenderModel(
onBackPressed = {
onBackPressed += 1
},
blockBackCallback = true
))

navigateBack()

// We blocked navigation so visible fragment should still be details
assertThat(onBackPressed).isEqualTo(1)
assertVisibleContract(key)

sendStateUpdate(key, TestBackCallbackRenderModel(
onBackPressed = { onBackPressed += 1 },
blockBackCallback = false
))

navigateBack()

assertThat(onBackPressed).isEqualTo(2)
assertVisibleContract(TestKey())
}

@Test fun `notify fragment environment if setOutput throws an error`() {
val key = TestKeyWithId(1)
navigateToTaskDetail(id = key.id)
Expand Down

0 comments on commit 8ac794e

Please sign in to comment.