Files
letro-ios/ElementX/Sources/Mocks/PollMock.swift
Alfonso Grillo c25134a5b2 Add polls "creator view" (#1765)
* Add end button in PollRoomTimelineView

* Add creator logic

* Refine PollRoomTimelineView previews

* Add UI tests

* Update preview tests
2023-09-21 14:59:17 +00:00

95 lines
3.8 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)
}
}
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) -> Self {
.init(id: .init(timelineID: UUID().uuidString, eventID: UUID().uuidString),
poll: poll,
body: "poll",
timestamp: "Now",
isOutgoing: isOutgoing,
isEditable: false,
sender: .init(id: "userID"),
properties: .init())
}
}