Add some unit tests

This commit is contained in:
Guillaume BIENKOWSKI 2015-02-17 23:03:31 +01:00
parent c775f069cc
commit 5703392b1c
10 changed files with 158 additions and 10 deletions

View file

@ -38,11 +38,11 @@
[super dealloc];
}
#pragma mark - ViewController Functions
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.tableView.accessibilityIdentifier = @"ChatRoom list";
[self loadData];
}

View file

@ -25,6 +25,15 @@
#import "UIContactDetailsHeader.h"
#import "UIContactDetailsFooter.h"
typedef enum _ContactSections {
ContactSections_None = 0,
ContactSections_Number,
ContactSections_Sip,
ContactSections_Email,
ContactSections_MAX
} ContactSections_e;
@interface ContactDetailsTableViewController : UITableViewController<ContactDetailsLabelViewDelegate, UITextFieldDelegate> {
@private
NSMutableArray *dataCache;

View file

@ -55,14 +55,6 @@
@implementation ContactDetailsTableViewController
typedef enum _ContactSections {
ContactSections_None = 0,
ContactSections_Number,
ContactSections_Sip,
ContactSections_Email,
ContactSections_MAX
} ContactSections_e;
static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSections_None, ContactSections_Number, ContactSections_Sip, ContactSections_Email};
@synthesize footerController;
@ -124,6 +116,8 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe
[super viewDidLoad];
[headerController view]; // Force view load
[footerController view]; // Force view load
self.tableView.accessibilityIdentifier = @"Contact numbers table";
}
- (void)viewDidDisappear:(BOOL)animated {

View file

@ -94,6 +94,7 @@
[normalView setAlpha:1.0f];
[editView setAlpha:0.0f];
[tableView setEditing:TRUE animated:false];
tableView.accessibilityIdentifier = @"Contact Name Table";
}

View file

@ -7,6 +7,7 @@
//
#import "ChatTester.h"
#include "LinphoneManager.h"
@implementation ChatTester
@ -98,5 +99,42 @@
[self goBackFromChat];
}
- (void)testRemoveAllChats {
NSArray* uuids = [self getUUIDArrayOfSize:5];
for( NSString* uuid in uuids ){
[self startChatWith:uuid];
[self sendMessage:@"Test"];
[self goBackFromChat];
}
[tester tapViewWithAccessibilityLabel:@"Edit" traits:UIAccessibilityTraitButton];
// we expect to be able to delete at least the amount of chatrooms we created
for( int i =0; i< uuids.count; i++){
[tester tapViewWithAccessibilityLabel:@"Delete" traits:UIAccessibilityTraitButton];
}
// then we try to delete all the rest of chatrooms
while ( [tester tryFindingTappableViewWithAccessibilityLabel:@"Delete" traits:UIAccessibilityTraitButton error:nil] )
{
[tester tapViewWithAccessibilityLabel:@"Delete" traits:UIAccessibilityTraitButton];
NSLog(@"Deleting an extra chat");
}
// check that the tableview is empty
UITableView* tv = nil;
NSError* err = nil;
if( [tester tryFindingAccessibilityElement:nil view:&tv withIdentifier:@"ChatRoom list" tappable:false error:&err] ){
XCTAssert(tv != nil);
XCTAssert([tv numberOfRowsInSection:0] == 0); // no more chat rooms
} else {
NSLog(@"Error: %@",err);
}
// test that there's no more chatrooms in the core
XCTAssert(linphone_core_get_chat_rooms([LinphoneManager getLc]) == nil);
}
@end

13
KifTests/ContactsTester.h Normal file
View file

@ -0,0 +1,13 @@
//
// ContactsTester.h
// linphone
//
// Created by Guillaume BIENKOWSKI on 17/02/2015.
//
//
#import "LinphoneTestCase.h"
@interface ContactsTester : LinphoneTestCase
@end

78
KifTests/ContactsTester.m Normal file
View file

@ -0,0 +1,78 @@
//
// ContactsTester.m
// linphone
//
// Created by Guillaume BIENKOWSKI on 17/02/2015.
//
//
#import "ContactsTester.h"
#import "ContactDetailsTableViewController.h"
@implementation ContactsTester
#pragma mark - Setup
- (void)beforeAll {
[tester tapViewWithAccessibilityLabel:@"Contacts"];
}
#pragma mark - Utils
- (void)setText:(NSString*)text forContactHeaderIndex:(NSInteger)idx {
[tester tapRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0] inTableViewWithAccessibilityIdentifier:@"Contact Name Table"];
[tester enterTextIntoCurrentFirstResponder:text];
}
- (void)setText:(NSString*)text forContactNumbersIndex:(NSInteger)idx inSection:(NSInteger)section {
[tester tapRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:section] inTableViewWithAccessibilityIdentifier:@"Contact numbers table"];
[tester enterTextIntoCurrentFirstResponder:text];
}
- (void)createContact:(NSString*)firstName lastName:(NSString*)lastName phoneNumber:(NSString*)phone SIPAddress:(NSString*)sip {
XCTAssert(firstName != nil);
[tester tapViewWithAccessibilityLabel:@"Add contact"];
// check that the OK button is disabled
[tester waitForViewWithAccessibilityLabel:@"Edit" traits:UIAccessibilityTraitButton|UIAccessibilityTraitNotEnabled|UIAccessibilityTraitSelected];
[self setText:firstName forContactHeaderIndex:0];
// entering text should enable the "edit" button
[tester waitForViewWithAccessibilityLabel:@"Edit" traits:UIAccessibilityTraitButton|UIAccessibilityTraitSelected];
if( lastName )
[self setText:lastName forContactHeaderIndex:1];
if ( phone )
[self setText:phone forContactNumbersIndex:0 inSection:ContactSections_Number];
if (sip)
[self setText:sip forContactNumbersIndex:0 inSection:ContactSections_Sip];
[tester tapViewWithAccessibilityLabel:@"Edit"];
[tester tapViewWithAccessibilityLabel:@"Back"];
}
#pragma mark - Tests
- (void)testDeleteContact {
NSString* contactName = [self getUUID];
[self createContact:contactName lastName:@"dummy" phoneNumber:@"0102030405" SIPAddress:@"testios"];
NSString* fullName = [contactName stringByAppendingString:@" dummy"];
[tester tapViewWithAccessibilityLabel:@"Firstname, Lastname" value:fullName traits:UIAccessibilityTraitStaticText];
[tester tapViewWithAccessibilityLabel:@"Edit"];
[tester scrollViewWithAccessibilityIdentifier:@"Contact numbers table" byFractionOfSizeHorizontal:0 vertical:-0.9];
[tester tapViewWithAccessibilityLabel:@"Remove"];
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Firstname, Lastname" value:fullName traits:UIAccessibilityTraitStaticText];
}
@end

View file

@ -16,5 +16,6 @@
- (NSString*)accountDomain;
- (NSString*)getUUID;
- (NSArray*)getUUIDArrayOfSize:(size_t)size;
@end

View file

@ -17,7 +17,7 @@
+ (void)initialize {
// default is 0.01, which sometimes confuses the simulator to the point that
// it will miss some keys
[KIFTypist setKeystrokeDelay:0.1];
[KIFTypist setKeystrokeDelay:0.05];
}
- (NSString *)accountUsername {
@ -32,6 +32,14 @@
return [[NSUUID UUID] UUIDString];
}
- (NSArray *)getUUIDArrayOfSize:(size_t)size {
NSMutableArray* array = [NSMutableArray arrayWithCapacity:size];
for (NSInteger i=0; i<size; i++) {
[array setObject:[self getUUID] atIndexedSubscript:i];
}
return array;
}
- (void)beforeAll{
#if TARGET_IPHONE_SIMULATOR
[tester acknowledgeSystemAlert];

View file

@ -780,6 +780,7 @@
F84015C01939FE37006ABAB5 /* test_inprogress.png in Resources */ = {isa = PBXBuildFile; fileRef = F84015BD1939FE37006ABAB5 /* test_inprogress.png */; };
F84015C11939FE37006ABAB5 /* test_passed.png in Resources */ = {isa = PBXBuildFile; fileRef = F84015BE1939FE37006ABAB5 /* test_passed.png */; };
F84015C7193B4E34006ABAB5 /* LogsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F84015C6193B4E34006ABAB5 /* LogsViewController.m */; };
F844AB141A93E3A200428306 /* ContactsTester.m in Sources */ = {isa = PBXBuildFile; fileRef = F844AB131A93E3A200428306 /* ContactsTester.m */; };
F85554481A6DA2F400A9F915 /* LinphoneTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = F85554471A6DA2F400A9F915 /* LinphoneTestCase.m */; };
/* End PBXBuildFile section */
@ -1790,6 +1791,8 @@
F84015BE1939FE37006ABAB5 /* test_passed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = test_passed.png; path = Resources/test_passed.png; sourceTree = "<group>"; };
F84015C5193B4E34006ABAB5 /* LogsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogsViewController.h; sourceTree = "<group>"; };
F84015C6193B4E34006ABAB5 /* LogsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LogsViewController.m; sourceTree = "<group>"; };
F844AB121A93E3A200428306 /* ContactsTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactsTester.h; sourceTree = "<group>"; };
F844AB131A93E3A200428306 /* ContactsTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactsTester.m; sourceTree = "<group>"; };
F85554461A6DA2F400A9F915 /* LinphoneTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinphoneTestCase.h; sourceTree = "<group>"; };
F85554471A6DA2F400A9F915 /* LinphoneTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LinphoneTestCase.m; sourceTree = "<group>"; };
F8DB48A1936CB14E39F5981D /* Pods-KifTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KifTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-KifTests/Pods-KifTests.debug.xcconfig"; sourceTree = "<group>"; };
@ -3022,6 +3025,8 @@
F0A1CE071A6B056E001CA2BE /* ChatTester.m */,
F85554461A6DA2F400A9F915 /* LinphoneTestCase.h */,
F85554471A6DA2F400A9F915 /* LinphoneTestCase.m */,
F844AB121A93E3A200428306 /* ContactsTester.h */,
F844AB131A93E3A200428306 /* ContactsTester.m */,
);
path = KifTests;
sourceTree = "<group>";
@ -3995,6 +4000,7 @@
buildActionMask = 2147483647;
files = (
F0A1CE081A6B056E001CA2BE /* ChatTester.m in Sources */,
F844AB141A93E3A200428306 /* ContactsTester.m in Sources */,
F85554481A6DA2F400A9F915 /* LinphoneTestCase.m in Sources */,
F0F952121A6AECD300254160 /* WizardTester.m in Sources */,
);