diff --git a/iOS/MonsterCards/Models/Monster.m b/iOS/MonsterCards/Models/Monster.m index d205b39..23c5a16 100644 --- a/iOS/MonsterCards/Models/Monster.m +++ b/iOS/MonsterCards/Models/Monster.m @@ -75,6 +75,7 @@ self.size = [jsonRoot objectForKey:@"size"] ?: @""; self.type = [jsonRoot objectForKey:@"type"] ?: @""; self.subtype = [jsonRoot objectForKey:@"tag"] ?: @""; + self.alignment = [jsonRoot objectForKey:@"alignment"] ?: @""; return self; } @@ -338,6 +339,7 @@ self.size = monster.size; self.type = monster.type; self.subtype = monster.subtype; + self.alignment = monster.alignment; } @end diff --git a/iOS/MonsterCards/Views/EditMonsterViewController.m b/iOS/MonsterCards/Views/EditMonsterViewController.m index abdd8a3..ee58ef1 100644 --- a/iOS/MonsterCards/Views/EditMonsterViewController.m +++ b/iOS/MonsterCards/Views/EditMonsterViewController.m @@ -59,7 +59,7 @@ // * Subtype // * Alignment - return 4; + return 5; } - (EditableShortStringTableViewCell*) makeShortStringCellFromCell:(UITableViewCell*)cell { @@ -109,6 +109,13 @@ shortStringCell.textField.text = self.editingMonster.subtype; shortStringCell.textField.placeholder = NSLocalizedString(@"Subtype", @"Placeholder text for the subtype of a monster or NPC."); 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; } @@ -128,6 +135,8 @@ self.editingMonster.type = (NSString*)value; } else if ([@"monster.subtype" isEqualToString:identifier]) { self.editingMonster.subtype = (NSString*)value; + } else if ([@"monster.alignment" isEqualToString:identifier]) { + self.editingMonster.alignment = (NSString*)value; } } } diff --git a/iOS/MonsterCardsTests/Models/MonsterTests.m b/iOS/MonsterCardsTests/Models/MonsterTests.m index b4f83eb..224aa70 100644 --- a/iOS/MonsterCardsTests/Models/MonsterTests.m +++ b/iOS/MonsterCardsTests/Models/MonsterTests.m @@ -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 diff --git a/iOS/MonsterCardsTests/Views/EditMonsterViewControllerTests.m b/iOS/MonsterCardsTests/Views/EditMonsterViewControllerTests.m index 49c3cc2..aa3ac76 100644 --- a/iOS/MonsterCardsTests/Views/EditMonsterViewControllerTests.m +++ b/iOS/MonsterCardsTests/Views/EditMonsterViewControllerTests.m @@ -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