Skip to content

Commit

Permalink
Splits tests; fixes auto-completion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Romero Zurbuchen committed Jan 18, 2016
1 parent bd7a3d5 commit 3f45226
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 78 deletions.
7 changes: 3 additions & 4 deletions .xctool-args
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[
"-workspace", "Tests/SlackTextViewControllerTests.xcworkspace",
"-scheme", "Tests",
"-workspace", "SlackTextViewController/SlackTextViewController.xcworkspace",
"-scheme", "SnapshotTests",
"-sdk", "iphonesimulator",
"-configuration", "Debug",
"-destination", "name=iPhone 4s,OS=8.1",
"-destination", "name=iPhone 5s,OS=8.1",
"-destination", "name=iPhone 6s,OS=9.2",
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
2F0E1D8DBCEA48E44AE1C143 /* libPods-SnapshotTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6327B11F9C471674A5F8BEBC /* libPods-SnapshotTests.a */; };
F559D04B1C4DAD5700FCBFFA /* AutoCompletionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F559D04A1C4DAD5700FCBFFA /* AutoCompletionTests.m */; };
F5A782781BD0CEF300EC230B /* SlackTextViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = F5A782771BD0CEF300EC230B /* SlackTextViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
F5A782A41BD0CF1D00EC230B /* SLKInputAccessoryView.h in Headers */ = {isa = PBXBuildFile; fileRef = F5A782901BD0CF1D00EC230B /* SLKInputAccessoryView.h */; settings = {ATTRIBUTES = (Public, ); }; };
F5A782A51BD0CF1D00EC230B /* SLKInputAccessoryView.m in Sources */ = {isa = PBXBuildFile; fileRef = F5A782911BD0CF1D00EC230B /* SLKInputAccessoryView.m */; };
Expand All @@ -34,7 +35,7 @@
F5B4E7A61C4DA0B4005CBBE0 /* SlackTextViewController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5A782741BD0CEF300EC230B /* SlackTextViewController.framework */; };
F5B4E7B31C4DA0BC005CBBE0 /* UITests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7B21C4DA0BC005CBBE0 /* UITests.m */; };
F5B4E7BB1C4DA24C005CBBE0 /* EXPMatchers+FBSnapshotTestExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7BA1C4DA24C005CBBE0 /* EXPMatchers+FBSnapshotTestExtensions.m */; };
F5B4E7BD1C4DA28A005CBBE0 /* SLKTextViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7BC1C4DA28A005CBBE0 /* SLKTextViewControllerTests.m */; };
F5B4E7BD1C4DA28A005CBBE0 /* DisplayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7BC1C4DA28A005CBBE0 /* DisplayTests.m */; };
F5B4E7C71C4DA2B8005CBBE0 /* NSString+LoremIpsum.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7C01C4DA2B8005CBBE0 /* NSString+LoremIpsum.m */; };
F5B4E7C81C4DA2B8005CBBE0 /* SLKTextInputbarStub.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7C21C4DA2B8005CBBE0 /* SLKTextInputbarStub.m */; };
F5B4E7C91C4DA2B8005CBBE0 /* SLKTextViewControllerStub.m in Sources */ = {isa = PBXBuildFile; fileRef = F5B4E7C41C4DA2B8005CBBE0 /* SLKTextViewControllerStub.m */; };
Expand Down Expand Up @@ -74,6 +75,7 @@
6327B11F9C471674A5F8BEBC /* libPods-SnapshotTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SnapshotTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
A6F4DB55302A979898CA257B /* Pods-SnapshotTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapshotTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SnapshotTests/Pods-SnapshotTests.debug.xcconfig"; sourceTree = "<group>"; };
CFFC0243895409AFFF7CC9F6 /* Pods-SnapshotTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapshotTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnapshotTests/Pods-SnapshotTests.release.xcconfig"; sourceTree = "<group>"; };
F559D04A1C4DAD5700FCBFFA /* AutoCompletionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AutoCompletionTests.m; sourceTree = "<group>"; };
F5A782741BD0CEF300EC230B /* SlackTextViewController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SlackTextViewController.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F5A782771BD0CEF300EC230B /* SlackTextViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SlackTextViewController.h; sourceTree = "<group>"; };
F5A782791BD0CEF400EC230B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -107,7 +109,7 @@
F5B4E7B41C4DA0BC005CBBE0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F5B4E7B91C4DA24C005CBBE0 /* EXPMatchers+FBSnapshotTestExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "EXPMatchers+FBSnapshotTestExtensions.h"; sourceTree = "<group>"; };
F5B4E7BA1C4DA24C005CBBE0 /* EXPMatchers+FBSnapshotTestExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "EXPMatchers+FBSnapshotTestExtensions.m"; sourceTree = "<group>"; };
F5B4E7BC1C4DA28A005CBBE0 /* SLKTextViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SLKTextViewControllerTests.m; sourceTree = "<group>"; };
F5B4E7BC1C4DA28A005CBBE0 /* DisplayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DisplayTests.m; sourceTree = "<group>"; };
F5B4E7BF1C4DA2B8005CBBE0 /* NSString+LoremIpsum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+LoremIpsum.h"; sourceTree = "<group>"; };
F5B4E7C01C4DA2B8005CBBE0 /* NSString+LoremIpsum.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+LoremIpsum.m"; sourceTree = "<group>"; };
F5B4E7C11C4DA2B8005CBBE0 /* SLKTextInputbarStub.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SLKTextInputbarStub.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -264,7 +266,8 @@
children = (
F5B4E7BE1C4DA2B8005CBBE0 /* Stubs */,
F5B4E7B81C4DA24C005CBBE0 /* Extensions */,
F5B4E7BC1C4DA28A005CBBE0 /* SLKTextViewControllerTests.m */,
F5B4E7BC1C4DA28A005CBBE0 /* DisplayTests.m */,
F559D04A1C4DAD5700FCBFFA /* AutoCompletionTests.m */,
F5B4E7A51C4DA0B4005CBBE0 /* Info.plist */,
);
path = SnapshotTests;
Expand Down Expand Up @@ -595,10 +598,11 @@
files = (
F5B4E7CA1C4DA2B8005CBBE0 /* SLKTextViewStub.m in Sources */,
F5B4E7BB1C4DA24C005CBBE0 /* EXPMatchers+FBSnapshotTestExtensions.m in Sources */,
F559D04B1C4DAD5700FCBFFA /* AutoCompletionTests.m in Sources */,
F5B4E7C71C4DA2B8005CBBE0 /* NSString+LoremIpsum.m in Sources */,
F5B4E7C91C4DA2B8005CBBE0 /* SLKTextViewControllerStub.m in Sources */,
F5B4E7C81C4DA2B8005CBBE0 /* SLKTextInputbarStub.m in Sources */,
F5B4E7BD1C4DA28A005CBBE0 /* SLKTextViewControllerTests.m in Sources */,
F5B4E7BD1C4DA28A005CBBE0 /* DisplayTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -927,6 +931,7 @@
F5B4E81C1C4DA335005CBBE0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
88 changes: 88 additions & 0 deletions SlackTextViewController/SnapshotTests/AutoCompletionTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// AutoCompletionTests.m
//
// Created by Ignacio Romero Z. on 18/1/16.
// Copyright (c) 2016 Slack Technologies, Inc. All rights reserved.
//

#define EXP_SHORTHAND

#import <UIKit/UIKit.h>
#import <Specta/Specta.h>

#import "EXPMatchers+FBSnapshotTestExtensions.h"
#import "NSString+LoremIpsum.h"

#import "SLKTextViewControllerStub.h"
#import "SLKTextViewStub.h"

SpecBegin(AutoCompletionTests)

__block UIWindow *window = nil;
__block SLKTextViewControllerStub *tvc = nil;
__block UINavigationController *nvc = nil;

beforeAll(^{

tvc = [[SLKTextViewControllerStub alloc] init];
nvc = [[UINavigationController alloc] initWithRootViewController:tvc];
nvc.view.backgroundColor = [UIColor whiteColor];

window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.rootViewController = [[UINavigationController alloc] initWithRootViewController:tvc];
window.backgroundColor = [UIColor redColor]; // Red color represents the keyboard area
[window makeKeyAndVisible];

expect(tvc.view).toNot.beNil();
expect(nvc.view).toNot.beNil();
});


#pragma mark - Autocompletion Tests

describe(@"Autocompletion Tests", ^{

beforeEach(^{
[tvc presentKeyboard:NO];

[tvc.textView slk_clearText:YES];
[tvc.textView slk_insertTextAtCaretRange:@"hello @"];
});

itShould(@"display the autocompletion view", ^{

expect(tvc.foundWord).to.beNil;
expect(tvc.autoCompleting).to.beTruthy;

return window;
});

itShould(@"filter results in autocompletion view", ^{

[tvc.textView slk_insertTextAtCaretRange:@"an"];

// Auto-completion mode should be enabled
expect(tvc.foundPrefix).to.equal(@"@");
expect(tvc.foundWord).to.equal(@"an");
expect(tvc.autoCompleting).to.beTruthy;

return window;
});

itShould(@"insert the first autocompletion item to the text input with prefix", ^{

[tvc acceptAutoCompletionWithString:@"Anna" keepPrefix:YES];

// Auto-completion mode should now be disabled
expect(tvc.foundPrefix).to.beNil;
expect(tvc.foundWord).to.beNil;
expect(tvc.autoCompleting).to.beFalsy;

expect(tvc.textView.text).to.equal(@"hello @Anna");

return window;
});
});


SpecEnd
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//
// SLKTextViewControllerTests.m
// Messenger
// DisplayTests.m
//
// Created by Ignacio Romero Z. on 3/11/15.
// Copyright (c) 2015 Slack Technologies, Inc. All rights reserved.
// Created by Ignacio Romero Z. on 18/1/16.
// Copyright (c) 2016 Slack Technologies, Inc. All rights reserved.
//

#define EXP_SHORTHAND
Expand All @@ -17,7 +16,7 @@
#import "SLKTextViewControllerStub.h"
#import "SLKTextViewStub.h"

SpecBegin(SLKTextViewControllerTests)
SpecBegin(DisplayTests)

__block UIWindow *window = nil;
__block SLKTextViewControllerStub *tvc = nil;
Expand All @@ -26,16 +25,6 @@
beforeAll(^{

tvc = [[SLKTextViewControllerStub alloc] init];
tvc.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

tvc.textView.placeholder = @"Placeholder";
tvc.textView.tintColor = tvc.textView.backgroundColor; // This helps preventing the caret to be displayed in the tests

[tvc.leftButton setImage:[UIImage imageNamed:@"icn_upload"] forState:UIControlStateNormal];
[tvc.leftButton setTintColor:[UIColor grayColor]];

[tvc registerClassForTextView:[SLKTextViewStub class]];

nvc = [[UINavigationController alloc] initWithRootViewController:tvc];
nvc.view.backgroundColor = [UIColor whiteColor];

Expand Down Expand Up @@ -105,7 +94,7 @@

tvc.textView.text = [NSString sentencesWithNumber:5];

expect(tvc.textView.numberOfLines).will.beGreaterThan(@10);
expect(tvc.textView.numberOfLines).will.beGreaterThanOrEqualTo(@9);

return window;
});
Expand All @@ -122,52 +111,4 @@
});


#pragma mark - Autocompletion Tests

describe(@"Autocompletion Tests", ^{

beforeEach(^{
[tvc presentKeyboard:NO];

[tvc.textView slk_clearText:YES];
[tvc.textView slk_insertTextAtCaretRange:@"hello @"];
});

itShould(@"display the autocompletion view", ^{

expect(tvc.foundPrefix).to.equal(@"@");
expect(tvc.foundWord).to.beNil;
expect(tvc.autoCompleting).to.beTruthy;

return window;
});

itShould(@"filter results in autocompletion view", ^{

[tvc.textView slk_insertTextAtCaretRange:@"an"];

// Auto-completion mode should be enabled
expect(tvc.foundPrefix).to.equal(@"@");
expect(tvc.foundWord).to.equal(@"an");
expect(tvc.autoCompleting).to.beTruthy;

return window;
});

itShould(@"insert the first autocompletion item to the text input with prefix", ^{

[tvc acceptAutoCompletionWithString:@"Anna" keepPrefix:YES];

// Auto-completion mode should now be disabled
expect(tvc.foundPrefix).to.beNil;
expect(tvc.foundWord).to.beNil;
expect(tvc.autoCompleting).to.beFalsy;

expect(tvc.textView.text).to.equal(@"hello @Anna");

return window;
});
});


SpecEnd
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

NSString *_specName(NSString *name) {

NSMutableString *specName = [NSMutableString stringWithString:name];
NSMutableString *specName = [NSMutableString stringWithString:[name stringByReplacingOccurrencesOfString:@" " withString:@"_"]];
[specName appendString:_deviceSuffix()];

return [specName lowercaseString];
Expand All @@ -77,7 +77,7 @@
NSString *folderName = [NSString stringWithFormat:@"%@Spec", [[pathComponents lastObject] stringByDeletingPathExtension]];

[pathComponents removeObjectsInRange:NSMakeRange([pathComponents count]-2, 2)];
[pathComponents addObject:@"ReferenceImages"];
[pathComponents addObject:@"SnapshotTests/ReferenceImages"];

NSString *path = [pathComponents componentsJoinedByString:@"/"];

Expand Down
Binary file added ...pletionTestsSpec/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
44 changes: 40 additions & 4 deletions SlackTextViewController/Stubs/SLKTextViewControllerStub.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "SLKTextViewControllerStub.h"
#import "SLKTextViewStub.h"
#import "NSString+LoremIpsum.h"

@interface SLKTextViewControllerStub ()
Expand All @@ -25,8 +26,43 @@ - (instancetype)init
return self;
}

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

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

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (void)configure
{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

self.textView.placeholder = @"Placeholder";
self.textView.tintColor = self.textView.backgroundColor; // This helps preventing the caret to be displayed in the tests

[self.leftButton setImage:[UIImage imageNamed:@"icn_upload"] forState:UIControlStateNormal];
[self.leftButton setTintColor:[UIColor grayColor]];

[self registerClassForTextView:[SLKTextViewStub class]];

self.usernames = @[@"Allen", @"Anna", @"Alicia", @"Arnold", @"Armando", @"Antonio", @"Brad", @"Catalaya", @"Christoph", @"Emerson", @"Eric", @"Everyone", @"Steve"];

[self registerPrefixesForAutoCompletion:@[@"@"]];
Expand All @@ -35,11 +71,9 @@ - (void)configure

#pragma mark - Auto-Completion Methods

- (BOOL)canShowAutoCompletion
- (void)didChangeAutoCompletionPrefix:(NSString *)prefix andWord:(NSString *)word
{
NSArray *array = nil;
NSString *prefix = self.foundPrefix;
NSString *word = self.foundWord;

self.searchResult = nil;

Expand All @@ -58,7 +92,9 @@ - (BOOL)canShowAutoCompletion

self.searchResult = [[NSArray alloc] initWithArray:array];

return self.searchResult.count > 0;
BOOL show = (self.searchResult.count > 0);

[self showAutoCompletionView:show];
}

- (CGFloat)heightForAutoCompletionView
Expand Down

0 comments on commit 3f45226

Please sign in to comment.