-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for DisposableEffect callbacks
Initially I'm adding just the test we already pass, where the effect is executed because it is removed from the composition. #2248
- Loading branch information
1 parent
8c03b03
commit 7bba4bc
Showing
6 changed files
with
120 additions
and
12 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
56 changes: 56 additions & 0 deletions
56
...od-treehouse-host/src/appsJvmTest/kotlin/app/cash/redwood/treehouse/GuestLifecycleTest.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,56 @@ | ||
/* | ||
* Copyright (C) 2024 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEmpty | ||
import assertk.assertions.isEqualTo | ||
import com.example.redwood.testapp.testing.ButtonValue | ||
import com.example.redwood.testapp.testing.TextInputValue | ||
import kotlin.test.Test | ||
import kotlinx.coroutines.test.runTest | ||
|
||
class GuestLifecycleTest { | ||
@Test | ||
fun disposableEffectDisposedWhenRemovedFromComposition() = runTest { | ||
val tester = TreehouseTester(this) | ||
val treehouseApp = tester.loadApp() | ||
val content = tester.content(treehouseApp) | ||
val view = tester.view() | ||
|
||
content.bind(view) | ||
|
||
content.awaitContent(1) | ||
val textInputValue = view.views.single() as TextInputValue | ||
assertThat(textInputValue.text).isEqualTo("what would you like to see?") | ||
textInputValue.onChange!!.invoke("GuestLifecycleTestShowDisposable") | ||
|
||
tester.sendFrame() | ||
assertThat(tester.hostApi.takeMessage()).isEqualTo("DisposableEffect.effect()") | ||
content.awaitContent(2) | ||
val nextButton = view.views.single() as ButtonValue | ||
assertThat(nextButton.text).isEqualTo("Next") | ||
nextButton.onClick!!.invoke() | ||
|
||
tester.sendFrame() | ||
assertThat(tester.hostApi.takeMessage()).isEqualTo("DisposableEffect.dispose()") | ||
content.awaitContent(3) | ||
assertThat(view.views).isEmpty() | ||
|
||
treehouseApp.stop() | ||
treehouseApp.close() | ||
} | ||
} |
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
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