Skip to content

Commit

Permalink
[ADS-176120] Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdeng2002 committed Dec 1, 2023
1 parent 2db27a4 commit 9356ef0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.instacart.formula.internal.ClearPluginsRule
import com.instacart.formula.internal.TestInspector
import com.instacart.formula.internal.Try
import com.instacart.formula.rxjava3.RxAction
import com.instacart.formula.rxjava3.RxJavaRuntime
import com.instacart.formula.subjects.ChildActionFiresParentEventOnStart
import com.instacart.formula.subjects.ChildMessageNoParentStateChange
import com.instacart.formula.subjects.ChildMessageTriggersEventTransitionInParent
Expand Down Expand Up @@ -1111,6 +1112,24 @@ class FormulaRuntimeTest(val runtime: TestableRuntime, val name: String) {
assertThat(error).isInstanceOf(IllegalStateException::class.java)
}

@Test fun `adding duplicate child logs an exception`() {
val logs = mutableListOf<String>()
RxJavaRuntime.setDefaultErrorHandler { logs.add(it.localizedMessage) }

val result = Try {
val formula = DynamicParentFormula()
runtime.test(formula, Unit)
.output { addChild(TestKey("1")) }
.output { addChild(TestKey("1")) }
}

val error = result.errorOrNull()?.cause
assertThat(error).isNull()
assertThat(logs).hasSize(1)
val log = logs.first()
assertThat(log).isEqualTo("Duplicate child key: TestKey(id=1)")
}

@Test
fun `parent removal triggers childs terminate message`() {
val terminateFormula = TerminateFormula()
Expand Down

0 comments on commit 9356ef0

Please sign in to comment.