Fix tests.

pull/1/head
Matthew Chen 7 years ago
parent 8063886a41
commit 6b39f73e65

@ -59,6 +59,11 @@ public class ContactsPicker: OWSViewController, UITableViewDelegate, UITableView
} }
private let collation = UILocalizedIndexedCollation.current() private let collation = UILocalizedIndexedCollation.current()
public var collationForTests: UILocalizedIndexedCollation {
get {
return collation
}
}
private let contactStore = CNContactStore() private let contactStore = CNContactStore()
// Data Source State // Data Source State

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
import XCTest import XCTest
@ -12,35 +12,37 @@ import WebRTC
class FakePeerConnectionClientDelegate: PeerConnectionClientDelegate { class FakePeerConnectionClientDelegate: PeerConnectionClientDelegate {
enum ConnectionState { enum ConnectionState {
case connected, failed case connected, disconnected, failed
} }
var connectionState: ConnectionState? var connectionState: ConnectionState?
var localIceCandidates = [RTCIceCandidate]() var localIceCandidates = [RTCIceCandidate]()
var dataChannelMessages = [OWSWebRTCProtosData]() var dataChannelMessages = [OWSWebRTCProtosData]()
internal func peerConnectionClientIceConnected(_ peerconnectionClient: PeerConnectionClient) { func peerConnectionClientIceConnected(_ peerconnectionClient: PeerConnectionClient) {
connectionState = .connected connectionState = .connected
} }
internal func peerConnectionClientIceFailed(_ peerconnectionClient: PeerConnectionClient) { func peerConnectionClientIceDisconnected(_ peerconnectionClient: PeerConnectionClient) {
connectionState = .disconnected
}
func peerConnectionClientIceFailed(_ peerconnectionClient: PeerConnectionClient) {
connectionState = .failed connectionState = .failed
} }
internal func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, addedLocalIceCandidate iceCandidate: RTCIceCandidate) { func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, addedLocalIceCandidate iceCandidate: RTCIceCandidate) {
localIceCandidates.append(iceCandidate) localIceCandidates.append(iceCandidate)
} }
internal func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, received dataChannelMessage: OWSWebRTCProtosData) { func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, received dataChannelMessage: OWSWebRTCProtosData) {
dataChannelMessages.append(dataChannelMessage) dataChannelMessages.append(dataChannelMessage)
} }
internal func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocal videoTrack: RTCVideoTrack?) { func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocal videoTrack: RTCVideoTrack?) {
} }
internal func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateRemote videoTrack: RTCVideoTrack?) { func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateRemote videoTrack: RTCVideoTrack?) {
} }
} }

@ -32,10 +32,10 @@ final class ContactsPickerTest: XCTestCase {
let emailOnlyContactD = CNMutableContact() let emailOnlyContactD = CNMutableContact()
emailOnlyContactD.emailAddresses.append(CNLabeledValue(label: nil, value: "dude@bla.com")) emailOnlyContactD.emailAddresses.append(CNLabeledValue(label: nil, value: "dude@bla.com"))
let contactsPicker = ContactsPicker(delegate: nil) let contactsPicker = ContactsPicker(allowsMultipleSelection: false, subtitleCellType: .phoneNumber)
let collatedContacts = contactsPicker.collatedContacts([emailOnlyContactB, emailOnlyContactD]) let collatedContacts = contactsPicker.collatedContacts([emailOnlyContactB, emailOnlyContactD])
let sectionTitles = contactsPicker.collation.sectionTitles let sectionTitles = contactsPicker.collationForTests.sectionTitles
if let bIndex = sectionTitles.index(of: "B") { if let bIndex = sectionTitles.index(of: "B") {
let bSectionContacts = collatedContacts[bIndex] let bSectionContacts = collatedContacts[bIndex]
XCTAssertEqual(bSectionContacts.first, emailOnlyContactB) XCTAssertEqual(bSectionContacts.first, emailOnlyContactB)
@ -54,10 +54,10 @@ final class ContactsPickerTest: XCTestCase {
nameAndEmailContact.givenName = "Alice" nameAndEmailContact.givenName = "Alice"
nameAndEmailContact.emailAddresses.append(CNLabeledValue(label: nil, value: "nameAndEmail@bla.com")) nameAndEmailContact.emailAddresses.append(CNLabeledValue(label: nil, value: "nameAndEmail@bla.com"))
let contactsPicker = ContactsPicker(delegate: nil) let contactsPicker = ContactsPicker(allowsMultipleSelection: false, subtitleCellType: .phoneNumber)
let collatedContacts = contactsPicker.collatedContacts([nameAndEmailContact]) let collatedContacts = contactsPicker.collatedContacts([nameAndEmailContact])
let sectionTitles = contactsPicker.collation.sectionTitles let sectionTitles = contactsPicker.collationForTests.sectionTitles
if let aIndex = sectionTitles.index(of: "A") { if let aIndex = sectionTitles.index(of: "A") {
let aSectionContacts = collatedContacts[aIndex] let aSectionContacts = collatedContacts[aIndex]
XCTAssertEqual(aSectionContacts.first, nameAndEmailContact) XCTAssertEqual(aSectionContacts.first, nameAndEmailContact)

Loading…
Cancel
Save