Files
element-x-ios/ElementX/Sources/Mocks/PollMock.swift
T
Alfonso Grillo e583f52c65 Edit poll UX (#2151)
* Add edit poll on room proxy

* Add CreatePollMode

* Add “edit poll” presentation flow

* Add delete poll section

* Inject editing poll

* Add submit action

* Refactor validation logic

* Add edit/delete actions

* Fix bubble timestamp for polls

* Update localisations

* Refactor CreatePoll -> PollForm

* Refactor tests

* Update rust sdk to 0.0.5-november23

* Update confirmation alerts

* Add edit support in TimelineItem menu

* Refactor a11y id

* Cleanup

* Fix failing tests

* Add tests

* Refine isEditable workaround

* Refactor timestamp in TimelineItemBubbledStylerView
2023-11-23 11:19:15 +00:00

105 lines
4.2 KiB
Swift

//
// Copyright 2023 New Vector Ltd
//
// 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.
//
import Foundation
extension Poll {
static func mock(question: String,
pollKind: Poll.Kind = .disclosed,
options: [Poll.Option],
votes: [String: [String]] = [:],
ended: Bool = false,
createdByAccountOwner: Bool = false) -> Self {
.init(question: question,
kind: pollKind,
maxSelections: 1,
options: options,
votes: votes,
endDate: ended ? Date() : nil,
createdByAccountOwner: createdByAccountOwner)
}
static func disclosed(createdByAccountOwner: Bool = false) -> Self {
mock(question: "What country do you like most?",
pollKind: .disclosed,
options: [.mock(text: "Italy 🇮🇹", votes: 5, allVotes: 10, isWinning: true),
.mock(text: "China 🇨🇳", votes: 3, allVotes: 10),
.mock(text: "USA 🇺🇸", votes: 2, allVotes: 10)],
createdByAccountOwner: createdByAccountOwner)
}
static func undisclosed(createdByAccountOwner: Bool = false) -> Self {
mock(question: "What country do you like most?",
pollKind: .undisclosed,
options: [.mock(text: "Italy 🇮🇹", votes: 5, allVotes: 10, isWinning: true),
.mock(text: "China 🇨🇳", votes: 3, allVotes: 10, isSelected: true),
.mock(text: "USA 🇺🇸", votes: 2, allVotes: 10)],
createdByAccountOwner: createdByAccountOwner)
}
static var endedDisclosed: Self {
mock(question: "What country do you like most?",
pollKind: .disclosed,
options: [.mock(text: "Italy 🇮🇹", votes: 5, allVotes: 10, isWinning: true),
.mock(text: "China 🇨🇳", votes: 3, allVotes: 10, isSelected: true),
.mock(text: "USA 🇺🇸", votes: 2, allVotes: 10)],
ended: true)
}
static var endedUndisclosed: Self {
mock(question: "What country do you like most?",
pollKind: .undisclosed,
options: [.mock(text: "Italy 🇮🇹", votes: 5, allVotes: 10, isWinning: true),
.mock(text: "China 🇨🇳", votes: 3, allVotes: 10, isSelected: true),
.mock(text: "USA 🇺🇸", votes: 2, allVotes: 10)],
ended: true)
}
static var emptyDisclosed: Self {
mock(question: "What country do you like most?",
pollKind: .disclosed,
options: [.mock(text: "Italy 🇮🇹", votes: 0, allVotes: 0),
.mock(text: "China 🇨🇳", votes: 0, allVotes: 0),
.mock(text: "USA 🇺🇸", votes: 0, allVotes: 0)],
createdByAccountOwner: true)
}
}
extension Poll.Option {
static func mock(text: String, votes: Int = 0, allVotes: Int = 0, isSelected: Bool = false, isWinning: Bool = false) -> Self {
.init(id: UUID().uuidString,
text: text,
votes: votes,
allVotes: allVotes,
isSelected: isSelected,
isWinning: isWinning)
}
}
extension PollRoomTimelineItem {
static func mock(poll: Poll, isOutgoing: Bool = true, isEditable: Bool = false) -> Self {
.init(id: .init(timelineID: UUID().uuidString, eventID: UUID().uuidString),
poll: poll,
body: "poll",
timestamp: "Now",
isOutgoing: isOutgoing,
isEditable: isEditable,
canBeRepliedTo: true,
sender: .init(id: "userID"),
properties: .init())
}
}