Give 0 has default value for fixtures creators.
Also increases the readability of tests.
This commit is contained in:
parent
0f8eda050b
commit
12da93a926
3 changed files with 32 additions and 18 deletions
|
|
@ -178,12 +178,23 @@ class RoomListPresenterTests {
|
||||||
val initialItems = initialState.roomList.dataOrNull().orEmpty()
|
val initialItems = initialState.roomList.dataOrNull().orEmpty()
|
||||||
assertThat(initialItems.size).isEqualTo(16)
|
assertThat(initialItems.size).isEqualTo(16)
|
||||||
assertThat(initialItems.all { it.isPlaceholder }).isTrue()
|
assertThat(initialItems.all { it.isPlaceholder }).isTrue()
|
||||||
roomListService.postAllRooms(listOf(aRoomSummaryFilled()))
|
roomListService.postAllRooms(
|
||||||
|
listOf(
|
||||||
|
aRoomSummaryFilled(
|
||||||
|
numUnreadMentions = 1,
|
||||||
|
numUnreadMessages = 2,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
val withRoomState = consumeItemsUntilPredicate { state -> state.roomList.dataOrNull()?.size == 1 }.last()
|
val withRoomState = consumeItemsUntilPredicate { state -> state.roomList.dataOrNull()?.size == 1 }.last()
|
||||||
val withRoomStateItems = withRoomState.roomList.dataOrNull().orEmpty()
|
val withRoomStateItems = withRoomState.roomList.dataOrNull().orEmpty()
|
||||||
assertThat(withRoomStateItems.size).isEqualTo(1)
|
assertThat(withRoomStateItems.size).isEqualTo(1)
|
||||||
assertThat(withRoomStateItems.first())
|
assertThat(withRoomStateItems.first()).isEqualTo(
|
||||||
.isEqualTo(createRoomListRoomSummary())
|
createRoomListRoomSummary(
|
||||||
|
numberOfUnreadMentions = 1,
|
||||||
|
numberOfUnreadMessages = 2,
|
||||||
|
)
|
||||||
|
)
|
||||||
scope.cancel()
|
scope.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +210,14 @@ class RoomListPresenterTests {
|
||||||
moleculeFlow(RecompositionMode.Immediate) {
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
}.test {
|
}.test {
|
||||||
roomListService.postAllRooms(listOf(aRoomSummaryFilled()))
|
roomListService.postAllRooms(
|
||||||
|
listOf(
|
||||||
|
aRoomSummaryFilled(
|
||||||
|
numUnreadMentions = 1,
|
||||||
|
numUnreadMessages = 2,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
skipItems(3)
|
skipItems(3)
|
||||||
val loadedState = awaitItem()
|
val loadedState = awaitItem()
|
||||||
// Test filtering with result
|
// Test filtering with result
|
||||||
|
|
@ -210,8 +228,12 @@ class RoomListPresenterTests {
|
||||||
assertThat(withFilteredRoomState.filteredRoomList.size).isEqualTo(1)
|
assertThat(withFilteredRoomState.filteredRoomList.size).isEqualTo(1)
|
||||||
assertThat(withFilteredRoomState.filter).isEqualTo(A_ROOM_NAME.substring(0, 3))
|
assertThat(withFilteredRoomState.filter).isEqualTo(A_ROOM_NAME.substring(0, 3))
|
||||||
assertThat(withFilteredRoomState.filteredRoomList.size).isEqualTo(1)
|
assertThat(withFilteredRoomState.filteredRoomList.size).isEqualTo(1)
|
||||||
assertThat(withFilteredRoomState.filteredRoomList.first())
|
assertThat(withFilteredRoomState.filteredRoomList.first()).isEqualTo(
|
||||||
.isEqualTo(createRoomListRoomSummary())
|
createRoomListRoomSummary(
|
||||||
|
numberOfUnreadMentions = 1,
|
||||||
|
numberOfUnreadMessages = 2,
|
||||||
|
)
|
||||||
|
)
|
||||||
// Test filtering without result
|
// Test filtering without result
|
||||||
withFilteredRoomState.eventSink.invoke(RoomListEvents.UpdateFilter("tada"))
|
withFilteredRoomState.eventSink.invoke(RoomListEvents.UpdateFilter("tada"))
|
||||||
skipItems(1)
|
skipItems(1)
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,7 @@ class RoomListRoomSummaryTest {
|
||||||
@Test
|
@Test
|
||||||
fun `test default value`() {
|
fun `test default value`() {
|
||||||
val sut = createRoomListRoomSummary(
|
val sut = createRoomListRoomSummary(
|
||||||
numberOfUnreadMentions = 0,
|
|
||||||
numberOfUnreadMessages = 0,
|
|
||||||
numberOfUnreadNotifications = 0,
|
|
||||||
isMarkedUnread = false,
|
isMarkedUnread = false,
|
||||||
userDefinedNotificationMode = null,
|
|
||||||
)
|
)
|
||||||
assertThat(sut.isHighlighted).isFalse()
|
assertThat(sut.isHighlighted).isFalse()
|
||||||
assertThat(sut.hasNewContent).isFalse()
|
assertThat(sut.hasNewContent).isFalse()
|
||||||
|
|
@ -42,11 +38,7 @@ class RoomListRoomSummaryTest {
|
||||||
@Test
|
@Test
|
||||||
fun `test isMarkedUnread set to true`() {
|
fun `test isMarkedUnread set to true`() {
|
||||||
val sut = createRoomListRoomSummary(
|
val sut = createRoomListRoomSummary(
|
||||||
numberOfUnreadMentions = 0,
|
|
||||||
numberOfUnreadMessages = 0,
|
|
||||||
numberOfUnreadNotifications = 0,
|
|
||||||
isMarkedUnread = true,
|
isMarkedUnread = true,
|
||||||
userDefinedNotificationMode = null,
|
|
||||||
)
|
)
|
||||||
assertThat(sut.isHighlighted).isTrue()
|
assertThat(sut.isHighlighted).isTrue()
|
||||||
assertThat(sut.hasNewContent).isTrue()
|
assertThat(sut.hasNewContent).isTrue()
|
||||||
|
|
@ -54,8 +46,8 @@ class RoomListRoomSummaryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun createRoomListRoomSummary(
|
internal fun createRoomListRoomSummary(
|
||||||
numberOfUnreadMentions: Int = 1,
|
numberOfUnreadMentions: Int = 0,
|
||||||
numberOfUnreadMessages: Int = 2,
|
numberOfUnreadMessages: Int = 0,
|
||||||
numberOfUnreadNotifications: Int = 0,
|
numberOfUnreadNotifications: Int = 0,
|
||||||
isMarkedUnread: Boolean = false,
|
isMarkedUnread: Boolean = false,
|
||||||
userDefinedNotificationMode: RoomNotificationMode? = null,
|
userDefinedNotificationMode: RoomNotificationMode? = null,
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ fun aRoomSummaryFilled(
|
||||||
isDirect: Boolean = false,
|
isDirect: Boolean = false,
|
||||||
avatarUrl: String? = null,
|
avatarUrl: String? = null,
|
||||||
lastMessage: RoomMessage? = aRoomMessage(),
|
lastMessage: RoomMessage? = aRoomMessage(),
|
||||||
numUnreadMentions: Int = 1,
|
numUnreadMentions: Int = 0,
|
||||||
numUnreadMessages: Int = 2,
|
numUnreadMessages: Int = 0,
|
||||||
notificationMode: RoomNotificationMode? = null,
|
notificationMode: RoomNotificationMode? = null,
|
||||||
) = RoomSummary.Filled(
|
) = RoomSummary.Filled(
|
||||||
aRoomSummaryDetails(
|
aRoomSummaryDetails(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue