Add poll test for someone else chose the same option.
This commit is contained in:
parent
f029759f9a
commit
a5441fdf22
|
@ -61,7 +61,7 @@ class PollAggregationTest : InstrumentedTest {
|
|||
val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30))
|
||||
aliceTimeline.start()
|
||||
|
||||
val TOTAL_TEST_COUNT = 3
|
||||
val TOTAL_TEST_COUNT = 4
|
||||
val lock = CountDownLatch(TOTAL_TEST_COUNT)
|
||||
|
||||
val aliceEventsListener = object : Timeline.Listener {
|
||||
|
@ -91,6 +91,11 @@ class PollAggregationTest : InstrumentedTest {
|
|||
TOTAL_TEST_COUNT - 2 -> {
|
||||
testBobChangesVoteToOption2(pollContent, pollSummary)
|
||||
lock.countDown()
|
||||
roomFromAlicePOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.get(1)?.id ?: "")
|
||||
}
|
||||
TOTAL_TEST_COUNT - 3 -> {
|
||||
testAliceAndBobVoteToOption2(pollContent, pollSummary)
|
||||
lock.countDown()
|
||||
}
|
||||
else -> {
|
||||
fail("Lock count ${lock.count} didn't handled.")
|
||||
|
@ -153,10 +158,25 @@ class PollAggregationTest : InstrumentedTest {
|
|||
} ?: run { fail("Aggregated poll content shouldn't be null after someone votes") }
|
||||
}
|
||||
|
||||
private fun testAliceAndBobVoteToOption2(pollContent: MessagePollContent, pollSummary: PollResponseAggregatedSummary?) {
|
||||
if (pollSummary == null) {
|
||||
fail("Poll summary shouldn't be null when someone votes")
|
||||
return
|
||||
}
|
||||
val answerId = pollContent.pollCreationInfo?.answers?.get(1)?.id
|
||||
// Check if the intended votes is in poll summary
|
||||
pollSummary.aggregatedContent?.let { aggregatedContent ->
|
||||
assertVoteCount(aggregatedContent, 2)
|
||||
aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId
|
||||
aggregatedContent.votes?.get(1)?.option shouldBeEqualTo answerId
|
||||
aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 2
|
||||
aggregatedContent.votesSummary?.get(answerId)?.percentage shouldBeEqualTo 1.0
|
||||
} ?: run { fail("Aggregated poll content shouldn't be null after someone votes") }
|
||||
}
|
||||
|
||||
private fun assertVoteCount(aggregatedContent: PollSummaryContent, expectedVoteCount: Int) {
|
||||
aggregatedContent.totalVotes shouldBeEqualTo expectedVoteCount
|
||||
aggregatedContent.votes?.size shouldBeEqualTo expectedVoteCount
|
||||
aggregatedContent.votesSummary?.size shouldBeEqualTo expectedVoteCount
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
Loading…
Reference in New Issue