Merge pull request #31 from phatle/login_model_test

Login model test
This commit is contained in:
Ash Furrow
2014-02-24 11:53:32 +01:00
5 changed files with 89 additions and 9 deletions

View File

@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
17A5BBDB18BB2F6D000E2D24 /* FRPLoginViewModelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.m */; };
2826EB375D254DDD8DE6EAA8 /* libPods-FRP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */; };
5E595111180E065F002F44FA /* FRPFullSizePhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */; };
5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595116180E0C33002F44FA /* FRPPhotoViewController.m */; };
@@ -50,6 +51,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPLoginViewModelTests.m; sourceTree = "<group>"; };
5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPFullSizePhotoViewController.h; sourceTree = "<group>"; };
5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPFullSizePhotoViewController.m; sourceTree = "<group>"; };
5E595115180E0C33002F44FA /* FRPPhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoViewController.h; sourceTree = "<group>"; };
@@ -282,6 +284,7 @@
5EBE2B19180B07D0007B6BF3 /* FRPTests */ = {
isa = PBXGroup;
children = (
17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.m */,
5E730B0F1815F78B003FCB43 /* FRPGalleryViewModelTests.m */,
5E93AD99186C781000795C9E /* FRPFullSizePhotoViewModelTests.m */,
5E93AD9B186C80DE00795C9E /* FRPPhotoViewModelTests.m */,
@@ -487,6 +490,7 @@
5E93AD9A186C781000795C9E /* FRPFullSizePhotoViewModelTests.m in Sources */,
5E730B101815F78B003FCB43 /* FRPGalleryViewModelTests.m in Sources */,
5E93AD9C186C80DE00795C9E /* FRPPhotoViewModelTests.m in Sources */,
17A5BBDB18BB2F6D000E2D24 /* FRPLoginViewModelTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -22,9 +22,8 @@
if (!self) return nil;
@weakify(self);
self.loginCommand = [[RACCommand alloc] initWithEnabled:[RACSignal combineLatest:@[RACObserve(self, username), RACObserve(self, password)] reduce:^id(NSString *username, NSString *password){
return @(username.length > 0 && password.length > 0);
}] signalBlock:^RACSignal *(id input) {
self.loginCommand = [[RACCommand alloc] initWithEnabled:[self validateLoginInputs]
signalBlock:^RACSignal *(id input) {
@strongify(self);
return [FRPPhotoImporter logInWithUsername:self.username password:self.password];
}];
@@ -32,4 +31,11 @@
return self;
}
- (RACSignal *)validateLoginInputs
{
return [RACSignal combineLatest:@[RACObserve(self, username), RACObserve(self, password)] reduce:^id(NSString *username, NSString *password){
return @(username.length > 0 && password.length > 0);
}];
}
@end

View File

@@ -0,0 +1,66 @@
//
// FRPLoginViewModelTests.m
// FRP
//
// Created by Phat, Le Tan on 2/24/14.
// Copyright (c) 2014 Ash Furrow. All rights reserved.
//
#import "Specta.h"
#define EXP_SHORTHAND
#import <Expecta/Expecta.h>
#import <OCMock/OCMock.h>
#import "FRPLoginViewModel.h"
@interface FRPLoginViewModel()
- (RACSignal *)validateLoginInputs;
@end
SpecBegin(FRPLoginViewModel)
__block FRPLoginViewModel *viewModel;
beforeEach(^{
viewModel = [[FRPLoginViewModel alloc] initWithModel:nil];
});
describe(@"FRPLoginViewModel", ^{
it(@"disable login command when username is empty", ^{
viewModel.username = @"";
viewModel.password = @"password";
__block id result;
[[viewModel validateLoginInputs] subscribeNext:^(id x) {
result = x;
}];
expect(result).to.equal(@0);
});
it(@"disable login command when password is empty", ^{
viewModel.username = @"username";
viewModel.password = @"";
__block id result;
[[viewModel validateLoginInputs] subscribeNext:^(id x) {
result = x;
}];
expect(result).to.equal(@0);
});
it(@"enable login command when username and password are available", ^{
viewModel.username = @"username";
viewModel.password = @"password";
__block id result;
[[viewModel validateLoginInputs] subscribeNext:^(id x) {
result = x;
}];
expect(result).to.equal(@1);
});
});
afterEach(^{
viewModel = nil;
});
SpecEnd

View File

@@ -0,0 +1,9 @@
//
// FRPPhotoImporterTests.m
// FRP
//
// Created by Phat, Le Tan on 2/24/14.
// Copyright (c) 2014 Ash Furrow. All rights reserved.
//
#include <stdio.h>

View File

@@ -11,14 +11,9 @@ pod 'AFImageDownloader', '1.0.0'
end
target "FRPTests" do
pod 'ReactiveCocoa', '2.1.4'
pod 'ReactiveViewModel', '0.1.1'
pod 'libextobjc', '0.3'
pod '500px-iOS-api', '1.0.5'
pod 'Specta', '~> 0.2.1'
pod 'Expecta', '~> 0.2'
pod 'OCMock', '~> 2.2.2'
pod 'AFImageDownloader', '1.0.0'
end