JLChen
2021-08-02 38f4fb064df09f344fc3237409c76a9fba2a8a9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright (c) 2010-2019 Belledonne Communications SARL.
 *
 * This file is part of linphone-iphone
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
 
#import "AssistantTester.h"
#import <KIF/KIF.h>
#import "LinphoneManager.h"
 
@implementation AssistantTester
 
- (void)beforeEach {
    [super beforeEach];
    [UIView setAnimationsEnabled:false];
 
    [tester tapViewWithAccessibilityLabel:@"Side menu button"];
    [tester tapViewWithAccessibilityLabel:@"Assistant"];
}
 
- (void)afterEach {
    [super afterEach];
    [LinphoneManager.instance removeAllAccounts];
    if ([tester tryFindingTappableViewWithAccessibilityLabel:@"Cancel" error:nil]) {
        [tester tapViewWithAccessibilityLabel:@"Cancel"];
    }
    [tester tapViewWithAccessibilityLabel:@"Dialer"];
}
 
#pragma mark - Utilities
 
- (void)_linphoneLogin:(NSString *)username withPW:(NSString *)pw {
    [tester tapViewWithAccessibilityLabel:@"Use Linphone account"];
 
    [tester enterText:username intoViewWithAccessibilityLabel:@"Username"];
    [tester enterText:pw intoViewWithAccessibilityLabel:@"Password"];
 
    [tester tapViewWithAccessibilityLabel:@"Login"];
}
 
- (void)_externalLoginWithProtocol:(NSString *)protocol {
    [tester tapViewWithAccessibilityLabel:@"Use SIP account"];
 
    [tester enterText:[self me] intoViewWithAccessibilityLabel:@"Username"];
    [tester enterText:[self me] intoViewWithAccessibilityLabel:@"Password"];
    [tester clearTextFromViewWithAccessibilityLabel:@"Domain"];
    [tester enterText:[self accountDomain] intoViewWithAccessibilityLabel:@"Domain"];
    [tester tapViewWithAccessibilityLabel:protocol];
 
    [tester tapViewWithAccessibilityLabel:@"Login"];
}
 
#pragma mark - Tests
 
- (void)testAccountCreation {
    NSString *username = [NSString stringWithFormat:@"%@-%.2f", [self getUUID], [[NSDate date] timeIntervalSince1970]];
    [tester tapViewWithAccessibilityLabel:@"Create account" traits:UIAccessibilityTraitButton];
 
    [tester enterText:username intoViewWithAccessibilityLabel:@"Username"];
    [tester enterText:username intoViewWithAccessibilityLabel:@"Password "];
    [tester enterText:username intoViewWithAccessibilityLabel:@"Password confirmation"];
    [tester enterText:@"testios@.dev.null" intoViewWithAccessibilityLabel:@"Email"];
 
    [tester tapViewWithAccessibilityLabel:@"Create account" traits:UIAccessibilityTraitButton];
 
    [tester waitForViewWithAccessibilityLabel:@"Finish configuration" traits:UIAccessibilityTraitButton];
    [tester tapViewWithAccessibilityLabel:@"Finish configuration"];
 
    [tester waitForViewWithAccessibilityLabel:@"Account validation failed"];
    [tester tapViewWithAccessibilityLabel:@"Skip verification"];
}
 
- (void)testExternalLoginWithTCP {
    [self _externalLoginWithProtocol:@"TCP"];
    [self waitForRegistration];
}
 
- (void)testExternalLoginWithTLS {
    [self _externalLoginWithProtocol:@"TLS"];
    [self waitForRegistration];
}
 
- (void)testExternalLoginWithUDP {
    [self _externalLoginWithProtocol:@"UDP"];
    [self waitForRegistration];
}
 
- (void)testLinphoneLogin {
    [self _linphoneLogin:@"testios" withPW:@"testtest"];
    [self waitForRegistration];
}
 
- (void)testLinphoneLoginWithBadPassword {
    [self _linphoneLogin:@"testios" withPW:@"badPass"];
 
    [self setInvalidAccountSet:true];
 
    UIView *alertViewText =
        [tester waitForViewWithAccessibilityLabel:@"Connection failure" traits:UIAccessibilityTraitStaticText];
    if (alertViewText) {
        UIView *reason = [tester waitForViewWithAccessibilityLabel:@"Bad credentials, check your account settings"
                                                            traits:UIAccessibilityTraitStaticText];
        if (reason == nil) {
            [tester fail];
        } else {
            [tester tapViewWithAccessibilityLabel:@"Continue"];
        }
    } else {
        [tester fail];
    }
}
 
- (void)testRemoteProvisioning {
    [tester tapViewWithAccessibilityLabel:@"Fetch remote configuration"];
    [tester enterText:@"smtp.linphone.org/testios_xml" intoViewWithAccessibilityLabel:@"URL"];
    [tester tapViewWithAccessibilityLabel:@"Fetch and apply"];
    [self waitForRegistration];
}
@end