| 1 |
package io.oxygenhub.android.ui |
| 2 |
|
| 3 |
import io.oxygenhub.android.FakeHubApi |
| 4 |
import io.oxygenhub.android.api.FlowRun |
| 5 |
import io.oxygenhub.android.api.HubException |
| 6 |
import io.oxygenhub.android.api.UserFlowRun |
| 7 |
import io.oxygenhub.android.widget.WidgetData |
| 8 |
import kotlinx.coroutines.test.runTest |
| 9 |
import org.junit.Assert.assertEquals |
| 10 |
import org.junit.Assert.assertFalse |
| 11 |
import org.junit.Assert.assertNull |
| 12 |
import org.junit.Test |
| 13 |
|
| 14 |
class WidgetDataTest { |
| 15 |
@Test |
| 16 |
fun theWidgetShowsTheLatestRunsAndCountsAndAsksForASignInWithoutOne() = runTest { |
| 17 |
val api = FakeHubApi() |
| 18 |
api.userFlowRuns = { (1L..5L).map { UserFlowRun("andy/a", FlowRun(number = it, status = "passed")) } } |
| 19 |
val d = WidgetData.load(api) |
| 20 |
assertEquals(listOf(1L, 2L, 3L), d.runs.map { it.run.number }) |
| 21 |
assertEquals(1, d.reviews) |
| 22 |
assertFalse(WidgetData.load(null).signedIn) |
| 23 |
} |
| 24 |
|
| 25 |
@Test |
| 26 |
fun aPartTheHubCannotGiveIsLeftOutNotTheWholeWidget() = runTest { |
| 27 |
val api = FakeHubApi() |
| 28 |
api.userFlowRuns = { throw HubException.Http(404, "no such API route") } |
| 29 |
val d = WidgetData.load(api) |
| 30 |
assertEquals(emptyList<UserFlowRun>(), d.runs) |
| 31 |
assertEquals(1, d.reviews) |
| 32 |
api.userProposals = { throw HubException.Http(500, "down") } |
| 33 |
assertNull(WidgetData.load(api).reviews) |
| 34 |
} |
| 35 |
} |