-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...mChatSwiftUITests/Tests/ChatChannel/MessageList/Polls/PollAttachmentViewModel_Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// Copyright © 2024 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
@testable import StreamChat | ||
@testable import StreamChatSwiftUI | ||
import SwiftUI | ||
import XCTest | ||
|
||
final class PollAttachmentViewModel_Tests: StreamChatTestCase { | ||
func test_hasMostVotes_whenWinningVote() { | ||
// Given | ||
let poll = Poll.mock(optionCount: 3, voteCountForOption: { optionIndex in | ||
switch optionIndex { | ||
case 0: return 2 | ||
case 1: return 3 | ||
case 2: return 1 | ||
default: return 0 | ||
} | ||
}) | ||
let message = ChatMessage.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: "", | ||
author: .mock(id: .unique), | ||
poll: poll | ||
) | ||
|
||
// When | ||
let viewModel = PollAttachmentViewModel(message: message, poll: poll) | ||
|
||
// Then | ||
XCTAssertEqual(viewModel.hasMostVotes(for: poll.options[0]), false) | ||
XCTAssertEqual(viewModel.hasMostVotes(for: poll.options[1]), true) | ||
XCTAssertEqual(viewModel.hasMostVotes(for: poll.options[2]), false) | ||
} | ||
|
||
func test_hasMostVotes_whenEqualHighestVotes() { | ||
// Given | ||
let poll = Poll.mock(optionCount: 3, voteCountForOption: { optionIndex in | ||
switch optionIndex { | ||
case 0: return 2 | ||
case 1: return 3 | ||
case 2: return 3 | ||
default: return 0 | ||
} | ||
}) | ||
let message = ChatMessage.mock( | ||
id: .unique, | ||
cid: .unique, | ||
text: "", | ||
author: .mock(id: .unique), | ||
poll: poll | ||
) | ||
|
||
// When | ||
let viewModel = PollAttachmentViewModel(message: message, poll: poll) | ||
|
||
// Then | ||
XCTAssertEqual(false, viewModel.hasMostVotes(for: poll.options[0])) | ||
XCTAssertEqual(false, viewModel.hasMostVotes(for: poll.options[1])) | ||
XCTAssertEqual(false, viewModel.hasMostVotes(for: poll.options[2])) | ||
} | ||
} |