Adds alignment to monsters.

Adds tests for editing alignment on monsters.
Adds tests for monster meta text when alignment is set.
This commit is contained in:
2020-09-12 17:39:07 -07:00
parent 7643b98c01
commit 2aaca29741
4 changed files with 115 additions and 12 deletions

View File

@@ -25,7 +25,7 @@
- (void)setUp {
_context = nil;
_monster = [[Monster alloc] initWithContext:_context];
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\"}";
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\",\"alignment\":\"any alignment\"}";
_jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding];
}
@@ -39,6 +39,7 @@
XCTAssertEqualObjects(@"", _monster.size);
XCTAssertEqualObjects(@"", _monster.type);
XCTAssertEqualObjects(@"", _monster.subtype);
XCTAssertEqualObjects(@"", _monster.alignment);
}
- (void)testInitWithJSONString {
@@ -49,6 +50,7 @@
XCTAssertEqualObjects(@"medium", _monster.size);
XCTAssertEqualObjects(@"humanoid", _monster.type);
XCTAssertEqualObjects(@"any race", _monster.subtype);
XCTAssertEqualObjects(@"any alignment", _monster.alignment);
}
- (void)testInitWithEmptyJSONString {
@@ -59,6 +61,7 @@
XCTAssertEqualObjects(@"", _monster.size);
XCTAssertEqualObjects(@"", _monster.type);
XCTAssertEqualObjects(@"", _monster.subtype);
XCTAssertEqualObjects(@"", _monster.alignment);
}
- (void)testInitWithJSONData {
_monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context];
@@ -68,6 +71,7 @@
XCTAssertEqualObjects(@"medium", _monster.size);
XCTAssertEqualObjects(@"humanoid", _monster.type);
XCTAssertEqualObjects(@"any race", _monster.subtype);
XCTAssertEqualObjects(@"any alignment", _monster.alignment);
}
- (void)testNameGetterAndSetter {
@@ -94,6 +98,11 @@
XCTAssertEqualObjects(subtype, _monster.subtype);
}
- (void)testAlignmentGetterAndSetter {
NSString *alignment = @"chaotic good";
_monster.alignment = alignment;
XCTAssertEqualObjects(alignment, _monster.alignment);
}
- (void)testCopyFromMonster {
Monster *otherMonster = [[Monster alloc] initWithJSONString:_jsonString andContext:_context];
[_monster copyFromMonster:otherMonster];
@@ -103,6 +112,7 @@
XCTAssertEqualObjects(@"medium", _monster.size);
XCTAssertEqualObjects(@"humanoid", _monster.type);
XCTAssertEqualObjects(@"any race", _monster.subtype);
XCTAssertEqualObjects(@"any alignment", _monster.alignment);
}
- (void)testMetaWithNoFieldsSet {
@@ -150,4 +160,50 @@
XCTAssertEqualObjects(@"large humanoid (elf)", _monster.meta);
}
- (void)testMetaWithAlignment {
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"chaotic good", _monster.meta);
}
- (void)testMetaWithSizeAndAlignment {
_monster.size = @"large";
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"large chaotic good", _monster.meta);
}
- (void)testMetaWithTypeAndAlignment {
_monster.type = @"humanoid";
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"humanoid chaotic good", _monster.meta);
}
- (void)testMetaWithSizeTypeAndAlignment {
_monster.size = @"large";
_monster.type = @"humanoid";
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"large humanoid chaotic good", _monster.meta);
}
- (void)testMetaWithSizeSubtypeAndAlignment {
_monster.size = @"large";
_monster.subtype = @"elf";
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"large (elf) chaotic good", _monster.meta);
}
- (void)testMetaWithTypeSubtypeAndAlignment {
_monster.type = @"humanoid";
_monster.subtype = @"elf";
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"humanoid (elf) chaotic good", _monster.meta);
}
- (void)testMetaWithSizeTypeSubtypeAndAlignment {
_monster.size = @"large";
_monster.type = @"humanoid";
_monster.subtype = @"elf";
_monster.alignment = @"chaotic good";
XCTAssertEqualObjects(@"large humanoid (elf) chaotic good", _monster.meta);
}
@end

View File

@@ -31,25 +31,16 @@
_appDelegate = mock([AppDelegate class]);
_persistentContainer = mock([NSPersistentCloudKitContainer class]);
UIApplication.sharedApplication.delegate = _appDelegate;
// ((AppDelegate*)UIApplication.sharedApplication.delegate).persistentContainer.viewContext = _context;
UIApplication.sharedApplication.delegate = _appDelegate;
}
- (void)tearDown {
}
// UIViewController
// UITableViewDelegate
// UITableViewDataSource
// EditableShortStringDeletgate
// Monster *originalMonster
// UITableView *monsterTableView
- (void)testRendersSubtypeCell {
UITableView *monstersTableView = mock([UITableView class]);
NSIndexPath *path = [NSIndexPath indexPathForRow:3 inSection:0];
EditableShortStringTableViewCell *shortStringCell = [[EditableShortStringTableViewCell alloc] init];
//mock([EditableShortStringTableViewCell class]);
UITextField *textField = [[UITextField alloc] init];
shortStringCell.textField = textField;
@@ -90,4 +81,49 @@
XCTAssertEqualObjects(@"newValue", _viewController.originalMonster.subtype);
}
- (void)testRendersAlignmentCell {
UITableView *monstersTableView = mock([UITableView class]);
NSIndexPath *path = [NSIndexPath indexPathForRow:4 inSection:0];
EditableShortStringTableViewCell *shortStringCell = [[EditableShortStringTableViewCell alloc] init];
UITextField *textField = [[UITextField alloc] init];
shortStringCell.textField = textField;
[given([monstersTableView dequeueReusableCellWithIdentifier:@"EditableShortString"]) willReturn:shortStringCell];
_monster.alignment = @"chaotic good";
_viewController.originalMonster = _monster;
_viewController.monsterTableView = monstersTableView;
[_viewController viewDidLoad];
[_viewController viewWillAppear:NO];
UITableViewCell *cell = [_viewController tableView:monstersTableView cellForRowAtIndexPath:path];
XCTAssertNotNil(cell);
XCTAssertTrue([cell isKindOfClass:[EditableShortStringTableViewCell class]]);
shortStringCell = (EditableShortStringTableViewCell*)cell;
XCTAssertEqualObjects(@"monster.alignment", shortStringCell.identifier);
XCTAssertEqualObjects(@"Alignment", shortStringCell.textField.placeholder);
XCTAssertEqualObjects(@"", shortStringCell.textField.text);
XCTAssertEqual(_viewController, shortStringCell.delegate);
}
- (void)testEditingAlignment {
UIViewController *destinationVC = mock([UIViewController class]);
UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"SaveChanges" source:_viewController destination:destinationVC performHandler:^{}];
_monster = [[Monster alloc] initWithContext:_context];
_monster.alignment = @"chaotic good";
_viewController.originalMonster = _monster;
[_viewController viewDidLoad];
[_viewController viewWillAppear:NO];
[_viewController editableValueDidChange:@"newValue" forIdentifier:@"monster.alignment" andType:@"String"];
[_viewController prepareForSegue:segue sender:nil];
XCTAssertEqualObjects(@"newValue", _viewController.originalMonster.alignment);
}
@end