mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-09 03:48:07 +08:00
Reorganization and cleanups of Unit Tests
* Reorganized tests to accommodate split into Logic & Application. * Eliminated 'Spec' naming in favor of 'Test' as the suite is entirely based on SenTest. * Pulled majority of testing support classes up into the library and documented them. * Introduced RKApplicationTests app for running the RKTableController UI tests
This commit is contained in:
126
Tests/Application/UI/RKFormTest.m
Normal file
126
Tests/Application/UI/RKFormTest.m
Normal file
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// RKFormTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 8/29/11.
|
||||
// Copyright (c) 2011 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKForm.h"
|
||||
#import "RKMappableObject.h"
|
||||
#import "RKTableController.h"
|
||||
|
||||
@interface UISwitch (ControlValue)
|
||||
@property (nonatomic, assign) NSNumber *controlValue;
|
||||
@end
|
||||
|
||||
@implementation UISwitch (ControlValue)
|
||||
|
||||
- (NSNumber *)controlValue {
|
||||
return [NSNumber numberWithBool:self.isOn];
|
||||
}
|
||||
|
||||
- (void)setControlValue:(NSNumber *)controlValue {
|
||||
self.on = [controlValue boolValue];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface RKTestTextField : UIControl
|
||||
@property (nonatomic, retain) NSString *text;
|
||||
@end
|
||||
|
||||
@implementation RKTestTextField
|
||||
|
||||
@synthesize text;
|
||||
|
||||
@end
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
@interface RKFormSpecTableViewCell : UITableViewCell {
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSString *someTextProperty;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKFormSpecTableViewCell
|
||||
|
||||
@synthesize someTextProperty;
|
||||
|
||||
@end
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
@interface RKFormTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKFormTest
|
||||
|
||||
- (void)testCommitValuesBackToTheFormObjectWithBuiltInTypes {
|
||||
RKMappableObject *mappableObject = [[RKMappableObject new] autorelease];
|
||||
RKForm *form = [RKForm formForObject:mappableObject usingBlock:^(RKForm *form) {
|
||||
[form addRowForAttribute:@"stringTest" withControlType:RKFormControlTypeTextField usingBlock:^(RKControlTableItem *tableItem) {
|
||||
tableItem.textField.text = @"testing 123";
|
||||
}];
|
||||
[form addRowForAttribute:@"numberTest" withControlType:RKFormControlTypeSwitch usingBlock:^(RKControlTableItem *tableItem) {
|
||||
tableItem.switchControl.on = YES;
|
||||
}];
|
||||
}];
|
||||
[form commitValuesToObject];
|
||||
assertThat(mappableObject.stringTest, is(equalTo(@"testing 123")));
|
||||
assertThatBool([mappableObject.numberTest boolValue], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testCommitValuesBackToTheFormObjectFromUserConfiguredControls {
|
||||
RKTestTextField *textField = [[RKTestTextField new] autorelease];
|
||||
textField.text = @"testing 123";
|
||||
UISwitch *switchControl = [[UISwitch new] autorelease];
|
||||
switchControl.on = YES;
|
||||
RKMappableObject *mappableObject = [[RKMappableObject new] autorelease];
|
||||
RKForm *form = [RKForm formForObject:mappableObject usingBlock:^(RKForm *form) {
|
||||
[form addRowMappingAttribute:@"stringTest" toKeyPath:@"text" onControl:textField];
|
||||
[form addRowMappingAttribute:@"numberTest" toKeyPath:@"controlValue" onControl:switchControl];
|
||||
}];
|
||||
[form commitValuesToObject];
|
||||
assertThat(mappableObject.stringTest, is(equalTo(@"testing 123")));
|
||||
assertThatBool([mappableObject.numberTest boolValue], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testCommitValuesBackToTheFormObjectFromCellKeyPaths {
|
||||
RKMappableObject *mappableObject = [[RKMappableObject new] autorelease];
|
||||
RKForm *form = [RKForm formForObject:mappableObject usingBlock:^(RKForm *form) {
|
||||
[form addRowMappingAttribute:@"stringTest" toKeyPath:@"someTextProperty" onCellWithClass:[RKFormSpecTableViewCell class]];
|
||||
}];
|
||||
|
||||
RKTableItem *tableItem = [form.tableItems lastObject];
|
||||
RKFormSpecTableViewCell *cell = [[RKFormSpecTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
|
||||
cell.someTextProperty = @"testing 123";
|
||||
id mockTableController = [OCMockObject niceMockForClass:[RKTableController class]];
|
||||
[[[mockTableController expect] andReturn:cell] cellForObject:tableItem];
|
||||
[form didLoadInTableController:mockTableController];
|
||||
|
||||
// Create a cell
|
||||
// Create a fake table view model
|
||||
// stub out returning the cell from the table view model
|
||||
|
||||
[form commitValuesToObject];
|
||||
assertThat(mappableObject.stringTest, is(equalTo(@"testing 123")));
|
||||
}
|
||||
|
||||
- (void)testMakeTheTableItemPassKVCInvocationsThroughToTheUnderlyingMappedControlKeyPath {
|
||||
// TODO: Implement me
|
||||
// add a control
|
||||
// invoke valueForKey: with the control value keyPath on the table item...
|
||||
}
|
||||
|
||||
- (void)testInvokeValueForKeyPathOnTheControlIfControlValueReturnsNil {
|
||||
// TODO: Implement me
|
||||
// add a custom control to the form
|
||||
// the control value should return nil so that valueForKeyPath is invoked directly
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user