mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 19:18:06 +00:00
168 lines
5.8 KiB
Objective-C
168 lines
5.8 KiB
Objective-C
//
|
|
// ContactsTester.m
|
|
// linphone
|
|
//
|
|
// Created by Guillaume BIENKOWSKI on 17/02/2015.
|
|
//
|
|
//
|
|
|
|
#import "ContactsTester.h"
|
|
|
|
#import "ContactDetailsTableView.h"
|
|
|
|
@implementation ContactsTester
|
|
|
|
#pragma mark - Setup
|
|
|
|
- (void)beforeAll {
|
|
[self switchToValidAccountIfNeeded];
|
|
}
|
|
|
|
- (void)beforeEach {
|
|
[super beforeEach];
|
|
if ([tester tryFindingTappableViewWithAccessibilityLabel:@"Back" error:nil]) {
|
|
[tester tapViewWithAccessibilityLabel:@"Back"];
|
|
}
|
|
[tester tapViewWithAccessibilityLabel:@"Contacts"];
|
|
}
|
|
|
|
#pragma mark - Utils
|
|
|
|
- (void)setText:(NSString *)text forIndex:(NSInteger)idx inSection:(NSInteger)section {
|
|
[tester tapRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:section]
|
|
inTableViewWithAccessibilityIdentifier:@"Contact 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 forIndex:0 inSection:ContactSections_First_Name];
|
|
|
|
// entering text should enable the "edit" button
|
|
[tester waitForViewWithAccessibilityLabel:@"Edit" traits:UIAccessibilityTraitButton | UIAccessibilityTraitSelected];
|
|
|
|
if (lastName) {
|
|
[self setText:lastName forIndex:0 inSection:ContactSections_Last_Name];
|
|
}
|
|
|
|
if (phone) {
|
|
[self setText:phone forIndex:0 inSection:ContactSections_Number];
|
|
}
|
|
|
|
if (sip) {
|
|
[self setText:sip forIndex:0 inSection:ContactSections_Sip];
|
|
}
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
}
|
|
|
|
- (void)tapCellForRowAtIndexPath:(NSInteger)idx inSection:(NSInteger)section atX:(CGFloat)x {
|
|
UITableView *tv = [self findTableView:@"Contact table"];
|
|
NSIndexPath *path = [NSIndexPath indexPathForRow:idx inSection:section];
|
|
UITableViewCell *last =
|
|
[tester waitForCellAtIndexPath:path inTableViewWithAccessibilityIdentifier:@"Contact table"];
|
|
XCTAssertNotNil(last);
|
|
|
|
CGRect cellFrame = [last.contentView convertRect:last.contentView.frame toView:tv];
|
|
[tv tapAtPoint:CGPointMake(x > 0 ? x : cellFrame.size.width + x, cellFrame.origin.y + cellFrame.size.height / 2.)];
|
|
[tester waitForAnimationsToFinish];
|
|
}
|
|
|
|
- (void)tapRemoveButtonForRowAtIndexPath:(NSInteger)idx inSection:(NSInteger)section {
|
|
[self tapCellForRowAtIndexPath:idx inSection:section atX:-10];
|
|
}
|
|
|
|
- (void)addEntries:(NSArray *)numbers inSection:(NSInteger)section {
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
NSString *name = (section == ContactSections_Sip) ? @"Add new SIP address" : @"Add new phone number";
|
|
[self setText:[numbers objectAtIndex:0] forIndex:0 inSection:section];
|
|
for (NSInteger i = 1; i < numbers.count; i++) {
|
|
[tester tapViewWithAccessibilityLabel:name traits:UIAccessibilityTraitButton];
|
|
[self setText:[numbers objectAtIndex:i] forIndex:i inSection:section];
|
|
}
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
|
|
for (NSInteger i = 0; i < numbers.count; i++) {
|
|
[tester waitForViewWithAccessibilityLabel:[@"Call " stringByAppendingString:[numbers objectAtIndex:i]]
|
|
traits:UIAccessibilityTraitButton];
|
|
}
|
|
}
|
|
|
|
- (void)deleteContactEntryForRowAtIndexPath:(NSInteger)idx inSection:(NSInteger)section {
|
|
if ([tester tryFindingTappableViewWithAccessibilityLabel:@"Delete" error:nil]) {
|
|
[tester tapViewWithAccessibilityLabel:@"Delete"];
|
|
} else {
|
|
// hack: Travis seems to be unable to click on delete for what ever reason
|
|
[self tapRemoveButtonForRowAtIndexPath:idx inSection:section];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Tests
|
|
|
|
- (void)testCallContactWithInvalidPhoneNumber {
|
|
NSString *contactName = [self getUUID];
|
|
NSString *phone = @"+5 15 #0664;447*46";
|
|
[self createContact:contactName lastName:@"dummy" phoneNumber:phone SIPAddress:nil];
|
|
[tester tapViewWithAccessibilityLabel:[@"Call " stringByAppendingString:phone]];
|
|
[tester waitForViewWithAccessibilityLabel:[phone stringByAppendingString:@" is not registered."]];
|
|
[tester tapViewWithAccessibilityLabel:@"Cancel"];
|
|
}
|
|
|
|
- (void)testDeleteContact {
|
|
NSString *contactName = [self getUUID];
|
|
[self createContact:contactName lastName:@"dummy" phoneNumber:@"0102030405" SIPAddress:[self me]];
|
|
[tester tapViewWithAccessibilityLabel:@"Back"];
|
|
|
|
NSString *fullName = [contactName stringByAppendingString:@" dummy"];
|
|
|
|
[tester tapViewWithAccessibilityLabel:fullName traits:UIAccessibilityTraitStaticText];
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
[tester scrollViewWithAccessibilityIdentifier:@"Contact table" byFractionOfSizeHorizontal:0 vertical:-0.9];
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Delete"];
|
|
[tester tapViewWithAccessibilityLabel:@"DELETE"];
|
|
}
|
|
|
|
- (void)testEditContact {
|
|
NSString *contactName = [self getUUID];
|
|
[self createContact:contactName lastName:@"dummy" phoneNumber:nil SIPAddress:nil];
|
|
|
|
/* Phone number */
|
|
NSArray *phones = @[ @"01234", @"56789" ];
|
|
[self addEntries:phones inSection:ContactSections_Number];
|
|
NSArray *SIPs = @[ @"sip1", @"sip2" ];
|
|
[self addEntries:SIPs inSection:ContactSections_Sip];
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
// remove all numbers
|
|
for (NSInteger i = 0; i < phones.count; i++) {
|
|
[self tapRemoveButtonForRowAtIndexPath:0 inSection:ContactSections_Number];
|
|
}
|
|
// remove all SIPs
|
|
for (NSInteger i = 0; i < SIPs.count; i++) {
|
|
[self tapRemoveButtonForRowAtIndexPath:0 inSection:ContactSections_Sip];
|
|
}
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
|
|
// then remove the contact
|
|
[tester tapViewWithAccessibilityLabel:@"Edit"];
|
|
|
|
[tester scrollViewWithAccessibilityIdentifier:@"Contact table" byFractionOfSizeHorizontal:0 vertical:-0.9];
|
|
|
|
[tester tapViewWithAccessibilityLabel:@"Delete"];
|
|
[tester tapViewWithAccessibilityLabel:@"DELETE"];
|
|
}
|
|
|
|
@end
|