mirror of
https://github.com/zhigang1992/FunctionalReactivePixels.git
synced 2026-01-12 17:22:42 +08:00
Merge branch 'master' into import_photo_test
Conflicts: FRP.xcodeproj/project.pbxproj FRPTests/FRPPhotoImporterTests.m
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
17E5A10E18BB43C600AFC028 /* FRPPhotoImporterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5A10D18BB43C600AFC028 /* FRPPhotoImporterTests.m */; };
|
||||
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 */; };
|
||||
@@ -52,6 +53,7 @@
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
17E5A10D18BB43C600AFC028 /* FRPPhotoImporterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPPhotoImporterTests.m; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
@@ -285,6 +287,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
17E5A10D18BB43C600AFC028 /* FRPPhotoImporterTests.m */,
|
||||
17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.m */,
|
||||
5E730B0F1815F78B003FCB43 /* FRPGalleryViewModelTests.m */,
|
||||
5E93AD99186C781000795C9E /* FRPFullSizePhotoViewModelTests.m */,
|
||||
5E93AD9B186C80DE00795C9E /* FRPPhotoViewModelTests.m */,
|
||||
@@ -491,6 +494,7 @@
|
||||
17E5A10E18BB43C600AFC028 /* FRPPhotoImporterTests.m in Sources */,
|
||||
5E730B101815F78B003FCB43 /* FRPGalleryViewModelTests.m in Sources */,
|
||||
5E93AD9C186C80DE00795C9E /* FRPPhotoViewModelTests.m in Sources */,
|
||||
17A5BBDB18BB2F6D000E2D24 /* FRPLoginViewModelTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
66
FRPTests/FRPLoginViewModelTests.m
Normal file
66
FRPTests/FRPLoginViewModelTests.m
Normal 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
|
||||
@@ -56,4 +56,4 @@ describe(@"FRPPhotoImporter", ^{
|
||||
});
|
||||
});
|
||||
|
||||
SpecEnd
|
||||
SpecEnd
|
||||
|
||||
Reference in New Issue
Block a user