From fd3e5128c7cbdaecc92922d19565d49eb9ade09a Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 10 Mar 2022 14:30:03 +0300 Subject: [PATCH 1/9] Test initial poll event. --- .../room/timeline/PollAggregationTest.kt | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt 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 new file mode 100644 index 0000000000..f50b8c978f --- /dev/null +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/PollAggregationTest.kt @@ -0,0 +1,119 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.matrix.android.sdk.session.room.timeline + +import org.amshove.kluent.fail +import org.amshove.kluent.shouldBe +import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldContainAll +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.runners.MethodSorters +import org.matrix.android.sdk.InstrumentedTest +import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.PollResponseAggregatedSummary +import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent +import org.matrix.android.sdk.api.session.room.model.message.PollType +import org.matrix.android.sdk.api.session.room.timeline.Timeline +import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent +import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings +import org.matrix.android.sdk.common.CommonTestHelper +import org.matrix.android.sdk.common.CryptoTestHelper +import java.util.concurrent.CountDownLatch + +@RunWith(JUnit4::class) +@FixMethodOrder(MethodSorters.JVM) +class PollAggregationTest : InstrumentedTest { + + @Test + fun testAllPollUseCases() { + val commonTestHelper = CommonTestHelper(context()) + val cryptoTestHelper = CryptoTestHelper(commonTestHelper) + val cryptoTestData = cryptoTestHelper.doE2ETestWithAliceAndBobInARoom(false) + + val aliceSession = cryptoTestData.firstSession + val aliceRoomId = cryptoTestData.roomId + val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!! + + val roomFromBobPOV = cryptoTestData.secondSession!!.getRoom(cryptoTestData.roomId)!! + // Bob creates a poll + roomFromBobPOV.sendPoll(PollType.DISCLOSED, pollQuestion, pollOptions) + + aliceSession.startSync(true) + val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30)) + aliceTimeline.start() + + val TOTAL_TEST_COUNT = 1 + val lock = CountDownLatch(TOTAL_TEST_COUNT) + + val aliceEventsListener = object : Timeline.Listener { + override fun onTimelineUpdated(snapshot: List) { + snapshot.firstOrNull { it.root.getClearType() == EventType.POLL_START }?.let { pollEvent -> + //val pollEventId = pollEvent.eventId + val pollContent = pollEvent.root.content?.toModel() + val pollSummary = pollEvent.annotations?.pollResponseSummary + + if (pollContent == null) { + fail("Poll content is null") + return + } + + when (lock.count.toInt()) { + TOTAL_TEST_COUNT -> { + // Poll has just been created. + testInitialPollConditions(pollContent, pollSummary) + lock.countDown() + } + else -> { + fail("Lock count ${lock.count} didn't handled.") + } + } + } + } + } + + aliceTimeline.addListener(aliceEventsListener) + + commonTestHelper.await(lock) + + aliceTimeline.removeAllListeners() + + aliceSession.stopSync() + aliceTimeline.dispose() + cryptoTestData.cleanUp(commonTestHelper) + } + + private fun testInitialPollConditions(pollContent: MessagePollContent, pollSummary: PollResponseAggregatedSummary?) { + // No votes yet, poll summary should be null + pollSummary shouldBe null + // Question should be the same as intended + pollContent.pollCreationInfo?.question?.question shouldBeEqualTo pollQuestion + // Options should be the same as intended + pollContent.pollCreationInfo?.answers?.let { answers -> + answers.size shouldBeEqualTo pollOptions.size + answers.map { it.answer } shouldContainAll pollOptions + } + } + + companion object { + const val pollQuestion = "Do you like creating polls?" + val pollOptions = listOf("Yes", "Absolutely", "As long as tests pass") + } +} From 1b348401bdf5c2532d5c0e32624434db4b5eccb6 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 10 Mar 2022 15:31:32 +0300 Subject: [PATCH 2/9] Add poll test for a single vote. --- .../room/timeline/PollAggregationTest.kt | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 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 f50b8c978f..b732b333f4 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 @@ -60,13 +60,13 @@ class PollAggregationTest : InstrumentedTest { val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30)) aliceTimeline.start() - val TOTAL_TEST_COUNT = 1 + val TOTAL_TEST_COUNT = 2 val lock = CountDownLatch(TOTAL_TEST_COUNT) val aliceEventsListener = object : Timeline.Listener { override fun onTimelineUpdated(snapshot: List) { snapshot.firstOrNull { it.root.getClearType() == EventType.POLL_START }?.let { pollEvent -> - //val pollEventId = pollEvent.eventId + val pollEventId = pollEvent.eventId val pollContent = pollEvent.root.content?.toModel() val pollSummary = pollEvent.annotations?.pollResponseSummary @@ -76,12 +76,17 @@ class PollAggregationTest : InstrumentedTest { } when (lock.count.toInt()) { - TOTAL_TEST_COUNT -> { + TOTAL_TEST_COUNT -> { // Poll has just been created. testInitialPollConditions(pollContent, pollSummary) lock.countDown() + roomFromBobPOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.firstOrNull()?.id ?: "") } - else -> { + TOTAL_TEST_COUNT - 1 -> { + testBobVotesOption1(pollContent, pollSummary) + lock.countDown() + } + else -> { fail("Lock count ${lock.count} didn't handled.") } } @@ -112,6 +117,23 @@ class PollAggregationTest : InstrumentedTest { } } + private fun testBobVotesOption1(pollContent: MessagePollContent, pollSummary: PollResponseAggregatedSummary?) { + if (pollSummary == null) { + fail("Poll summary shouldn't be null when someone votes") + return + } + val answerId = pollContent.pollCreationInfo?.answers?.first()?.id + // Check if the intended vote is in poll summary + pollSummary.aggregatedContent?.let { aggregatedContent -> + aggregatedContent.totalVotes shouldBeEqualTo 1 + aggregatedContent.votes?.size shouldBeEqualTo 1 + aggregatedContent.votesSummary?.size shouldBeEqualTo 1 + aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId + aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 1 + aggregatedContent.votesSummary?.get(answerId)?.percentage shouldBeEqualTo 1.0 + } ?: run { fail("Aggregated poll content shouldn't be null after someone votes") } + } + companion object { const val pollQuestion = "Do you like creating polls?" val pollOptions = listOf("Yes", "Absolutely", "As long as tests pass") From f029759f9ab53b9789bd331a938c971947ea94a9 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 10 Mar 2022 15:47:40 +0300 Subject: [PATCH 3/9] Add poll test for changing previous answer. --- .../room/timeline/PollAggregationTest.kt | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 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 b732b333f4..54a8cc1509 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 @@ -29,6 +29,7 @@ import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.PollResponseAggregatedSummary +import org.matrix.android.sdk.api.session.room.model.PollSummaryContent import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent import org.matrix.android.sdk.api.session.room.model.message.PollType import org.matrix.android.sdk.api.session.room.timeline.Timeline @@ -60,7 +61,7 @@ class PollAggregationTest : InstrumentedTest { val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30)) aliceTimeline.start() - val TOTAL_TEST_COUNT = 2 + val TOTAL_TEST_COUNT = 3 val lock = CountDownLatch(TOTAL_TEST_COUNT) val aliceEventsListener = object : Timeline.Listener { @@ -85,6 +86,11 @@ class PollAggregationTest : InstrumentedTest { TOTAL_TEST_COUNT - 1 -> { testBobVotesOption1(pollContent, pollSummary) lock.countDown() + roomFromBobPOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.get(1)?.id ?: "") + } + TOTAL_TEST_COUNT - 2 -> { + testBobChangesVoteToOption2(pollContent, pollSummary) + lock.countDown() } else -> { fail("Lock count ${lock.count} didn't handled.") @@ -125,15 +131,34 @@ class PollAggregationTest : InstrumentedTest { val answerId = pollContent.pollCreationInfo?.answers?.first()?.id // Check if the intended vote is in poll summary pollSummary.aggregatedContent?.let { aggregatedContent -> - aggregatedContent.totalVotes shouldBeEqualTo 1 - aggregatedContent.votes?.size shouldBeEqualTo 1 - aggregatedContent.votesSummary?.size shouldBeEqualTo 1 + assertVoteCount(aggregatedContent, 1) aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 1 aggregatedContent.votesSummary?.get(answerId)?.percentage shouldBeEqualTo 1.0 } ?: run { fail("Aggregated poll content shouldn't be null after someone votes") } } + private fun testBobChangesVoteToOption2(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 vote is in poll summary + pollSummary.aggregatedContent?.let { aggregatedContent -> + assertVoteCount(aggregatedContent, 1) + aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId + aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 1 + 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 { const val pollQuestion = "Do you like creating polls?" val pollOptions = listOf("Yes", "Absolutely", "As long as tests pass") From a5441fdf22c2d3adee695db9718a5582d16d7882 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 10 Mar 2022 16:51:23 +0300 Subject: [PATCH 4/9] 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 { From cd29b1aa4b5d7f44918fae92a71e2ce2457bccd4 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Thu, 10 Mar 2022 17:40:16 +0300 Subject: [PATCH 5/9] Add poll test for users vote different options. --- .../room/timeline/PollAggregationTest.kt | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 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 e7fae6c5bb..b8d604c56b 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 @@ -19,6 +19,7 @@ package org.matrix.android.sdk.session.room.timeline import org.amshove.kluent.fail import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldContain import org.amshove.kluent.shouldContainAll import org.junit.FixMethodOrder import org.junit.Test @@ -61,7 +62,7 @@ class PollAggregationTest : InstrumentedTest { val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30)) aliceTimeline.start() - val TOTAL_TEST_COUNT = 4 + val TOTAL_TEST_COUNT = 5 val lock = CountDownLatch(TOTAL_TEST_COUNT) val aliceEventsListener = object : Timeline.Listener { @@ -96,6 +97,11 @@ class PollAggregationTest : InstrumentedTest { TOTAL_TEST_COUNT - 3 -> { testAliceAndBobVoteToOption2(pollContent, pollSummary) lock.countDown() + roomFromAlicePOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.firstOrNull()?.id ?: "") + } + TOTAL_TEST_COUNT - 4 -> { + testAliceVotesOption1AndBobVotesOption2(pollContent, pollSummary) + lock.countDown() } else -> { fail("Lock count ${lock.count} didn't handled.") @@ -136,7 +142,7 @@ class PollAggregationTest : InstrumentedTest { val answerId = pollContent.pollCreationInfo?.answers?.first()?.id // Check if the intended vote is in poll summary pollSummary.aggregatedContent?.let { aggregatedContent -> - assertVoteCount(aggregatedContent, 1) + assertTotalVotesCount(aggregatedContent, 1) aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 1 aggregatedContent.votesSummary?.get(answerId)?.percentage shouldBeEqualTo 1.0 @@ -151,7 +157,7 @@ class PollAggregationTest : InstrumentedTest { val answerId = pollContent.pollCreationInfo?.answers?.get(1)?.id // Check if the intended vote is in poll summary pollSummary.aggregatedContent?.let { aggregatedContent -> - assertVoteCount(aggregatedContent, 1) + assertTotalVotesCount(aggregatedContent, 1) aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 1 aggregatedContent.votesSummary?.get(answerId)?.percentage shouldBeEqualTo 1.0 @@ -166,7 +172,7 @@ class PollAggregationTest : InstrumentedTest { val answerId = pollContent.pollCreationInfo?.answers?.get(1)?.id // Check if the intended votes is in poll summary pollSummary.aggregatedContent?.let { aggregatedContent -> - assertVoteCount(aggregatedContent, 2) + assertTotalVotesCount(aggregatedContent, 2) aggregatedContent.votes?.first()?.option shouldBeEqualTo answerId aggregatedContent.votes?.get(1)?.option shouldBeEqualTo answerId aggregatedContent.votesSummary?.get(answerId)?.total shouldBeEqualTo 2 @@ -174,7 +180,26 @@ class PollAggregationTest : InstrumentedTest { } ?: run { fail("Aggregated poll content shouldn't be null after someone votes") } } - private fun assertVoteCount(aggregatedContent: PollSummaryContent, expectedVoteCount: Int) { + private fun testAliceVotesOption1AndBobVotesOption2(pollContent: MessagePollContent, pollSummary: PollResponseAggregatedSummary?) { + if (pollSummary == null) { + fail("Poll summary shouldn't be null when someone votes") + return + } + val firstAnswerId = pollContent.pollCreationInfo?.answers?.firstOrNull()?.id + val secondAnswerId = pollContent.pollCreationInfo?.answers?.get(1)?.id + // Check if the intended votes is in poll summary + pollSummary.aggregatedContent?.let { aggregatedContent -> + assertTotalVotesCount(aggregatedContent, 2) + aggregatedContent.votes!!.map { it.option } shouldContain firstAnswerId + aggregatedContent.votes!!.map { it.option } shouldBeEqualTo secondAnswerId + aggregatedContent.votesSummary?.get(firstAnswerId)?.total shouldBeEqualTo 1 + aggregatedContent.votesSummary?.get(secondAnswerId)?.total shouldBeEqualTo 1 + aggregatedContent.votesSummary?.get(firstAnswerId)?.percentage shouldBeEqualTo 0.5 + aggregatedContent.votesSummary?.get(secondAnswerId)?.percentage shouldBeEqualTo 0.5 + } ?: run { fail("Aggregated poll content shouldn't be null after someone votes") } + } + + private fun assertTotalVotesCount(aggregatedContent: PollSummaryContent, expectedVoteCount: Int) { aggregatedContent.totalVotes shouldBeEqualTo expectedVoteCount aggregatedContent.votes?.size shouldBeEqualTo expectedVoteCount } From 8b08d3db251a037010687d9ba7bfb7bc47486031 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 11 Mar 2022 11:36:06 +0300 Subject: [PATCH 6/9] Fix poll test for users vote different options. --- .../android/sdk/session/room/timeline/PollAggregationTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b8d604c56b..ef8899e027 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 @@ -191,7 +191,7 @@ class PollAggregationTest : InstrumentedTest { pollSummary.aggregatedContent?.let { aggregatedContent -> assertTotalVotesCount(aggregatedContent, 2) aggregatedContent.votes!!.map { it.option } shouldContain firstAnswerId - aggregatedContent.votes!!.map { it.option } shouldBeEqualTo secondAnswerId + aggregatedContent.votes!!.map { it.option } shouldContain secondAnswerId aggregatedContent.votesSummary?.get(firstAnswerId)?.total shouldBeEqualTo 1 aggregatedContent.votesSummary?.get(secondAnswerId)?.total shouldBeEqualTo 1 aggregatedContent.votesSummary?.get(firstAnswerId)?.percentage shouldBeEqualTo 0.5 From 7c6167ace94c4a8636855ff8c46bf69b0147677a Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 11 Mar 2022 18:59:27 +0300 Subject: [PATCH 7/9] Add poll test for ended polls. --- .../sdk/session/room/timeline/PollAggregationTest.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 ef8899e027..e104f29ed2 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 @@ -19,6 +19,7 @@ package org.matrix.android.sdk.session.room.timeline import org.amshove.kluent.fail import org.amshove.kluent.shouldBe import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldBeGreaterThan import org.amshove.kluent.shouldContain import org.amshove.kluent.shouldContainAll import org.junit.FixMethodOrder @@ -62,7 +63,7 @@ class PollAggregationTest : InstrumentedTest { val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30)) aliceTimeline.start() - val TOTAL_TEST_COUNT = 5 + val TOTAL_TEST_COUNT = 6 val lock = CountDownLatch(TOTAL_TEST_COUNT) val aliceEventsListener = object : Timeline.Listener { @@ -102,6 +103,11 @@ class PollAggregationTest : InstrumentedTest { TOTAL_TEST_COUNT - 4 -> { testAliceVotesOption1AndBobVotesOption2(pollContent, pollSummary) lock.countDown() + roomFromBobPOV.endPoll(pollEventId) + } + TOTAL_TEST_COUNT - 5 -> { + testEndedPoll(pollSummary) + lock.countDown() } else -> { fail("Lock count ${lock.count} didn't handled.") @@ -199,6 +205,10 @@ class PollAggregationTest : InstrumentedTest { } ?: run { fail("Aggregated poll content shouldn't be null after someone votes") } } + private fun testEndedPoll(pollSummary: PollResponseAggregatedSummary?) { + pollSummary?.closedTime ?: 0 shouldBeGreaterThan 0 + } + private fun assertTotalVotesCount(aggregatedContent: PollSummaryContent, expectedVoteCount: Int) { aggregatedContent.totalVotes shouldBeEqualTo expectedVoteCount aggregatedContent.votes?.size shouldBeEqualTo expectedVoteCount From a12f918dd5e37b6451c81de0607b7aa7da2653f7 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 11 Mar 2022 19:19:20 +0300 Subject: [PATCH 8/9] Add poll test for users try to change their votes after poll is ended. --- .../session/room/timeline/PollAggregationTest.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 e104f29ed2..1de5498040 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 @@ -63,7 +63,7 @@ class PollAggregationTest : InstrumentedTest { val aliceTimeline = roomFromAlicePOV.createTimeline(null, TimelineSettings(30)) aliceTimeline.start() - val TOTAL_TEST_COUNT = 6 + val TOTAL_TEST_COUNT = 7 val lock = CountDownLatch(TOTAL_TEST_COUNT) val aliceEventsListener = object : Timeline.Listener { @@ -86,26 +86,38 @@ class PollAggregationTest : InstrumentedTest { roomFromBobPOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.firstOrNull()?.id ?: "") } TOTAL_TEST_COUNT - 1 -> { + // Bob: Option 1 testBobVotesOption1(pollContent, pollSummary) lock.countDown() roomFromBobPOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.get(1)?.id ?: "") } TOTAL_TEST_COUNT - 2 -> { + // Bob: Option 2 testBobChangesVoteToOption2(pollContent, pollSummary) lock.countDown() roomFromAlicePOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.get(1)?.id ?: "") } TOTAL_TEST_COUNT - 3 -> { + // Alice: Option 2, Bob: Option 2 testAliceAndBobVoteToOption2(pollContent, pollSummary) lock.countDown() roomFromAlicePOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.firstOrNull()?.id ?: "") } TOTAL_TEST_COUNT - 4 -> { + // Alice: Option 1, Bob: Option 2 testAliceVotesOption1AndBobVotesOption2(pollContent, pollSummary) lock.countDown() roomFromBobPOV.endPoll(pollEventId) } TOTAL_TEST_COUNT - 5 -> { + // Alice: Option 1, Bob: Option 2 [poll is ended] + testEndedPoll(pollSummary) + lock.countDown() + roomFromAlicePOV.voteToPoll(pollEventId, pollContent.pollCreationInfo?.answers?.get(1)?.id ?: "") + } + TOTAL_TEST_COUNT - 6 -> { + // Alice: Option 1 (ignore change), Bob: Option 2 [poll is ended] + testAliceVotesOption1AndBobVotesOption2(pollContent, pollSummary) testEndedPoll(pollSummary) lock.countDown() } From 635be17d462fe72e65724a17f3bac1f5ef3bf858 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 11 Mar 2022 19:23:41 +0300 Subject: [PATCH 9/9] Changelog added. --- changelog.d/5522.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5522.feature diff --git a/changelog.d/5522.feature b/changelog.d/5522.feature new file mode 100644 index 0000000000..b50e8d1e60 --- /dev/null +++ b/changelog.d/5522.feature @@ -0,0 +1 @@ +Poll Integration Tests \ No newline at end of file