From 1c3aab92c14be85a4e4e26fc4b2ca3863a4ec0a4 Mon Sep 17 00:00:00 2001 From: Shannon Young Date: Fri, 24 Jun 2016 10:35:08 -0700 Subject: [PATCH] Update the unit test to make it a little more interesting. --- ResearchKitTests/ORKStepTests.m | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/ResearchKitTests/ORKStepTests.m b/ResearchKitTests/ORKStepTests.m index 510f400e..e243c0cd 100644 --- a/ResearchKitTests/ORKStepTests.m +++ b/ResearchKitTests/ORKStepTests.m @@ -38,10 +38,12 @@ @end -@interface TestStep : ORKStep +@interface DragonPokerStep : ORKStep +@property (nonatomic) NSDate *playDate; @end -@interface TestStepViewController : ORKStepViewController +@interface DragonPokerStepViewController : ORKStepViewController +@property (nonatomic) BOOL shouldShowCancelButton; @end @@ -117,7 +119,8 @@ } - (void)testInstantiateStepViewControllerWithResult { - TestStep *step = [[TestStep alloc] initWithIdentifier:@"test"]; + DragonPokerStep *step = [[DragonPokerStep alloc] initWithIdentifier:@"test"]; + step.playDate = [NSDate date]; ORKStepResult *result = [[ORKStepResult alloc] initWithIdentifier:step.identifier]; ORKStepViewController *stepViewController = [step instantiateStepViewControllerWithResult:result]; XCTAssertNotNil(stepViewController); @@ -125,14 +128,28 @@ @end -@implementation TestStep +@implementation DragonPokerStep +/// Example implementation of an override of the class method +/// In this example, only show the cancel button on Tuesdays - (ORKStepViewController *)instantiateStepViewControllerWithResult:(ORKResult *)result { - // Example implementation of an override of the class method - return [[TestStepViewController alloc] initWithStep:self]; + DragonPokerStepViewController *viewController = [[DragonPokerStepViewController alloc] initWithStep:self result:result]; + NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitWeekday fromDate:self.playDate]; + viewController.shouldShowCancelButton = components.weekday == 2; + return viewController; } @end -@implementation TestStepViewController +@implementation DragonPokerStepViewController + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + // Hide the cancel button if it should not be shown. + if (!self.shouldShowCancelButton) { + self.cancelButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] initWithFrame:CGRectZero]]; + } +} + @end