Adds subtype to monster.
Adds EditMonsterViewController tests for editing subtype. Adds tests for meta property of Monster.
This commit is contained in:
93
iOS/MonsterCardsTests/Views/EditMonsterViewControllerTests.m
Normal file
93
iOS/MonsterCardsTests/Views/EditMonsterViewControllerTests.m
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// EditMonsterViewControllerTests.m
|
||||
// MonsterCardsTests
|
||||
//
|
||||
// Created by Tom Hicks on 9/12/20.
|
||||
// Copyright © 2020 Tom Hicks. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
@import OCMockito;
|
||||
@import OCHamcrest;
|
||||
#import "EditMonsterViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface EditMonsterViewControllerTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation EditMonsterViewControllerTests {
|
||||
EditMonsterViewController *_viewController;
|
||||
NSManagedObjectContext *_context;
|
||||
AppDelegate *_appDelegate;
|
||||
NSPersistentCloudKitContainer *_persistentContainer;
|
||||
Monster *_monster;
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
_monster = mock([Monster class]);
|
||||
_viewController = [[EditMonsterViewController alloc] init];
|
||||
_context = mock([NSManagedObjectContext class]);
|
||||
_appDelegate = mock([AppDelegate class]);
|
||||
_persistentContainer = mock([NSPersistentCloudKitContainer class]);
|
||||
|
||||
UIApplication.sharedApplication.delegate = _appDelegate;
|
||||
// ((AppDelegate*)UIApplication.sharedApplication.delegate).persistentContainer.viewContext = _context;
|
||||
}
|
||||
|
||||
- (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;
|
||||
|
||||
[given([monstersTableView dequeueReusableCellWithIdentifier:@"EditableShortString"]) willReturn:shortStringCell];
|
||||
|
||||
_monster.subtype = @"elf";
|
||||
_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.subtype", shortStringCell.identifier);
|
||||
XCTAssertEqualObjects(@"Subtype", shortStringCell.textField.placeholder);
|
||||
XCTAssertEqualObjects(@"", shortStringCell.textField.text);
|
||||
XCTAssertEqual(_viewController, shortStringCell.delegate);
|
||||
}
|
||||
|
||||
- (void)testEditingSubtype {
|
||||
UIViewController *destinationVC = mock([UIViewController class]);
|
||||
UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"SaveChanges" source:_viewController destination:destinationVC performHandler:^{}];
|
||||
|
||||
_monster = [[Monster alloc] initWithContext:_context];
|
||||
_monster.subtype = @"elf";
|
||||
_viewController.originalMonster = _monster;
|
||||
[_viewController viewDidLoad];
|
||||
[_viewController viewWillAppear:NO];
|
||||
|
||||
[_viewController editableValueDidChange:@"newValue" forIdentifier:@"monster.subtype" andType:@"String"];
|
||||
|
||||
[_viewController prepareForSegue:segue sender:nil];
|
||||
|
||||
XCTAssertEqualObjects(@"newValue", _viewController.originalMonster.subtype);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user