diff --git a/MessageKit.xcodeproj/project.pbxproj b/MessageKit.xcodeproj/project.pbxproj index 5b08411a6..9ab3e2466 100644 --- a/MessageKit.xcodeproj/project.pbxproj +++ b/MessageKit.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 382C794221705D2000F4FAF5 /* HorizontalEdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 382C794121705D2000F4FAF5 /* HorizontalEdgeInsets.swift */; }; 383B9EB121728BAD008AB91A /* SenderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 383B9EB021728BAD008AB91A /* SenderType.swift */; }; 38C2AE7C20D4878D00F8079E /* MessageInputBar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38C2AE7B20D4878D00F8079E /* MessageInputBar.framework */; }; + 38F8062F2173CD8F00CDB9DB /* MockUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F8062D2173CD4300CDB9DB /* MockUser.swift */; }; 88916B2D1CF0DF2F00469F91 /* MessageKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88916B221CF0DF2F00469F91 /* MessageKit.framework */; }; 8962AC8A1F87AB7D0030B058 /* MessagesCollectionViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC831F87AB230030B058 /* MessagesCollectionViewTests.swift */; }; 8962AC8C1F87AB7D0030B058 /* AvatarViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC851F87AB230030B058 /* AvatarViewTests.swift */; }; @@ -133,6 +134,7 @@ 382C794121705D2000F4FAF5 /* HorizontalEdgeInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalEdgeInsets.swift; sourceTree = ""; }; 383B9EB021728BAD008AB91A /* SenderType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SenderType.swift; sourceTree = ""; }; 38C2AE7B20D4878D00F8079E /* MessageInputBar.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageInputBar.framework; path = Carthage/Build/iOS/MessageInputBar.framework; sourceTree = ""; }; + 38F8062D2173CD4300CDB9DB /* MockUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUser.swift; sourceTree = ""; }; 88916B221CF0DF2F00469F91 /* MessageKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MessageKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 88916B2C1CF0DF2F00469F91 /* MessageKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MessageKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8962AC741F87AB230030B058 /* MessageKitDateFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageKitDateFormatterTests.swift; sourceTree = ""; }; @@ -300,6 +302,7 @@ children = ( 8962AC7B1F87AB230030B058 /* MockMessage.swift */, 8962AC7A1F87AB230030B058 /* MockMessagesDataSource.swift */, + 38F8062D2173CD4300CDB9DB /* MockUser.swift */, ); path = Mocks; sourceTree = ""; @@ -641,6 +644,7 @@ 1F066E131FD90BB600E11013 /* MessagesViewControllerSpec.swift in Sources */, 1F066E1D1FDA3C1700E11013 /* SenderSpec.swift in Sources */, 8962AC8A1F87AB7D0030B058 /* MessagesCollectionViewTests.swift in Sources */, + 38F8062F2173CD8F00CDB9DB /* MockUser.swift in Sources */, 8962AC8D1F87AB7D0030B058 /* MessageCollectionViewCellTests.swift in Sources */, 8962AC991F87AB860030B058 /* MessagesDisplayDelegateTests.swift in Sources */, 1FD589622064E1B9004B5081 /* MockMessage.swift in Sources */, diff --git a/Tests/ControllersTest/MessagesViewControllerTests.swift b/Tests/ControllersTest/MessagesViewControllerTests.swift index cac274332..8e7a7d783 100644 --- a/Tests/ControllersTest/MessagesViewControllerTests.swift +++ b/Tests/ControllersTest/MessagesViewControllerTests.swift @@ -90,7 +90,7 @@ class MessagesViewControllerTests: XCTestCase { let messagesDataSource = MockMessagesDataSource() sut.messagesCollectionView.messagesDataSource = messagesDataSource messagesDataSource.messages.append(MockMessage(text: "Test", - sender: messagesDataSource.senders[0], + user: messagesDataSource.senders[0], messageId: "test_id")) sut.messagesCollectionView.reloadData() @@ -108,7 +108,7 @@ class MessagesViewControllerTests: XCTestCase { let attributes = [NSAttributedString.Key.foregroundColor: UIColor.black] let attriutedString = NSAttributedString(string: "Test", attributes: attributes) messagesDataSource.messages.append(MockMessage(attributedText: attriutedString, - sender: messagesDataSource.senders[0], + user: messagesDataSource.senders[0], messageId: "test_id")) sut.messagesCollectionView.reloadData() @@ -124,7 +124,7 @@ class MessagesViewControllerTests: XCTestCase { let messagesDataSource = MockMessagesDataSource() sut.messagesCollectionView.messagesDataSource = messagesDataSource messagesDataSource.messages.append(MockMessage(image: UIImage(), - sender: messagesDataSource.senders[0], + user: messagesDataSource.senders[0], messageId: "test_id")) sut.messagesCollectionView.reloadData() @@ -140,7 +140,7 @@ class MessagesViewControllerTests: XCTestCase { let messagesDataSource = MockMessagesDataSource() sut.messagesCollectionView.messagesDataSource = messagesDataSource messagesDataSource.messages.append(MockMessage(thumbnail: UIImage(), - sender: messagesDataSource.senders[0], + user: messagesDataSource.senders[0], messageId: "test_id")) sut.messagesCollectionView.reloadData() @@ -156,7 +156,7 @@ class MessagesViewControllerTests: XCTestCase { let messagesDataSource = MockMessagesDataSource() sut.messagesCollectionView.messagesDataSource = messagesDataSource messagesDataSource.messages.append(MockMessage(location: CLLocation(latitude: 60.0, longitude: 70.0), - sender: messagesDataSource.senders[0], + user: messagesDataSource.senders[0], messageId: "test_id")) sut.messagesCollectionView.reloadData() @@ -170,9 +170,9 @@ class MessagesViewControllerTests: XCTestCase { // MARK: - Assistants - private func makeMessages(for senders: [Sender]) -> [MessageType] { - return [MockMessage(text: "Text 1", sender: senders[0], messageId: "test_id_1"), - MockMessage(text: "Text 2", sender: senders[1], messageId: "test_id_2")] + private func makeMessages(for senders: [MockUser]) -> [MessageType] { + return [MockMessage(text: "Text 1", user: senders[0], messageId: "test_id_1"), + MockMessage(text: "Text 2", user: senders[1], messageId: "test_id_2")] } } diff --git a/Tests/Mocks/MockMessage.swift b/Tests/Mocks/MockMessage.swift index 5d7e9c446..7dc2d36c8 100644 --- a/Tests/Mocks/MockMessage.swift +++ b/Tests/Mocks/MockMessage.swift @@ -56,42 +56,45 @@ struct MockMediaItem: MediaItem { struct MockMessage: MessageType { var messageId: String - var sender: Sender + var sender: SenderType { + return user + } var sentDate: Date var kind: MessageKind + var user: MockUser - private init(kind: MessageKind, sender: Sender, messageId: String) { + private init(kind: MessageKind, user: MockUser, messageId: String) { self.kind = kind - self.sender = sender + self.user = user self.messageId = messageId self.sentDate = Date() } - init(text: String, sender: Sender, messageId: String) { - self.init(kind: .text(text), sender: sender, messageId: messageId) + init(text: String, user: MockUser, messageId: String) { + self.init(kind: .text(text), user: user, messageId: messageId) } - init(attributedText: NSAttributedString, sender: Sender, messageId: String) { - self.init(kind: .attributedText(attributedText), sender: sender, messageId: messageId) + init(attributedText: NSAttributedString, user: MockUser, messageId: String) { + self.init(kind: .attributedText(attributedText), user: user, messageId: messageId) } - init(image: UIImage, sender: Sender, messageId: String) { + init(image: UIImage, user: MockUser, messageId: String) { let mediaItem = MockMediaItem(image: image) - self.init(kind: .photo(mediaItem), sender: sender, messageId: messageId) + self.init(kind: .photo(mediaItem), user: user, messageId: messageId) } - init(thumbnail: UIImage, sender: Sender, messageId: String) { + init(thumbnail: UIImage, user: MockUser, messageId: String) { let mediaItem = MockMediaItem(image: thumbnail) - self.init(kind: .video(mediaItem), sender: sender, messageId: messageId) + self.init(kind: .video(mediaItem), user: user, messageId: messageId) } - init(location: CLLocation, sender: Sender, messageId: String) { + init(location: CLLocation, user: MockUser, messageId: String) { let locationItem = MockLocationItem(location: location) - self.init(kind: .location(locationItem), sender: sender, messageId: messageId) + self.init(kind: .location(locationItem), user: user, messageId: messageId) } - init(emoji: String, sender: Sender, messageId: String) { - self.init(kind: .emoji(emoji), sender: sender, messageId: messageId) + init(emoji: String, user: MockUser, messageId: String) { + self.init(kind: .emoji(emoji), user: user, messageId: messageId) } } diff --git a/Tests/Mocks/MockMessagesDataSource.swift b/Tests/Mocks/MockMessagesDataSource.swift index 566d8d278..59ff06f38 100644 --- a/Tests/Mocks/MockMessagesDataSource.swift +++ b/Tests/Mocks/MockMessagesDataSource.swift @@ -28,13 +28,17 @@ import Foundation class MockMessagesDataSource: MessagesDataSource { var messages: [MessageType] = [] - let senders: [Sender] = [Sender(id: "sender_1", displayName: "Sender 1"), - Sender(id: "sender_2", displayName: "Sender 2")] + let senders: [MockUser] = [MockUser(id: "sender_1", displayName: "Sender 1"), + MockUser(id: "sender_2", displayName: "Sender 2")] - func currentSender() -> Sender { + var currentUser: MockUser { return senders[0] } + func currentSender() -> SenderType { + return currentUser + } + func numberOfSections(in messagesCollectionView: MessagesCollectionView) -> Int { return messages.count } diff --git a/Tests/Mocks/MockUser.swift b/Tests/Mocks/MockUser.swift new file mode 100644 index 000000000..cfeb6a769 --- /dev/null +++ b/Tests/Mocks/MockUser.swift @@ -0,0 +1,31 @@ +/* + MIT License + + Copyright (c) 2017-2018 MessageKit + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import Foundation +@testable import MessageKit + +struct MockUser: SenderType { + var id: String + var displayName: String +} diff --git a/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift b/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift index 4d2dae9d6..7d0db3a7a 100644 --- a/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift +++ b/Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift @@ -76,7 +76,7 @@ class MessagesDisplayDelegateTests: XCTestCase { func testBackgroundColorForMessageWithEmoji_returnsClearForDefault() { sut.dataProvider.messages.append(MockMessage(emoji: "🤔", - sender: sut.dataProvider.currentSender(), + user: sut.dataProvider.currentUser, messageId: "003")) let backgroundColor = sut.backgroundColor(for: sut.dataProvider.messages[2], at: IndexPath(item: 0, section: 0), @@ -196,10 +196,10 @@ private class MockMessagesViewController: MessagesViewController, MessagesDispla fileprivate func makeDataSource() -> MockMessagesDataSource { let dataSource = MockMessagesDataSource() dataSource.messages.append(MockMessage(text: "Text 1", - sender: dataSource.senders[0], + user: dataSource.senders[0], messageId: "001")) dataSource.messages.append(MockMessage(text: "Text 2", - sender: dataSource.senders[1], + user: dataSource.senders[1], messageId: "002")) return dataSource diff --git a/Tests/SenderSpec.swift b/Tests/SenderSpec.swift index 56910a3d3..ee2fb73f5 100644 --- a/Tests/SenderSpec.swift +++ b/Tests/SenderSpec.swift @@ -32,16 +32,16 @@ final class SenderSpec: QuickSpec { describe("equality between two Senders") { context("they have the same id ") { it("should be equal") { - let sender1 = Sender(id: "1", displayName: "Steven") - let sender2 = Sender(id: "1", displayName: "Nathan") - expect(sender1).to(equal(sender2)) + let sender1 = MockUser(id: "1", displayName: "Steven") + let sender2 = MockUser(id: "1", displayName: "Nathan") + expect(sender1.isEqualTo(sender2)).to(equal(true)) } } context("they have a different id") { it("should not be equal") { - let sender1 = Sender(id: "1", displayName: "Steven") - let sender2 = Sender(id: "2", displayName: "Nathan") - expect(sender1).toNot(equal(sender2)) + let sender1 = MockUser(id: "1", displayName: "Steven") + let sender2 = MockUser(id: "2", displayName: "Nathan") + expect(sender1.isEqualTo(sender2)).to(equal(false)) } } }