added alert to show possible error, improved tests

This commit is contained in:
Flavio Alescio
2023-01-27 17:10:16 +01:00
parent 378d4d072e
commit 9d0f5c208b
7 changed files with 45 additions and 40 deletions
@@ -57,35 +57,35 @@ final class PollHistoryCoordinator: NSObject, Coordinator, Presentable {
func showPollDetail(_ poll: TimelinePollDetails) {
if let event = parameters.room.mxSession.store.event(withEventId: poll.id, inRoom: parameters.room.roomId),
let detailCoordinator: PollHistoryDetailCoordinator = try? .init(parameters: .init(event: event, room: self.parameters.room)) {
detailCoordinator.toPresentable().presentationController?.delegate = self
detailCoordinator.completion = { [weak self, weak detailCoordinator] result in
guard let self = self, let coordinator = detailCoordinator else { return }
switch result {
case .dismiss:
self.toPresentable().dismiss(animated: true)
self.remove(childCoordinator: coordinator)
case .viewInTimeline:
self.toPresentable().dismiss(animated: false)
self.remove(childCoordinator: coordinator)
var event = event
if poll.closed {
let room = self.parameters.room
let relatedEvents = room.mxSession.store.relations(forEvent: event.eventId, inRoom: room.roomId, relationType: MXEventRelationTypeReference)
let pollEndedEvent = relatedEvents.first(where: { $0.eventType == .pollEnd })
event = pollEndedEvent ?? event
}
self.completion?(event)
}
}
self.add(childCoordinator: detailCoordinator)
detailCoordinator.start()
self.toPresentable().present(detailCoordinator.toPresentable(), animated: true)
} else {
// TODO: #1040 manage error
guard let event = parameters.room.mxSession.store.event(withEventId: poll.id, inRoom: parameters.room.roomId),
let detailCoordinator: PollHistoryDetailCoordinator = try? .init(parameters: .init(event: event, room: self.parameters.room)) else {
pollHistoryViewModel.context.alertInfo = .init(id: true, title: VectorL10n.settingsDiscoveryErrorMessage)
return
}
detailCoordinator.toPresentable().presentationController?.delegate = self
detailCoordinator.completion = { [weak self, weak detailCoordinator] result in
guard let self = self, let coordinator = detailCoordinator else { return }
switch result {
case .dismiss:
self.toPresentable().dismiss(animated: true)
self.remove(childCoordinator: coordinator)
case .viewInTimeline:
self.toPresentable().dismiss(animated: false)
self.remove(childCoordinator: coordinator)
var event = event
if poll.closed {
let room = self.parameters.room
let relatedEvents = room.mxSession.store.relations(forEvent: event.eventId, inRoom: room.roomId, relationType: MXEventRelationTypeReference)
let pollEndedEvent = relatedEvents.first(where: { $0.eventType == .pollEnd })
event = pollEndedEvent ?? event
}
self.completion?(event)
}
}
self.add(childCoordinator: detailCoordinator)
detailCoordinator.start()
self.toPresentable().present(detailCoordinator.toPresentable(), animated: true)
}
func toPresentable() -> UIViewController {
@@ -20,15 +20,17 @@ import XCTest
class PollHistoryDetailUITests: MockScreenTestCase {
func testPollHistoryDetailOpenPoll() {
app.goToScreenWithIdentifier(MockPollHistoryDetailScreenState.openDisclosed.title)
XCTAssert(app.staticTexts["Active polls"].exists)
XCTAssert(app.staticTexts["1/1/01"].exists)
XCTAssert(app.buttons["View poll in timeline"].exists)
let title = app.navigationBars.staticTexts.firstMatch.label
XCTAssertEqual(title, VectorL10n.pollHistoryActiveSegmentTitle)
XCTAssertEqual(app.staticTexts["PollHistoryDetail.date"].label, "1/1/01")
XCTAssertEqual(app.buttons["PollHistoryDetail.viewInTimeLineButton"].label, VectorL10n.pollHistoryDetailViewInTimeline)
}
func testPollHistoryDetailClosedPoll() {
app.goToScreenWithIdentifier(MockPollHistoryDetailScreenState.closedDisclosed.title)
XCTAssert(app.staticTexts["Past polls"].exists)
XCTAssert(app.staticTexts["1/1/01"].exists)
XCTAssert(app.buttons["View poll in timeline"].exists)
let title = app.navigationBars.staticTexts.firstMatch.label
XCTAssertEqual(title, VectorL10n.pollHistoryPastSegmentTitle)
XCTAssertEqual(app.staticTexts["PollHistoryDetail.date"].label, "1/1/01")
XCTAssertEqual(app.buttons["PollHistoryDetail.viewInTimeLineButton"].label, VectorL10n.pollHistoryDetailViewInTimeline)
}
}
@@ -51,4 +51,5 @@ class PollHistoryDetailViewModelTests: XCTestCase {
func testInitialState() {
XCTAssertFalse(context.viewState.isPollClosed)
}
}
@@ -53,6 +53,7 @@ struct PollHistoryDetail: View {
.foregroundColor(theme.colors.tertiaryContent)
.font(theme.fonts.caption1)
.padding([.top])
.accessibilityIdentifier("PollHistoryDetail.date")
TimelinePollView(viewModel: timelineViewModel.context)
.navigationTitle(navigationTitle)
.navigationBarTitleDisplayMode(.inline)
@@ -88,6 +89,7 @@ struct PollHistoryDetail: View {
Text(VectorL10n.pollHistoryDetailViewInTimeline)
}
.accentColor(theme.colors.accent)
.accessibilityIdentifier("PollHistoryDetail.viewInTimeLineButton")
}
private var navigationTitle: String {
@@ -64,10 +64,11 @@ struct PollHistory: View {
ScrollView {
LazyVStack(spacing: 32) {
ForEach(viewModel.viewState.polls ?? []) { pollData in
PollListItem(pollData: pollData)
.onTapGesture {
viewModel.send(viewAction: .showPollDetail(poll: pollData))
}
Button(action: {
viewModel.send(viewAction: .showPollDetail(poll: pollData))
}) {
PollListItem(pollData: pollData)
}
}
.frame(maxWidth: .infinity, alignment: .leading)