Skip to content

Commit b8eb87d

Browse files
authored
Add rewards tests to UITestBed (#803)
* Added rewards to UITestBed app.
1 parent 5d963b6 commit b8eb87d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Branch-TestBed/Branch-TestBed-UITests/UITestBed/Info.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<key>branch_universal_link_domains</key>
5959
<array>
6060
<string>branch-uitestbed.app.link</string>
61+
<string>branch-uitestbed.test-app.link</string>
6162
<string>branch-uitestbed-alternate.app.link</string>
6263
</array>
6364
</dict>

Branch-TestBed/Branch-TestBed-UITests/UITestBed/TBBranchViewController.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ @interface TBBranchViewController () <UITableViewDelegate, UITableViewDataSource
5050
@property (nonatomic, strong) BranchLinkProperties *linkProperties;
5151
@property (nonatomic, weak) IBOutlet UITableView *tableView;
5252
@property (nonatomic, strong) IBOutlet UINavigationItem *navigationItem;
53+
54+
@property (nonatomic, strong) TBTableRow *rewardsRow;
5355
@end
5456

5557
@implementation TBBranchViewController
@@ -84,6 +86,11 @@ - (void)initializeTableData {
8486
row(@"ShareLink no anchor (one day link)", sharelinkTableRowNilAnchor:);
8587
row(@"BUO Share from table row", buoShareTableRow:);
8688

89+
section(@"Rewards");
90+
self.rewardsRow = row(@"Refresh Rewards", refreshRewards:);
91+
row(@"Show Rewards History", showRewardsHistory:);
92+
row(@"Redeem 5 Points", redeemRewards:);
93+
8794
section(@"App Update State");
8895
row(@"Erase All App Data", clearAllAppDataAction:)
8996
row(@"Show Dates & Update State", showDatesAction:)
@@ -521,4 +528,60 @@ - (IBAction) buoShareBarButton:(id)sender {
521528
}];
522529
}
523530

531+
#pragma mark - Rewards
532+
533+
- (IBAction) refreshRewards:(TBTableRow*)sender {
534+
[TBWaitingView showWithMessage:@"Refreshing" activityIndicator:YES disableTouches:YES];
535+
[[Branch getInstance] loadRewardsWithCallback: ^ (BOOL changed, NSError *error) {
536+
if (error) {
537+
[TBWaitingView hide];
538+
[self showAlertWithTitle:@"Error" message:error.localizedDescription];
539+
} else {
540+
long credits = [[Branch getInstance] getCredits];
541+
sender.value = [NSString stringWithFormat:@"%ld", credits];
542+
NSIndexPath *indexPath = [self.tableData indexPathForRow:sender];
543+
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
544+
NSString *message = [NSString stringWithFormat:@"Credits: %ld", credits];
545+
[TBWaitingView hideWithMessage:message];
546+
}
547+
}];
548+
}
549+
550+
- (void) refreshRewardsQuietly {
551+
[[Branch getInstance] loadRewardsWithCallback: ^ (BOOL changed, NSError *error) {
552+
if (!error) {
553+
long credits = [[Branch getInstance] getCredits];
554+
self.rewardsRow.value = [NSString stringWithFormat:@"%ld", credits];
555+
NSIndexPath *indexPath = [self.tableData indexPathForRow:self.rewardsRow];
556+
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
557+
}
558+
}];
559+
}
560+
561+
- (IBAction) showRewardsHistory:(TBTableRow*)sender {
562+
[TBWaitingView showWithMessage:@"Getting Rewards" activityIndicator:YES disableTouches:YES];
563+
[[Branch getInstance] getCreditHistoryWithCallback:^(NSArray *creditHistory, NSError *error) {
564+
[TBWaitingView hide];
565+
if (error) {
566+
[self showAlertWithTitle:@"Error" message:error.localizedDescription];
567+
} else {
568+
[self showDataViewControllerWithTitle:@"Rewards" message:@"Rewards History" object:creditHistory];
569+
}
570+
}];
571+
}
572+
573+
- (IBAction) redeemRewards:(TBTableRow*)sender {
574+
[TBWaitingView showWithMessage:@"Redeeming" activityIndicator:YES disableTouches:YES];
575+
[[Branch getInstance] redeemRewards:5 callback:^(BOOL changed, NSError *error) {
576+
if (error || !changed) {
577+
[TBWaitingView hide];
578+
[self showAlertWithTitle:@"Redemption Unsuccessful" message:error.localizedDescription];
579+
} else {
580+
[TBWaitingView hideWithMessage:@"Five points redeemed!"];
581+
[self refreshRewardsQuietly];
582+
}
583+
}];
584+
}
585+
524586
@end
587+

0 commit comments

Comments
 (0)