FRANotificationsTableViewControllerTests.m revision ff2edace1e77f0e80bc2f5da30344d21c3274885
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
*/
#import <OCMock/OCMock.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "FRAApplicationAssembly.h"
#import "FRAIdentityModel.h"
#import "FRAIdentity.h"
#import "FRANotification.h"
#import "FRANotificationTableViewCell.h"
#import "FRANotificationsTableViewController.h"
#import "FRAPushMechanism.h"
@interface FRANotificationsTableViewControllerTests : XCTestCase
@end
}
- (void)setUp {
[super setUp];
// load notifications controller from storyboard
viewController = [storyboard instantiateViewControllerWithIdentifier:@"NotificationsTableViewController"];
}
- (void)tearDown {
[super tearDown];
}
- (void)testShowsNoNotificationsIfThereAreNone {
// Given
// When
// Then
XCTAssertEqual([viewController tableView:viewController.tableView numberOfRowsInSection:PENDING_SECTION], 0);
XCTAssertEqual([viewController tableView:viewController.tableView numberOfRowsInSection:COMPLETED_SECTION], 0);
}
// Given
// When
// Then
XCTAssertEqualObjects([viewController tableView:viewController.tableView titleForHeaderInSection:PENDING_SECTION], @"");
XCTAssertEqual([viewController tableView:viewController.tableView numberOfRowsInSection:PENDING_SECTION], 2);
XCTAssertEqual([viewController tableView:viewController.tableView numberOfRowsInSection:COMPLETED_SECTION], 0);
}
// Given
// When
// Then
XCTAssertEqualObjects([viewController tableView:viewController.tableView titleForHeaderInSection:COMPLETED_SECTION], @"COMPLETED");
XCTAssertEqual([viewController tableView:viewController.tableView numberOfRowsInSection:PENDING_SECTION], 0);
XCTAssertEqual([viewController tableView:viewController.tableView numberOfRowsInSection:COMPLETED_SECTION], 2);
}
- (void)testShowsDetailsOfPendingNotification {
// Given
FRANotification *pendingNotification = [self pendingNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-15.0]];
// When
// Then
}
// Given
// When
// Then
XCTAssertEqualObjects([viewController tableView:viewController.tableView willSelectRowAtIndexPath:notificationIndexPath], notificationIndexPath);
}
- (void)testShowsDetailsOfApprovedNotification {
// Given
FRANotification *approvedNotification = [self approvedNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-15.0]];
// When
// Then
}
// Given
// When
// Then
XCTAssertEqualObjects([viewController tableView:viewController.tableView willSelectRowAtIndexPath:notificationIndexPath], nil);
}
- (void)testShowsDetailsOfDeniedNotification {
// Given
FRANotification *deniedNotification = [self deniedNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-15.0]];
// When
// Then
}
// Given
// When
// Then
XCTAssertEqualObjects([viewController tableView:viewController.tableView willSelectRowAtIndexPath:notificationIndexPath], nil);
}
// FIXME: testSortsPendingNotificationsChronologically fails due to unmet assertions in UIKit
//- (void)testSortsPendingNotificationsChronologically {
// // Given
// FRANotification *firstNotification = [self pendingNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-15.0]];
// FRANotification *secondNotification = [self pendingNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-240.0]];
// FRANotification *thirdNotification = [self pendingNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-300.0]];
// // NB. Add notifications out of order to confirm that they get sorted after retrieval from the push mechanism
// [pushMechanism addNotification:secondNotification error:nil];
// [pushMechanism addNotification:thirdNotification error:nil];
// [pushMechanism addNotification:firstNotification error:nil];
//
// // When
// FRANotificationTableViewCell *firstCell = [self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:PENDING_SECTION]];
// FRANotificationTableViewCell *secondCell = [self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:PENDING_SECTION]];
// FRANotificationTableViewCell *thirdCell = [self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:PENDING_SECTION]];
//
// // Then
// XCTAssertEqualObjects(firstCell.time.text, [firstNotification age]);
// XCTAssertEqualObjects(secondCell.time.text, [secondNotification age]);
// XCTAssertEqualObjects(thirdCell.time.text, [thirdNotification age]);
//}
// Given
FRANotification *firstNotification = [self approvedNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-15.0]];
FRANotification *secondNotification = [self deniedNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-240.0]];
FRANotification *thirdNotification = [self approvedNotificationReceivedAt:[NSDate dateWithTimeIntervalSinceNow:-300.0]];
// NB. Add notifications out of order to confirm that they get sorted after retrieval from the push mechanism
// When
FRANotificationTableViewCell *firstCell = [self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:COMPLETED_SECTION]];
FRANotificationTableViewCell *secondCell = [self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:COMPLETED_SECTION]];
FRANotificationTableViewCell *thirdCell = [self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:COMPLETED_SECTION]];
// Then
}
- (void)simulateLoadingOfView {
} else {
}
}
- (void)simulateUnloadingOfView {
}
messageId:@"dummy"
challenge:@"dummy"
timeToLive:120.0
loadBalancerCookieData:@"01"];
}
return notification;
}
return notification;
}
return (FRANotificationTableViewCell *)
}
@end