Skip to content

Commit

Permalink
unit tests and refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Dec 19, 2014
1 parent ea3b8cc commit 395b134
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 25 deletions.
12 changes: 12 additions & 0 deletions JSQMessages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
88A2601919D8E18400924534 /* JSQMessagesTypingIndicatorFooterViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A2600019D8E18400924534 /* JSQMessagesTypingIndicatorFooterViewTests.m */; };
88A2601B19D8E45600924534 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 88A2601A19D8E45600924534 /* Info.plist */; };
88A901B619F618B100F99777 /* JSQMediaItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A901B519F618B100F99777 /* JSQMediaItem.m */; };
88C00A4E1A44D4C600B004B3 /* JSQLocationMediaItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88C00A4D1A44D4C600B004B3 /* JSQLocationMediaItemTests.m */; };
88C00A501A44D4D800B004B3 /* JSQPhotoMediaItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88C00A4F1A44D4D800B004B3 /* JSQPhotoMediaItemTests.m */; };
88C00A521A44D4E500B004B3 /* JSQVideoMediaItemTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88C00A511A44D4E500B004B3 /* JSQVideoMediaItemTests.m */; };
88C4583019F5F7A0008FD427 /* JSQMessagesMediaViewBubbleImageMasker.m in Sources */ = {isa = PBXBuildFile; fileRef = 88C4582F19F5F7A0008FD427 /* JSQMessagesMediaViewBubbleImageMasker.m */; };
88E4D7131A0DBD6B000CC061 /* JSQMessages.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8841B88719F4988800EA16B6 /* JSQMessages.strings */; };
94A4FA20C2FBD0D62614D5A8 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97E6750B77E8A7042BA0754B /* libPods.a */; };
Expand Down Expand Up @@ -268,6 +271,9 @@
88A2601A19D8E45600924534 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
88A901B419F618B100F99777 /* JSQMediaItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSQMediaItem.h; sourceTree = "<group>"; };
88A901B519F618B100F99777 /* JSQMediaItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQMediaItem.m; sourceTree = "<group>"; };
88C00A4D1A44D4C600B004B3 /* JSQLocationMediaItemTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQLocationMediaItemTests.m; sourceTree = "<group>"; };
88C00A4F1A44D4D800B004B3 /* JSQPhotoMediaItemTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQPhotoMediaItemTests.m; sourceTree = "<group>"; };
88C00A511A44D4E500B004B3 /* JSQVideoMediaItemTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQVideoMediaItemTests.m; sourceTree = "<group>"; };
88C4582E19F5F7A0008FD427 /* JSQMessagesMediaViewBubbleImageMasker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSQMessagesMediaViewBubbleImageMasker.h; sourceTree = "<group>"; };
88C4582F19F5F7A0008FD427 /* JSQMessagesMediaViewBubbleImageMasker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSQMessagesMediaViewBubbleImageMasker.m; sourceTree = "<group>"; };
97E6750B77E8A7042BA0754B /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -602,10 +608,13 @@
88A25FF219D8E18400924534 /* ModelTests */ = {
isa = PBXGroup;
children = (
88C00A4D1A44D4C600B004B3 /* JSQLocationMediaItemTests.m */,
88A25FF319D8E18400924534 /* JSQMessageMediaTests.m */,
88A25FF419D8E18400924534 /* JSQMessagesAvatarImageTests.m */,
88A25FF519D8E18400924534 /* JSQMessagesBubbleImageTests.m */,
88A25FF619D8E18400924534 /* JSQMessageTextTests.m */,
88C00A4F1A44D4D800B004B3 /* JSQPhotoMediaItemTests.m */,
88C00A511A44D4E500B004B3 /* JSQVideoMediaItemTests.m */,
);
path = ModelTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -865,6 +874,7 @@
files = (
88A2600219D8E18400924534 /* JSQMessagesUIColorTests.m in Sources */,
88A2601819D8E18400924534 /* JSQMessagesToolbarContentViewTests.m in Sources */,
88C00A521A44D4E500B004B3 /* JSQVideoMediaItemTests.m in Sources */,
88A2601519D8E18400924534 /* JSQMessagesInputToolbarTests.m in Sources */,
88A2601719D8E18400924534 /* JSQMessagesLoadEarlierHeaderViewTests.m in Sources */,
88A2601219D8E18400924534 /* JSQMessagesCollectionViewCellTests.m in Sources */,
Expand All @@ -881,9 +891,11 @@
88A2601319D8E18400924534 /* JSQMessagesCollectionViewTests.m in Sources */,
88A2600119D8E18400924534 /* JSQMessagesNSStringTests.m in Sources */,
88A2600A19D8E18400924534 /* JSQMessagesToolbarButtonFactoryTests.m in Sources */,
88C00A501A44D4D800B004B3 /* JSQPhotoMediaItemTests.m in Sources */,
88324C3419F6301C00BC732D /* JSQMessagesMediaViewBubbleImageMaskerTests.m in Sources */,
88A2601919D8E18400924534 /* JSQMessagesTypingIndicatorFooterViewTests.m in Sources */,
88A2600319D8E18400924534 /* JSQMessagesUIImageTests.m in Sources */,
88C00A4E1A44D4C600B004B3 /* JSQLocationMediaItemTests.m in Sources */,
88A2600C19D8E18400924534 /* JSQMessagesCollectionViewLayoutAttributesTests.m in Sources */,
88A2600619D8E18400924534 /* JSQMessagesViewControllerTests.m in Sources */,
88A2600519D8E18400924534 /* JSQMessagesKeyboardControllerTests.m in Sources */,
Expand Down
64 changes: 64 additions & 0 deletions JSQMessagesTests/ModelTests/JSQLocationMediaItemTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// Created by Jesse Squires
// http://www.jessesquires.com
//
//
// MIT License
// Copyright (c) 2014 Jesse Squires
// http://opensource.org/licenses/MIT
//

#import <XCTest/XCTest.h>

#import "JSQLocationMediaItem.h"


@interface JSQLocationMediaItemTests : XCTestCase

@property (strong, nonatomic) CLLocation *location;

@end


@implementation JSQLocationMediaItemTests

- (void)setUp
{
[super setUp];
self.location = [[CLLocation alloc] initWithLatitude:37.795313 longitude:-122.393757];
}

- (void)tearDown
{
self.location = nil;
[super tearDown];
}

- (void)testLocationItemInit
{
JSQLocationMediaItem *item = [[JSQLocationMediaItem alloc] initWithLocation:self.location];
XCTAssertNotNil(item);
}

- (void)testMediaDataProtocol
{
JSQLocationMediaItem *item = [[JSQLocationMediaItem alloc] init];

XCTAssertTrue(!CGSizeEqualToSize([item mediaViewDisplaySize], CGSizeZero));
XCTAssertNotNil([item mediaPlaceholderView]);
XCTAssertNil([item mediaView], @"Media view should be nil if location is nil");

XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __PRETTY_FUNCTION__]];

[item setLocation:self.location withCompletionHandler:^{
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:5 handler:^(NSError *error) {
XCTAssertNil(error, @"Expectation should not error");
}];

XCTAssertNotNil([item mediaView], @"Media view should NOT be nil once item has media data");
}

@end
20 changes: 10 additions & 10 deletions JSQMessagesTests/ModelTests/JSQMessageMediaTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ - (void)tearDown
- (void)testMediaMessageInit
{
JSQMessage *msg = [[JSQMessage alloc] initWithSenderId:self.senderId
senderDisplayName:self.senderDisplayName
date:self.date
media:self.mockMediaData];
senderDisplayName:self.senderDisplayName
date:self.date
media:self.mockMediaData];
XCTAssertNotNil(msg, @"Message should not be nil");
}

Expand All @@ -83,24 +83,24 @@ - (void)testMediaMessageInvalidInit
- (void)testMediaMessageIsEqual
{
JSQMessage *msg = [[JSQMessage alloc] initWithSenderId:self.senderId
senderDisplayName:self.senderDisplayName
date:self.date
media:self.mockMediaData];
senderDisplayName:self.senderDisplayName
date:self.date
media:self.mockMediaData];
JSQMessage *copy = [msg copy];

XCTAssertEqualObjects(msg, copy, @"Copied messages should be equal");

XCTAssertEqual([msg hash], [copy hash], @"Copied messages hashes should be equal");

XCTAssertEqualObjects(msg, copy, @"Copied messages should be equal");
XCTAssertEqualObjects(msg, msg, @"Messages should be equal to itself");
}

- (void)testMediaMessageArchiving
{
JSQMessage *msg = [[JSQMessage alloc] initWithSenderId:self.senderId
senderDisplayName:self.senderDisplayName
date:self.date
media:[FakeMedia new]];
senderDisplayName:self.senderDisplayName
date:self.date
media:[FakeMedia new]];

NSData *msgData = [NSKeyedArchiver archivedDataWithRootObject:msg];

Expand Down
2 changes: 1 addition & 1 deletion JSQMessagesTests/ModelTests/JSQMessageTextTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ - (void)testTextMessageIsEqual
JSQMessage *copy = [msg copy];

XCTAssertEqualObjects(msg, copy, @"Copied messages should be equal");

XCTAssertEqual([msg hash], [copy hash], @"Copied messages hashes should be equal");

XCTAssertEqualObjects(msg, copy, @"Copied messages should be equal");
XCTAssertEqualObjects(msg, msg, @"Messages should be equal to itself");
}

Expand Down
76 changes: 76 additions & 0 deletions JSQMessagesTests/ModelTests/JSQPhotoMediaItemTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Created by Jesse Squires
// http://www.jessesquires.com
//
//
// MIT License
// Copyright (c) 2014 Jesse Squires
// http://opensource.org/licenses/MIT
//

#import <XCTest/XCTest.h>

#import "JSQPhotoMediaItem.h"


@interface JSQPhotoMediaItemTests : XCTestCase

@end


@implementation JSQPhotoMediaItemTests

- (void)setUp
{
[super setUp];
}

- (void)tearDown
{
[super tearDown];
}

- (void)testPhotoItemInit
{
JSQPhotoMediaItem *item = [[JSQPhotoMediaItem alloc] initWithImage:[UIImage new]];
XCTAssertNotNil(item);
}

- (void)testPhotoItemIsEqual
{
JSQPhotoMediaItem *item = [[JSQPhotoMediaItem alloc] initWithImage:[UIImage imageNamed:@"demo_avatar_jobs"]];

JSQPhotoMediaItem *copy = [item copy];

XCTAssertEqualObjects(item, copy, @"Copied items should be equal");

XCTAssertEqual([item hash], [copy hash], @"Copied item hashes should be equal");

XCTAssertEqualObjects(item, item, @"Item should be equal to itself");
}

- (void)testPhotoItemArchiving
{
JSQPhotoMediaItem *item = [[JSQPhotoMediaItem alloc] initWithImage:[UIImage new]];

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:item];

JSQPhotoMediaItem *unarchivedItem = [NSKeyedUnarchiver unarchiveObjectWithData:data];

XCTAssertEqualObjects(item, unarchivedItem);
}

- (void)testMediaDataProtocol
{
JSQPhotoMediaItem *item = [[JSQPhotoMediaItem alloc] initWithImage:nil];

XCTAssertTrue(!CGSizeEqualToSize([item mediaViewDisplaySize], CGSizeZero));
XCTAssertNotNil([item mediaPlaceholderView]);
XCTAssertNil([item mediaView], @"Media view should be nil if image is nil");

item.image = [UIImage imageNamed:@"demo_avatar_jobs"];

XCTAssertNotNil([item mediaView], @"Media view should NOT be nil once item has media data");
}

@end
77 changes: 77 additions & 0 deletions JSQMessagesTests/ModelTests/JSQVideoMediaItemTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// Created by Jesse Squires
// http://www.jessesquires.com
//
//
// MIT License
// Copyright (c) 2014 Jesse Squires
// http://opensource.org/licenses/MIT
//

#import <XCTest/XCTest.h>

#import "JSQVideoMediaItem.h"


@interface JSQVideoMediaItemTests : XCTestCase

@end


@implementation JSQVideoMediaItemTests

- (void)setUp
{
[super setUp];
}

- (void)tearDown
{
[super tearDown];
}

- (void)testVideoMediaItemInit
{
JSQVideoMediaItem *item = [[JSQVideoMediaItem alloc] initWithFileURL:[NSURL URLWithString:@"file://"] isReadyToPlay:NO];
XCTAssertNotNil(item);
}

- (void)testVideoItemIsEqual
{
JSQVideoMediaItem *item = [[JSQVideoMediaItem alloc] initWithFileURL:[NSURL URLWithString:@"file://"] isReadyToPlay:YES];

JSQVideoMediaItem *copy = [item copy];

XCTAssertEqualObjects(item, copy, @"Copied items should be equal");

XCTAssertEqual([item hash], [copy hash], @"Copied item hashes should be equal");

XCTAssertEqualObjects(item, item, @"Item should be equal to itself");
}

- (void)testVideoItemArchiving
{
JSQVideoMediaItem *item = [[JSQVideoMediaItem alloc] initWithFileURL:[NSURL URLWithString:@"file://"] isReadyToPlay:YES];

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:item];

JSQVideoMediaItem *unarchivedItem = [NSKeyedUnarchiver unarchiveObjectWithData:data];

XCTAssertEqualObjects(item, unarchivedItem);
}

- (void)testMediaDataProtocol
{
JSQVideoMediaItem *item = [[JSQVideoMediaItem alloc] init];

XCTAssertTrue(!CGSizeEqualToSize([item mediaViewDisplaySize], CGSizeZero));
XCTAssertNotNil([item mediaPlaceholderView]);
XCTAssertNil([item mediaView], @"Media view should be nil if fileURL is nil, and readyToPlay is NO");

item.fileURL = [NSURL URLWithString:@"file://"];
item.isReadyToPlay = YES;

XCTAssertNotNil([item mediaView], @"Media view should NOT be nil once item has media data");
}

@end
2 changes: 1 addition & 1 deletion JSQMessagesViewController/Model/JSQLocationMediaItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ - (BOOL)isEqual:(id)object

- (NSUInteger)hash
{
return self.location.hash;
return super.hash ^ self.location.hash;
}

- (NSString *)description
Expand Down
13 changes: 1 addition & 12 deletions JSQMessagesViewController/Model/JSQPhotoMediaItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,9 @@ - (UIView *)mediaView

#pragma mark - NSObject

- (BOOL)isEqual:(id)object
{
if (![super isEqual:object]) {
return NO;
}

JSQPhotoMediaItem *photoItem = (JSQPhotoMediaItem *)object;

return [self.image isEqual:photoItem.image];
}

- (NSUInteger)hash
{
return self.image.hash;
return super.hash ^ self.image.hash;
}

- (NSString *)description
Expand Down
2 changes: 1 addition & 1 deletion JSQMessagesViewController/Model/JSQVideoMediaItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ - (BOOL)isEqual:(id)object

- (NSUInteger)hash
{
return self.fileURL.hash;
return super.hash ^ self.fileURL.hash;
}

- (NSString *)description
Expand Down

0 comments on commit 395b134

Please sign in to comment.