Skip to content

Commit

Permalink
Update Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Nov 26, 2018
1 parent 762f583 commit 308eb6b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 35 deletions.
4 changes: 4 additions & 0 deletions MessageKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -133,6 +134,7 @@
382C794121705D2000F4FAF5 /* HorizontalEdgeInsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalEdgeInsets.swift; sourceTree = "<group>"; };
383B9EB021728BAD008AB91A /* SenderType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SenderType.swift; sourceTree = "<group>"; };
38C2AE7B20D4878D00F8079E /* MessageInputBar.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageInputBar.framework; path = Carthage/Build/iOS/MessageInputBar.framework; sourceTree = "<group>"; };
38F8062D2173CD4300CDB9DB /* MockUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUser.swift; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -300,6 +302,7 @@
children = (
8962AC7B1F87AB230030B058 /* MockMessage.swift */,
8962AC7A1F87AB230030B058 /* MockMessagesDataSource.swift */,
38F8062D2173CD4300CDB9DB /* MockUser.swift */,
);
path = Mocks;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
16 changes: 8 additions & 8 deletions Tests/ControllersTest/MessagesViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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")]
}

}
Expand Down
33 changes: 18 additions & 15 deletions Tests/Mocks/MockMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
10 changes: 7 additions & 3 deletions Tests/Mocks/MockMessagesDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
31 changes: 31 additions & 0 deletions Tests/Mocks/MockUser.swift
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions Tests/ProtocolsTests/MessagesDisplayDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Tests/SenderSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit 308eb6b

Please sign in to comment.