mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Improve tests
This commit is contained in:
@@ -42,7 +42,7 @@ final class PollHistoryViewModelTests: XCTestCase {
|
||||
|
||||
func testLoadingStateIsTrueWhileLoading() {
|
||||
XCTAssertFalse(viewModel.state.isLoading)
|
||||
pollHistoryService.nextBatchPublishers = [loadingPublisher, emptyPublisher]
|
||||
pollHistoryService.nextBatchPublishers = [MockPollPublisher.loadingPolls, MockPollPublisher.emptyPolls]
|
||||
viewModel.process(viewAction: .viewAppeared)
|
||||
XCTAssertTrue(viewModel.state.isLoading)
|
||||
viewModel.process(viewAction: .viewAppeared)
|
||||
@@ -83,12 +83,40 @@ final class PollHistoryViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testLivePollsAreHandled() throws {
|
||||
pollHistoryService.nextBatchPublishers = [emptyPublisher]
|
||||
pollHistoryService.nextBatchPublishers = [MockPollPublisher.emptyPolls]
|
||||
pollHistoryService.livePollsPublisher = Just(mockPoll).eraseToAnyPublisher()
|
||||
viewModel.process(viewAction: .viewAppeared)
|
||||
XCTAssertEqual(viewModel.state.polls?.count, 1)
|
||||
XCTAssertEqual(viewModel.state.polls?.first?.id, "id")
|
||||
}
|
||||
|
||||
func testLivePollsDontChangeLoadingState() throws {
|
||||
let livePolls = PassthroughSubject<TimelinePollDetails, Never>()
|
||||
pollHistoryService.nextBatchPublishers = [MockPollPublisher.loadingPolls]
|
||||
pollHistoryService.livePollsPublisher = livePolls.eraseToAnyPublisher()
|
||||
viewModel.process(viewAction: .viewAppeared)
|
||||
XCTAssertTrue(viewModel.state.isLoading)
|
||||
XCTAssertNil(viewModel.state.polls)
|
||||
livePolls.send(mockPoll)
|
||||
XCTAssertTrue(viewModel.state.isLoading)
|
||||
XCTAssertNotNil(viewModel.state.polls)
|
||||
XCTAssertEqual(viewModel.state.polls?.count, 1)
|
||||
}
|
||||
|
||||
func testAfterFailureCompletionIsCalled() throws {
|
||||
let expectation = expectation(description: #function)
|
||||
|
||||
pollHistoryService.nextBatchPublishers = [MockPollPublisher.failure]
|
||||
viewModel.completion = { event in
|
||||
XCTAssertEqual(event, .genericError)
|
||||
expectation.fulfill()
|
||||
}
|
||||
viewModel.process(viewAction: .viewAppeared)
|
||||
XCTAssertFalse(viewModel.state.isLoading)
|
||||
XCTAssertNotNil(viewModel.state.polls)
|
||||
|
||||
wait(for: [expectation], timeout: 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
private extension PollHistoryViewModelTests {
|
||||
@@ -98,14 +126,6 @@ private extension PollHistoryViewModelTests {
|
||||
}
|
||||
}
|
||||
|
||||
var loadingPublisher: AnyPublisher<TimelinePollDetails, Error> {
|
||||
Empty(completeImmediately: false, outputType: TimelinePollDetails.self, failureType: Error.self).eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
var emptyPublisher: AnyPublisher<TimelinePollDetails, Error> {
|
||||
Empty(completeImmediately: true, outputType: TimelinePollDetails.self, failureType: Error.self).eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
var mockPoll: TimelinePollDetails {
|
||||
.init(id: "id",
|
||||
question: "Do you like polls?",
|
||||
|
||||
Reference in New Issue
Block a user