Allow polls to be edited (#1869)

Polls can be edited if they do not have any votes

---------

Co-authored-by: ElementBot <benoitm+elementbot@element.io>
This commit is contained in:
jonnyandrew 2023-11-24 16:47:58 +00:00 committed by GitHub
parent 4e52244b86
commit 8fcec4a006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 827 additions and 173 deletions

View file

@ -103,6 +103,7 @@ class FakeMatrixRoom(
private var reportContentResult = Result.success(Unit)
private var sendLocationResult = Result.success(Unit)
private var createPollResult = Result.success(Unit)
private var editPollResult = Result.success(Unit)
private var sendPollResponseResult = Result.success(Unit)
private var endPollResult = Result.success(Unit)
private var progressCallbackValues = emptyList<Pair<Long, Long>>()
@ -130,8 +131,11 @@ class FakeMatrixRoom(
private val _sentLocations = mutableListOf<SendLocationInvocation>()
val sentLocations: List<SendLocationInvocation> = _sentLocations
private val _createPollInvocations = mutableListOf<CreatePollInvocation>()
val createPollInvocations: List<CreatePollInvocation> = _createPollInvocations
private val _createPollInvocations = mutableListOf<SavePollInvocation>()
val createPollInvocations: List<SavePollInvocation> = _createPollInvocations
private val _editPollInvocations = mutableListOf<SavePollInvocation>()
val editPollInvocations: List<SavePollInvocation> = _editPollInvocations
private val _sendPollResponseInvocations = mutableListOf<SendPollResponseInvocation>()
val sendPollResponseInvocations: List<SendPollResponseInvocation> = _sendPollResponseInvocations
@ -375,10 +379,21 @@ class FakeMatrixRoom(
maxSelections: Int,
pollKind: PollKind
): Result<Unit> = simulateLongTask {
_createPollInvocations.add(CreatePollInvocation(question, answers, maxSelections, pollKind))
_createPollInvocations.add(SavePollInvocation(question, answers, maxSelections, pollKind))
return createPollResult
}
override suspend fun editPoll(
pollStartId: EventId,
question: String,
answers: List<String>,
maxSelections: Int,
pollKind: PollKind
): Result<Unit> = simulateLongTask {
_editPollInvocations.add(SavePollInvocation(question, answers, maxSelections, pollKind))
return editPollResult
}
override suspend fun sendPollResponse(
pollStartId: EventId,
answers: List<String>
@ -511,6 +526,10 @@ class FakeMatrixRoom(
createPollResult = result
}
fun givenEditPollResult(result: Result<Unit>) {
editPollResult = result
}
fun givenSendPollResponseResult(result: Result<Unit>) {
sendPollResponseResult = result
}
@ -544,7 +563,7 @@ data class SendLocationInvocation(
val assetType: AssetType?,
)
data class CreatePollInvocation(
data class SavePollInvocation(
val question: String,
val answers: List<String>,
val maxSelections: Int,

View file

@ -181,11 +181,12 @@ fun aTimelineItemDebugInfo(
fun aPollContent(
question: String = "Do you like polls?",
answers: List<PollAnswer> = listOf(PollAnswer("1", "Yes"), PollAnswer("2", "No")),
) = PollContent(
question = question,
kind = PollKind.Disclosed,
maxSelections = 1u,
answers = listOf(PollAnswer("1", "Yes"), PollAnswer("2", "No")),
answers = answers,
votes = mapOf(),
endTime = null
)