1@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
3package soy.iko.opencode.ui.file
5import kotlinx.coroutines.Dispatchers
6import kotlinx.coroutines.ExperimentalCoroutinesApi
7import kotlinx.coroutines.test.StandardTestDispatcher
8import kotlinx.coroutines.test.TestScope
9import kotlinx.coroutines.test.resetMain
10import kotlinx.coroutines.test.runTest
11import kotlinx.coroutines.test.setMain
13import org.junit.Assert.assertEquals
14import org.junit.Assert.assertFalse
15import org.junit.Assert.assertNotNull
16import org.junit.Assert.assertNull
17import org.junit.Before
19import soy.iko.opencode.data.model.FileContent
20import soy.iko.opencode.data.model.ServerProfile
21import soy.iko.opencode.ui.testing.FakeAppContainer
22import soy.iko.opencode.ui.testing.FakeEventStreamClient
23import soy.iko.opencode.ui.testing.FakeOpencodeApiClient
24import soy.iko.opencode.ui.testing.FakeOpencodeConnection
25import soy.iko.opencode.ui.testing.FakeSessionRepository
27class FileViewModelTest {
28 private val testDispatcher = StandardTestDispatcher()
29 private val testScope = TestScope(testDispatcher)
32 fun setUp() { Dispatchers.setMain(testDispatcher) }
35 fun tearDown() { Dispatchers.resetMain() }
37 private fun makeContainer(api: FakeOpencodeApiClient): FakeAppContainer {
38 val events = FakeEventStreamClient()
39 val repo = FakeSessionRepository(api, events)
40 val container = FakeAppContainer()
41 container.setActiveConnection(
42 FakeOpencodeConnection(api, events, repo, ServerProfile(id = "s1", label = "T", baseUrl = "http://localhost")),
48 fun load_success_populatesContent() = testScope.runTest {
49 val api = FakeOpencodeApiClient().apply { fileContent = FileContent(content = "hello source") }
50 val vm = FileViewModel(makeContainer(api), "src/Main.kt")
51 testScheduler.advanceUntilIdle()
53 val state = vm.state.value
54 assertFalse(state.loading)
55 assertNotNull(state.content)
56 assertEquals("hello source", state.content?.content)
57 assertNull(state.error)
61 fun load_withoutConnection_showsNotConnected() = testScope.runTest {
62 val vm = FileViewModel(FakeAppContainer(), "src/Main.kt")
63 testScheduler.advanceUntilIdle()
65 val state = vm.state.value
66 assertFalse(state.loading)
67 assertNotNull(state.error)
68 assertNull(state.content)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list