added view in timeline action, added tests

This commit is contained in:
Flavio Alescio
2023-01-27 15:07:32 +01:00
parent 0188075f57
commit 5ea70aacd8
15 changed files with 141 additions and 87 deletions
@@ -18,21 +18,17 @@ import RiotSwiftUI
import XCTest
class PollHistoryDetailUITests: MockScreenTestCase {
func testPollHistoryDetailPromptRegular() {
let promptType = PollHistoryDetailPromptType.regular
app.goToScreenWithIdentifier(MockPollHistoryDetailScreenState.promptType(promptType).title)
let title = app.staticTexts["title"]
XCTAssert(title.exists)
XCTAssertEqual(title.label, promptType.title)
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)
}
func testPollHistoryDetailPromptUpgrade() {
let promptType = PollHistoryDetailPromptType.upgrade
app.goToScreenWithIdentifier(MockPollHistoryDetailScreenState.promptType(promptType).title)
let title = app.staticTexts["title"]
XCTAssert(title.exists)
XCTAssertEqual(title.label, promptType.title)
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)
}
}
@@ -27,22 +27,28 @@ class PollHistoryDetailViewModelTests: XCTestCase {
var context: PollHistoryDetailViewModelType.Context!
override func setUpWithError() throws {
viewModel = PollHistoryDetailViewModel(promptType: .regular, initialCount: Constants.counterInitialValue)
let answerOptions = [TimelinePollAnswerOption(id: "1", text: "1", count: 1, winner: false, selected: false),
TimelinePollAnswerOption(id: "2", text: "2", count: 1, winner: false, selected: false),
TimelinePollAnswerOption(id: "3", text: "3", count: 1, winner: false, selected: false)]
let timelinePoll = TimelinePollDetails(id: "poll-id",
question: "Question",
answerOptions: answerOptions,
closed: false,
startDate: .init(),
totalAnswerCount: 3,
type: .disclosed,
eventType: .started,
maxAllowedSelections: 1,
hasBeenEdited: false,
hasDecryptionError: false)
viewModel = PollHistoryDetailViewModel(timelineViewModel: TimelinePollViewModel(timelinePollDetails: timelinePoll))
context = viewModel.context
}
func testInitialState() {
XCTAssertEqual(context.viewState.count, Constants.counterInitialValue)
}
func testCounter() throws {
context.send(viewAction: .incrementCount)
XCTAssertEqual(context.viewState.count, 1)
context.send(viewAction: .incrementCount)
XCTAssertEqual(context.viewState.count, 2)
context.send(viewAction: .decrementCount)
XCTAssertEqual(context.viewState.count, 1)
XCTAssertFalse(context.viewState.isPollClosed)
}
}