Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public fun Poll.getSubtitle(context: Context): String {
if (closed) {
return context.getString(R.string.stream_ui_poll_description_closed)
}
if (enforceUniqueVote) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On your canCastVote() question: you were right to leave it alone. With enforce_unique_vote the server treats a vote on a different option as a vote change, so returning true there is the correct behaviour.

The reverse case is the broken one. Our own single answer polls carry both maxVotesAllowed = 1 and enforceUniqueVote = true, so canCastVote() returns false after the first vote, and PollOptionVotingRow.kt:111 and PollView.kt:308 then swallow a tap on another option. The user has to deselect first. iOS lets the switch through.

On your offer to handle that separately: yes please, a follow-up PR would be welcome. Nothing needed in this one.

return context.getString(R.string.stream_ui_poll_description_single_answer)
}
val maxVotes = maxVotesAllowed?.let { min(it, options.size) }
return when (maxVotes) {
1 -> context.getString(R.string.stream_ui_poll_description_single_answer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,29 @@ internal class PollExtensionsTest {

@Test
fun `getSubtitle should return single answer subtitle when maxVotesAllowed is 1`() {
val poll = randomPoll(maxVotesAllowed = 1, closed = false)
val poll = randomPoll(enforceUniqueVote = false, maxVotesAllowed = 1, closed = false)
whenever(context.getString(R.string.stream_ui_poll_description_single_answer))
.thenReturn("You can select only one answer.")

val result = poll.getSubtitle(context)

assertEquals("You can select only one answer.", result)
}

@Test
fun `getSubtitle should return single answer subtitle when enforceUniqueVote is true and maxVotesAllowed is null`() {
val poll = randomPoll(enforceUniqueVote = true, maxVotesAllowed = null, closed = false)
whenever(context.getString(R.string.stream_ui_poll_description_single_answer))
.thenReturn("You can select only one answer.")

val result = poll.getSubtitle(context)

assertEquals("You can select only one answer.", result)
}

@Test
fun `getSubtitle should return single answer subtitle when enforceUniqueVote is true and maxVotesAllowed is 1`() {
val poll = randomPoll(enforceUniqueVote = true, maxVotesAllowed = 1, closed = false)
whenever(context.getString(R.string.stream_ui_poll_description_single_answer))
.thenReturn("You can select only one answer.")

Expand All @@ -47,6 +69,7 @@ internal class PollExtensionsTest {
fun `getSubtitle should return multiple answers subtitle when maxVotesAllowed is greater than 1`() {
val poll = randomPoll(
options = listOf(randomOption(), randomOption()),
enforceUniqueVote = false,
maxVotesAllowed = 2,
closed = false,
)
Expand All @@ -58,9 +81,25 @@ internal class PollExtensionsTest {
assertEquals("You can select up to 2 answers.", result)
}

@Test
fun `getSubtitle should return unlimited answers subtitle when the poll has no vote limit`() {
val poll = randomPoll(
options = listOf(randomOption(), randomOption()),
enforceUniqueVote = false,
maxVotesAllowed = null,
closed = false,
)
whenever(context.getString(R.string.stream_ui_poll_description_unlimited_answers))
.thenReturn("Select one or more.")

val result = poll.getSubtitle(context)

assertEquals("Select one or more.", result)
}

@Test
fun `getSubtitle should respect the minimum of maxVotesAllowed and options size`() {
val poll = randomPoll(maxVotesAllowed = 3, closed = false)
val poll = randomPoll(enforceUniqueVote = false, maxVotesAllowed = 3, closed = false)
whenever(context.getString(R.string.stream_ui_poll_description_single_answer))
.thenReturn("You can select only one answer.")

Expand Down
Loading