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

@@ -75,6 +75,7 @@
self.size = [jsonRoot objectForKey:@"size"] ?: @""; self.size = [jsonRoot objectForKey:@"size"] ?: @"";
self.type = [jsonRoot objectForKey:@"type"] ?: @""; self.type = [jsonRoot objectForKey:@"type"] ?: @"";
self.subtype = [jsonRoot objectForKey:@"tag"] ?: @""; self.subtype = [jsonRoot objectForKey:@"tag"] ?: @"";
self.alignment = [jsonRoot objectForKey:@"alignment"] ?: @"";
return self; return self;
} }
@@ -338,6 +339,7 @@
self.size = monster.size; self.size = monster.size;
self.type = monster.type; self.type = monster.type;
self.subtype = monster.subtype; self.subtype = monster.subtype;
self.alignment = monster.alignment;
} }
@end @end

View File

@@ -59,7 +59,7 @@
// * Subtype // * Subtype
// * Alignment // * Alignment
return 4; return 5;
} }
- (EditableShortStringTableViewCell*) makeShortStringCellFromCell:(UITableViewCell*)cell { - (EditableShortStringTableViewCell*) makeShortStringCellFromCell:(UITableViewCell*)cell {
@@ -109,6 +109,13 @@
shortStringCell.textField.text = self.editingMonster.subtype; shortStringCell.textField.text = self.editingMonster.subtype;
shortStringCell.textField.placeholder = NSLocalizedString(@"Subtype", @"Placeholder text for the subtype of a monster or NPC."); shortStringCell.textField.placeholder = NSLocalizedString(@"Subtype", @"Placeholder text for the subtype of a monster or NPC.");
return shortStringCell; return shortStringCell;
case 4:
shortStringCell = [self makeShortStringCellFromCell: [self.monsterTableView dequeueReusableCellWithIdentifier:@"EditableShortString"]];
shortStringCell.delegate = self;
shortStringCell.identifier = @"monster.alignment";
shortStringCell.textField.text = self.editingMonster.alignment;
shortStringCell.textField.placeholder = NSLocalizedString(@"Alignment", @"Placeholder text for the alignment of a monster or NPC.");
return shortStringCell;
} }
break; break;
} }
@@ -128,6 +135,8 @@
self.editingMonster.type = (NSString*)value; self.editingMonster.type = (NSString*)value;
} else if ([@"monster.subtype" isEqualToString:identifier]) { } else if ([@"monster.subtype" isEqualToString:identifier]) {
self.editingMonster.subtype = (NSString*)value; self.editingMonster.subtype = (NSString*)value;
} else if ([@"monster.alignment" isEqualToString:identifier]) {
self.editingMonster.alignment = (NSString*)value;
} }
} }
} }

View File

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

View File

@@ -31,25 +31,16 @@
_appDelegate = mock([AppDelegate class]); _appDelegate = mock([AppDelegate class]);
_persistentContainer = mock([NSPersistentCloudKitContainer class]); _persistentContainer = mock([NSPersistentCloudKitContainer class]);
UIApplication.sharedApplication.delegate = _appDelegate; UIApplication.sharedApplication.delegate = _appDelegate;
// ((AppDelegate*)UIApplication.sharedApplication.delegate).persistentContainer.viewContext = _context;
} }
- (void)tearDown { - (void)tearDown {
} }
// UIViewController
// UITableViewDelegate
// UITableViewDataSource
// EditableShortStringDeletgate
// Monster *originalMonster
// UITableView *monsterTableView
- (void)testRendersSubtypeCell { - (void)testRendersSubtypeCell {
UITableView *monstersTableView = mock([UITableView class]); UITableView *monstersTableView = mock([UITableView class]);
NSIndexPath *path = [NSIndexPath indexPathForRow:3 inSection:0]; NSIndexPath *path = [NSIndexPath indexPathForRow:3 inSection:0];
EditableShortStringTableViewCell *shortStringCell = [[EditableShortStringTableViewCell alloc] init]; EditableShortStringTableViewCell *shortStringCell = [[EditableShortStringTableViewCell alloc] init];
//mock([EditableShortStringTableViewCell class]);
UITextField *textField = [[UITextField alloc] init]; UITextField *textField = [[UITextField alloc] init];
shortStringCell.textField = textField; shortStringCell.textField = textField;
@@ -90,4 +81,49 @@
XCTAssertEqualObjects(@"newValue", _viewController.originalMonster.subtype); 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 @end