FRAAccountsTableViewControllerTests.m revision 415243fbc81341293a852ff6aa14e9608d08685c
/*
* 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 "FRAAccountsTableViewController.h"
#import "FRAAccountTableViewCell.h"
#import "FRAApplicationAssembly.h"
#import "FRAIdentityModel.h"
#import "FRAIdentity.h"
#import "FRANotification.h"
#import "FRAOathMechanism.h"
#import "FRAPushMechanism.h"
@interface FRAAccountsTableViewControllerTests : XCTestCase
@end
}
- (void)setUp {
[super setUp];
// create a mock instance of the identity database
// patch Typhoon assembly to mock account controller database dependency
FRAApplicationAssembly *assembly = (FRAApplicationAssembly *) [TyphoonComponentFactory defaultFactory];
return mockIdentityModel;
}];
// load accounts controller from storyboard
accountsController = [storyboard instantiateViewControllerWithIdentifier:@"AccountsTableController"];
}
- (void)tearDown {
[super tearDown];
}
- (void)testHasNoCellsWhenDatabaseIsEmpty {
// Given
// When
NSInteger rows = [accountsController tableView:accountsController.tableView numberOfRowsInSection:0];
// Then
}
// Given
FRAIdentity *firstIdentity = [FRAIdentity identityWithDatabase:nil accountName:@"Alice" issuer:@"Issuer_1" image:nil];
FRAIdentity *secondIdentity = [FRAIdentity identityWithDatabase:nil accountName:@"Bob" issuer:@"Issuer_1" image:nil];
FRAIdentity *thirdIdentity = [FRAIdentity identityWithDatabase:nil accountName:@"Alice" issuer:@"Issuer_2" image:nil];
NSArray *identities = @[secondIdentity, thirdIdentity, firstIdentity]; // NB. Identities aren't sorted
// When
NSInteger rows = [accountsController tableView:accountsController.tableView numberOfRowsInSection:0];
// Then
}
// Given
FRAIdentity *identity = [FRAIdentity identityWithDatabase:nil accountName:@"Alice" issuer:@"Issuer" image:nil];
// When
// Then
}
// FIXME: testShowsTokenIconWithoutBadgeForOathMechanism
//- (void)testShowsTokenIconWithoutBadgeForOathMechanism {
// // Given
// FRAIdentity *identity = [FRAIdentity identityWithDatabase:nil accountName:@"Alice" issuer:@"Issuer" image:nil];
// FRAOathMechanism *oathMechanism = [[FRAOathMechanism alloc] init];
// [identity addMechanism:oathMechanism];
// XCTAssertNotNil([identity mechanismOfClass:[FRAOathMechanism class]]);
// NSArray* identities = @[identity];
// OCMStub([mockIdentityModel identities]).andReturn(identities);
//
// // When
// FRAAccountTableViewCell *cell = [self cellForRow:0];
//
// // Then
// XCTAssertFalse(cell.firstMechanismIcon.hidden);
// XCTAssertTrue(cell.secondMechanismIcon.hidden);
// XCTAssertEqualObjects(cell.notificationsBadge.text, @"0");
// XCTAssertTrue(cell.notificationsBadge.hidesWhenZero);
//}
// FIXME: testCanShowOathMechanismAndPushMechanism
//- (void)testCanShowOathMechanismAndPushMechanism {
// // Given
// FRAIdentity *identity = [FRAIdentity identityWithDatabase:nil accountName:@"Alice" issuer:@"Issuer" image:nil];
// FRAOathMechanism *oathMechanism = [[FRAOathMechanism alloc] init];
// [identity addMechanism:oathMechanism];
// FRAPushMechanism *pushMechanism = [[FRAPushMechanism alloc] initWithDatabase:nil];
// [pushMechanism addNotification:[[FRANotification alloc] init]];
// [identity addMechanism:pushMechanism];
// XCTAssertNotNil([identity mechanismOfClass:[FRAOathMechanism class]]);
// XCTAssertNotNil([identity mechanismOfClass:[FRAPushMechanism class]]);
// NSArray* identities = @[identity];
// OCMStub([mockIdentityModel identities]).andReturn(identities);
//
// // When
// FRAAccountTableViewCell *cell = [self cellForRow:0];
//
// // Then
// XCTAssertFalse(cell.firstMechanismIcon.hidden);
// XCTAssertFalse(cell.secondMechanismIcon.hidden);
// XCTAssertEqualObjects(cell.notificationsBadge.text, @"1");
// XCTAssertTrue(cell.notificationsBadge.hidesWhenZero);
//}
return (FRAAccountTableViewCell*) [accountsController tableView:accountsController.tableView cellForRowAtIndexPath:indexPath];
}
}
@end