From a5441fdf22c2d3adee695db9718a5582d16d7882 Mon Sep 17 00:00:00 2001 From: Onuray Sahin <onurays@element.io> Date: Thu, 10 Mar 2022 16:51:23 +0300 Subject: [PATCH] Add poll test for someone else chose the same option. --- .../room/timeline/PollAggregationTest.kt | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt index 54a8cc1509..e7fae6c5bb 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt @@ -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 {