From f1243168ed11f2135f8fa06266bad976962c122d Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 25 Jun 2015 13:55:59 +0200 Subject: [PATCH] Tests: fix contact edition test by handling """propertly""" tableview edit button --- Classes/ContactDetailsTableViewController.m | 4 - Classes/ContactsTableViewController.m | 7 -- KifTests/ChatTester.m | 34 ++----- KifTests/ContactsTester.m | 102 +++++++++++--------- KifTests/LinphoneTestCase.h | 5 +- KifTests/LinphoneTestCase.m | 18 +++- KifTests/WizardTester.m | 69 ++++++------- submodules/linphone | 2 +- 8 files changed, 121 insertions(+), 120 deletions(-) diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index b92b72986..82f709fe6 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -108,10 +108,6 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {ContactSe self.tableView.accessibilityIdentifier = @"Contact numbers table"; } -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; -} - #pragma mark - - (BOOL)isValid { diff --git a/Classes/ContactsTableViewController.m b/Classes/ContactsTableViewController.m index f13b1dbdd..652352fa7 100644 --- a/Classes/ContactsTableViewController.m +++ b/Classes/ContactsTableViewController.m @@ -205,13 +205,6 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf [controller loadData]; } -#pragma mark - ViewController Functions - -- (void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; -} - - #pragma mark - UITableViewDataSource Functions - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { diff --git a/KifTests/ChatTester.m b/KifTests/ChatTester.m index 984c98105..918522ba8 100644 --- a/KifTests/ChatTester.m +++ b/KifTests/ChatTester.m @@ -8,9 +8,6 @@ #import "ChatTester.h" #include "LinphoneManager.h" -#import "UIChatRoomCell.h" - -#import "KIF/UIApplication-KIFAdditions.h" @implementation ChatTester @@ -67,7 +64,7 @@ #pragma mark - tests - (void)testSendMessageToMyself { - [self startChatWith:[self accountUsername]]; + [self startChatWith:[self me]]; [self sendMessage:@"Hello"]; @@ -88,11 +85,11 @@ } - (void)testSendToSIPAddress { - NSString *sipAddr = [NSString stringWithFormat:@"sip:%@@%@", [self accountUsername], [self accountDomain]]; + NSString *sipAddr = [NSString stringWithFormat:@"sip:%@@%@", [self me], [self accountDomain]]; [self startChatWith:sipAddr]; - [tester waitForViewWithAccessibilityLabel:@"Contact name" value:@"testios" traits:0]; + [tester waitForViewWithAccessibilityLabel:@"Contact name" value:[self me] traits:0]; [self goBackFromChat]; } @@ -153,17 +150,6 @@ ASSERT_EQ(linphone_core_get_chat_rooms([LinphoneManager getLc]), NULL); } -- (UITableView *)findTableView:(NSString *)table { - UITableView *tv = nil; - NSError *err = nil; - if ([tester tryFindingAccessibilityElement:nil view:&tv withIdentifier:table tappable:false error:&err]) { - XCTAssertNotNil(tv); - } else { - XCTFail(@"Error: %@", err); - } - return tv; -} - - (void)uploadImageWithQuality:(NSString *)quality { UITableView *tv = [self findTableView:@"Chat list"]; @@ -195,8 +181,7 @@ } - (void)testUploadImage { - NSString *myself = @"testios"; - [self startChatWith:myself]; + [self startChatWith:[self me]]; ASSERT_EQ([[LinphoneManager instance] fileTransferDelegates].count, 0); [self uploadImageWithQuality:@"Minimum"]; @@ -204,7 +189,7 @@ [self goBackFromChat]; // if we go back to the same chatroom, the message should be still there - [self startChatWith:myself]; + [self startChatWith:[self me]]; UITableView *tv = [self findTableView:@"Chat list"]; ASSERT_EQ([tv numberOfRowsInSection:0], 1); @@ -221,8 +206,7 @@ } - (void)testCancelUploadImage { - NSString *myself = @"testios"; - [self startChatWith:myself]; + [self startChatWith:[self me]]; [self uploadImageWithQuality:@"Minimum"]; [tester tapViewWithAccessibilityLabel:@"Cancel transfer"]; if ([[[LinphoneManager instance] fileTransferDelegates] count] != 0) { @@ -233,8 +217,7 @@ } - (void)test3UploadsSimultanously { - NSString *myself = @"testios"; - [self startChatWith:myself]; + [self startChatWith:[self me]]; // use Maximum quality to be sure that first transfer is not terminated when the third begins [self uploadImageWithQuality:@"Maximum"]; [self uploadImageWithQuality:@"Maximum"]; @@ -252,8 +235,7 @@ } - (void)downloadImage { - NSString *myself = @"testios"; - [self startChatWith:myself]; + [self startChatWith:[self me]]; [self uploadImageWithQuality:@"Minimum"]; // wait for the upload to terminate... for (int i = 0; i < 15; i++) { diff --git a/KifTests/ContactsTester.m b/KifTests/ContactsTester.m index f7c89a176..0bbafb2b6 100644 --- a/KifTests/ContactsTester.m +++ b/KifTests/ContactsTester.m @@ -63,35 +63,50 @@ - (void)testDeleteContact { NSString* contactName = [self getUUID]; - [self createContact:contactName lastName:@"dummy" phoneNumber:@"0102030405" SIPAddress:@"testios"]; - - NSString* fullName = [contactName stringByAppendingString:@" dummy"]; - - [tester tapViewWithAccessibilityLabel: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]; + [self createContact:contactName lastName:@"dummy" phoneNumber:@"0102030405" SIPAddress:[self me]]; + + NSString *fullName = [contactName stringByAppendingString:@" dummy"]; + + [tester tapViewWithAccessibilityLabel: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]; } -- (void)addNumbersToSection:(NSInteger)section numbers:(NSArray*)numbers { +- (void)tapEditButtonForRowAtIndexPath:(NSInteger)idx inSection:(NSInteger)section { + // tap the "+" to add a new item (or "-" to delete it).... WOW, this code is ugly! + // the thing is: we don't handle the "+" button ourself (system stuff) + // so it is not present in the tableview cell... so we tap on a fixed position of screen :) + UITableView *tv = [self findTableView:@"Contact numbers table"]; + NSIndexPath *path = [NSIndexPath indexPathForRow:idx inSection:section]; + UITableViewCell *last = + [tester waitForCellAtIndexPath:path inTableViewWithAccessibilityIdentifier:@"Contact numbers table"]; + XCTAssertNotNil(last); - [tester tapViewWithAccessibilityLabel:@"Edit"]; - for(NSInteger i = 0; i +#import @interface LinphoneTestCase : KIFTestCase @property BOOL invalidAccountSet; - (void)switchToValidAccountIfNeeded; -- (NSString*)accountUsername; +- (NSString *)me; - (NSString*)accountDomain; - (NSString*)getUUID; - (NSArray*)getUUIDArrayOfSize:(size_t)size; +- (UITableView *)findTableView:(NSString *)table; + @end #define ASSERT_EQ(actual, expected) \ diff --git a/KifTests/LinphoneTestCase.m b/KifTests/LinphoneTestCase.m index 2da354b6a..d484327b2 100644 --- a/KifTests/LinphoneTestCase.m +++ b/KifTests/LinphoneTestCase.m @@ -25,8 +25,8 @@ } } -- (NSString *)accountUsername { - return @"testios"; +- (NSString *)me { + return @"testios"; } - (NSString *)accountDomain { @@ -74,7 +74,7 @@ static bool invalidAccount = true; LinphoneAddress* addr = linphone_core_interpret_url(lc, identity); const char* username = linphone_address_get_username(addr); - if (addr && (username && strcmp(username, [[self accountUsername] UTF8String]) == 0) && + if (addr && (username && strcmp(username, [[self me] UTF8String]) == 0) && (domain && strcmp(domain, [[self accountDomain] UTF8String]) == 0) && linphone_proxy_config_get_state(cfg) == LinphoneRegistrationOk) { isOK = true; @@ -107,7 +107,7 @@ static bool invalidAccount = true; [tester tapViewWithAccessibilityLabel:@"Start"]; [tester tapViewWithAccessibilityLabel:@"Sign in linphone.org account"]; - [tester enterText:@"testios" intoViewWithAccessibilityLabel:@"Username"]; + [tester enterText:[self me] intoViewWithAccessibilityLabel:@"Username"]; [tester enterText:@"testtest" intoViewWithAccessibilityLabel:@"Password"]; [tester tapViewWithAccessibilityLabel:@"Sign in"]; @@ -116,5 +116,15 @@ static bool invalidAccount = true; } } +- (UITableView *)findTableView:(NSString *)table { + UITableView *tv = nil; + NSError *err = nil; + if ([tester tryFindingAccessibilityElement:nil view:&tv withIdentifier:table tappable:false error:&err]) { + XCTAssertNotNil(tv); + } else { + XCTFail(@"Error: %@", err); + } + return tv; +} @end diff --git a/KifTests/WizardTester.m b/KifTests/WizardTester.m index 4ac3c337c..19f9fd572 100644 --- a/KifTests/WizardTester.m +++ b/KifTests/WizardTester.m @@ -52,49 +52,50 @@ [self setInvalidAccountSet:true]; [tester tapViewWithAccessibilityLabel:@"Start"]; [tester tapViewWithAccessibilityLabel:@"Sign in SIP account"]; - - [tester enterText:@"testios" intoViewWithAccessibilityLabel:@"Username"]; - [tester enterText:@"testtest" intoViewWithAccessibilityLabel:@"Password"]; - [tester enterText:@"sip.linphone.org" intoViewWithAccessibilityLabel:@"Domain"]; - [tester tapViewWithAccessibilityLabel:protocol]; - - [tester tapViewWithAccessibilityLabel:@"Sign in"]; - - // check the registration state - UIView* regState = [tester waitForViewWithAccessibilityLabel:@"Registration state"]; - [tester waitForTimeInterval:1]; - [tester expectView:regState toContainText:@"Registered"]; + + [tester enterText:[self me] intoViewWithAccessibilityLabel:@"Username"]; + [tester enterText:@"testtest" intoViewWithAccessibilityLabel:@"Password"]; + [tester enterText:[self accountDomain] intoViewWithAccessibilityLabel:@"Domain"]; + [tester tapViewWithAccessibilityLabel:protocol]; + + [tester tapViewWithAccessibilityLabel:@"Sign in"]; + + // check the registration state + UIView *regState = [tester waitForViewWithAccessibilityLabel:@"Registration state"]; + [tester waitForTimeInterval:1]; + [tester expectView:regState toContainText:@"Registered"]; } #pragma mark - Tests - (void)testLinphoneLogin { - [self _linphoneLogin:@"testios" withPW:@"testtest"]; - - // check the registration state - UIView* regState = [tester waitForViewWithAccessibilityLabel:@"Registration state"]; - [tester waitForTimeInterval:1]; - [tester expectView:regState toContainText:@"Registered"]; - + [self _linphoneLogin:[self me] withPW:@"testtest"]; + + // check the registration state + UIView *regState = [tester waitForViewWithAccessibilityLabel:@"Registration state"]; + [tester waitForTimeInterval:1]; + [tester expectView:regState toContainText:@"Registered"]; } - (void)testLinphoneLoginWithBadPassword { - [self _linphoneLogin:@"testios" withPW:@"badPass"]; - - [self setInvalidAccountSet:true]; - - UIView* alertViewText = [tester waitForViewWithAccessibilityLabel:@"Registration failure" traits:UIAccessibilityTraitStaticText]; - if( alertViewText ){ - UIView *reason = [tester waitForViewWithAccessibilityLabel:@"Forbidden" traits:UIAccessibilityTraitStaticText]; - if( reason == nil ){ [tester fail]; - } else { - [tester tapViewWithAccessibilityLabel:@"OK"]; // alertview - [tester tapViewWithAccessibilityLabel:@"Cancel"]; // cancel wizard - } - } else { - [tester fail]; - } + [self _linphoneLogin:[self me] withPW:@"badPass"]; + + [self setInvalidAccountSet:true]; + + UIView *alertViewText = + [tester waitForViewWithAccessibilityLabel:@"Registration failure" traits:UIAccessibilityTraitStaticText]; + if (alertViewText) { + UIView *reason = [tester waitForViewWithAccessibilityLabel:@"Forbidden" traits:UIAccessibilityTraitStaticText]; + if (reason == nil) { + [tester fail]; + } else { + [tester tapViewWithAccessibilityLabel:@"OK"]; // alertview + [tester tapViewWithAccessibilityLabel:@"Cancel"]; // cancel wizard + } + } else { + [tester fail]; + } } - (void)testExternalLoginWithUDP { diff --git a/submodules/linphone b/submodules/linphone index cb878f6c0..fb74ece02 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit cb878f6c007cf87e0585edf7e3bc999dbe818c81 +Subproject commit fb74ece02a13e2474acd87071c98c9c7622bc252