-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
c098039
commit 9343fff
Showing
12 changed files
with
149 additions
and
35 deletions.
There are no files selected for viewing
10 changes: 4 additions & 6 deletions
10
.github/workflows/lint-action.yml → .github/workflows/test-action.yml
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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
name: reviewdog | ||
on: [pull_request] | ||
jobs: | ||
ktlint: | ||
name: Check Code Quality | ||
test: | ||
name: Running Unit Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Clone repo | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 1 | ||
- name: ktlint | ||
uses: ScaCap/action-ktlint@master | ||
with: | ||
github_token: ${{ secrets.github_token }} | ||
- run: "./gradlew :shared:testDebugUnitTest" | ||
|
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
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
26 changes: 26 additions & 0 deletions
26
shared/src/commonTest/kotlin/com/kevinschildhorn/fotopresenter/MainCoroutineRule.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,26 @@ | ||
package com.kevinschildhorn.fotopresenter | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
|
||
@ExperimentalCoroutinesApi | ||
class MainCoroutineRule(private val dispatcher: TestDispatcher = StandardTestDispatcher()) : | ||
TestWatcher() { | ||
|
||
override fun starting(description: Description?) { | ||
super.starting(description) | ||
Dispatchers.setMain(dispatcher) | ||
} | ||
|
||
override fun finished(description: Description?) { | ||
super.finished(description) | ||
Dispatchers.resetMain() | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...ommonTest/kotlin/com/kevinschildhorn/fotopresenter/ui/viewmodel/DirectoryViewModelTest.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,65 @@ | ||
package com.kevinschildhorn.fotopresenter.ui.viewmodel | ||
|
||
import com.kevinschildhorn.fotopresenter.MainCoroutineRule | ||
import com.kevinschildhorn.fotopresenter.data.network.MockNetworkHandler | ||
import com.kevinschildhorn.fotopresenter.testingModule | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.context.stopKoin | ||
import org.koin.test.KoinTest | ||
import org.koin.test.inject | ||
import kotlin.test.AfterTest | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
Testing [DirectoryViewModel] | ||
**/ | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class DirectoryViewModelTest : KoinTest { | ||
|
||
@ExperimentalCoroutinesApi | ||
@get:Rule | ||
var mainCoroutineRule = MainCoroutineRule() | ||
|
||
private val viewModel: DirectoryViewModel by inject() | ||
|
||
@AfterTest | ||
fun tearDown() { | ||
stopKoin() | ||
} | ||
|
||
@Test | ||
fun `UI State`() = runTest { | ||
startKoin { | ||
modules(testingModule()) | ||
} | ||
|
||
MockNetworkHandler.connectSuccessfully() | ||
with(viewModel.uiState.value) { | ||
assertEquals("", currentPath) | ||
assertEquals(0, directoryContents.allDirectories.count()) | ||
} | ||
|
||
viewModel.refreshScreen() | ||
advanceUntilIdle() | ||
|
||
|
||
with(viewModel.uiState.value) { | ||
//assertEquals("", currentPath) | ||
//assertEquals(2, directoryContents.allDirectories.count()) | ||
} | ||
MockNetworkHandler.disconnect() | ||
} | ||
} |
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