@@ -28,25 +28,28 @@ - (void)setUp
28
28
_app = [[XCUIApplication alloc ] init ];
29
29
[_app launch ];
30
30
31
- _window = _app.windows [@" RNCAsyncStorageExample macOS" ];
32
- XCTAssert (_window.exists );
31
+ NSPredicate *exists = [NSPredicate predicateWithFormat: @" exists == 1" ];
32
+
33
+ _window = _app.windows [@" AsyncStorageExample" ];
34
+ [self waitForExpectation: exists evaluatedWithObject: _window timeout: 5 ];
33
35
34
36
_restartButton = _window.otherElements [@" restart_button" ].staticTexts .firstMatch ;
35
- XCTAssert (_restartButton. exists ) ;
37
+ [ self waitForExpectation: exists evaluatedWithObject: _restartButton timeout: 5 ] ;
36
38
37
39
_getSetClearButton = _window.buttons [@" testType_getSetClear" ].staticTexts .firstMatch ;
38
- XCTAssert (_getSetClearButton. exists ) ;
40
+ [ self waitForExpectation: exists evaluatedWithObject: _getSetClearButton timeout: 5 ] ;
39
41
40
42
_mergeItemButton = _window.buttons [@" testType_mergeItem" ].staticTexts .firstMatch ;
41
- XCTAssert (_mergeItemButton. exists ) ;
43
+ [ self waitForExpectation: exists evaluatedWithObject: _mergeItemButton timeout: 5 ] ;
42
44
43
- [self sendTestAppCommand: @" rnc-asyncstorage://clear-all-storage" ];
45
+ [self setDelegate ];
46
+ [self clear ];
47
+ [self unsetDelegate ];
48
+ [self clear ];
44
49
}
45
50
46
51
- (void )testShouldStoreValueInAsyncStorage
47
52
{
48
- [self sendTestAppCommand: @" rnc-asyncstorage://unset-delegate" ];
49
-
50
53
[_getSetClearButton click ];
51
54
52
55
XCUIElement *storedNumber = _window.staticTexts [@" storedNumber_text" ];
@@ -64,13 +67,11 @@ - (void)testShouldStoreValueInAsyncStorage
64
67
65
68
NSString *expectedText = [NSString stringWithFormat: @" %d " , tapTimes * 10 ];
66
69
67
- XCTAssertEqualObjects (storedNumber.label , expectedText);
70
+ XCTAssertEqualObjects (storedNumber.value , expectedText);
68
71
}
69
72
70
73
- (void )testShouldClearItem
71
74
{
72
- [self sendTestAppCommand: @" rnc-asyncstorage://unset-delegate" ];
73
-
74
75
[_getSetClearButton click ];
75
76
76
77
XCUIElement *increaseBy10Button =
@@ -85,36 +86,8 @@ - (void)testShouldClearItem
85
86
XCTAssertEqualObjects (storedNumber.label , @" " );
86
87
}
87
88
88
- - (NSString *)performInputWithFormat :format
89
- {
90
- NSString *name = arc4random_uniform (2 ) == 0 ? @" Jerry" : @" Sarah" ;
91
- NSString *age = arc4random_uniform (2 ) == 0 ? @" 21" : @" 23" ;
92
- NSString *eyeColor = arc4random_uniform (2 ) == 0 ? @" blue" : @" green" ;
93
- NSString *shoeSize = arc4random_uniform (2 ) == 0 ? @" 9" : @" 10" ;
94
-
95
- XCUIElement *nameInput = _window.textFields [@" testInput-name" ];
96
- [nameInput click ];
97
- [nameInput typeText: name];
98
-
99
- XCUIElement *ageInput = _window.textFields [@" testInput-age" ];
100
- [ageInput click ];
101
- [ageInput typeText: age];
102
-
103
- XCUIElement *eyesInput = _window.textFields [@" testInput-eyes" ];
104
- [eyesInput click ];
105
- [eyesInput typeText: eyeColor];
106
-
107
- XCUIElement *showInput = _window.textFields [@" testInput-shoe" ];
108
- [showInput click ];
109
- [showInput typeText: shoeSize];
110
-
111
- return [NSString stringWithFormat: format, name, age, eyeColor, shoeSize];
112
- }
113
-
114
89
- (void )testShouldMergeItemsInAsyncStorage
115
90
{
116
- [self sendTestAppCommand: @" rnc-asyncstorage://unset-delegate" ];
117
-
118
91
[_mergeItemButton click ];
119
92
120
93
XCUIElement *saveItemButton = _window.buttons [@" saveItem_button" ].staticTexts .firstMatch ;
@@ -128,7 +101,7 @@ - (void)testShouldMergeItemsInAsyncStorage
128
101
[saveItemButton click ];
129
102
[_restartButton click ];
130
103
[restoreItemButton click ];
131
- XCTAssertEqualObjects (storyText.label , story);
104
+ XCTAssertEqualObjects (storyText.value , story);
132
105
[_restartButton click ];
133
106
134
107
// merging here
@@ -137,16 +110,15 @@ - (void)testShouldMergeItemsInAsyncStorage
137
110
[mergeItemButton click ];
138
111
[_restartButton click ];
139
112
[restoreItemButton click ];
140
- XCTAssertEqualObjects (storyText.label , newStory);
113
+ XCTAssertEqualObjects (storyText.value , newStory);
141
114
}
142
115
143
116
- (void )testMergeItemDelegate
144
117
{
145
- [self sendTestAppCommand: @" rnc-asyncstorage://set-delegate " ];
118
+ [self setDelegate ];
146
119
147
120
[_mergeItemButton click ];
148
121
149
- XCUIElement *saveItemButton = _window.buttons [@" saveItem_button" ].staticTexts .firstMatch ;
150
122
XCUIElement *restoreItemButton = _window.buttons [@" restoreItem_button" ].staticTexts .firstMatch ;
151
123
XCUIElement *mergeItemButton = _window.buttons [@" mergeItem_button" ].staticTexts .firstMatch ;
152
124
XCUIElement *storyText = _window.staticTexts [@" storyTextView" ];
@@ -157,13 +129,69 @@ - (void)testMergeItemDelegate
157
129
[mergeItemButton click ];
158
130
[_restartButton click ];
159
131
[restoreItemButton click ];
160
- XCTAssertEqualObjects (storyText.label , story);
132
+ XCTAssertEqualObjects (storyText.value , story);
133
+ }
134
+
135
+ #pragma mark - Private
136
+
137
+ - (void )clear
138
+ {
139
+ [_getSetClearButton click ];
140
+ [self clickButton: @" clear_button" ];
141
+ }
142
+
143
+ - (void )clickButton : (NSString *)identifier
144
+ {
145
+ NSPredicate *exists = [NSPredicate predicateWithFormat: @" exists == 1" ];
146
+ XCUIElement *button = _window.buttons [identifier].staticTexts .firstMatch ;
147
+ [self waitForExpectation: exists evaluatedWithObject: button timeout: 5 ];
148
+ [button click ];
149
+ }
150
+
151
+ - (NSString *)performInputWithFormat :format
152
+ {
153
+ NSString *name = arc4random_uniform (2 ) == 0 ? @" Jerry" : @" Sarah" ;
154
+ NSString *age = arc4random_uniform (2 ) == 0 ? @" 21" : @" 23" ;
155
+ NSString *eyeColor = arc4random_uniform (2 ) == 0 ? @" blue" : @" green" ;
156
+ NSString *shoeSize = arc4random_uniform (2 ) == 0 ? @" 9" : @" 10" ;
157
+
158
+ XCUIElement *nameInput = _window.textFields [@" testInput-name" ];
159
+ [nameInput click ];
160
+ [nameInput typeText: name];
161
+
162
+ XCUIElement *ageInput = _window.textFields [@" testInput-age" ];
163
+ [ageInput click ];
164
+ [ageInput typeText: age];
165
+
166
+ XCUIElement *eyesInput = _window.textFields [@" testInput-eyes" ];
167
+ [eyesInput click ];
168
+ [eyesInput typeText: eyeColor];
169
+
170
+ XCUIElement *showInput = _window.textFields [@" testInput-shoe" ];
171
+ [showInput click ];
172
+ [showInput typeText: shoeSize];
173
+
174
+ return [NSString stringWithFormat: format, name, age, eyeColor, shoeSize];
175
+ }
176
+
177
+ - (void )setDelegate
178
+ {
179
+ [_mergeItemButton click ];
180
+ [self clickButton: @" setDelegate_button" ];
181
+ }
182
+
183
+ - (void )unsetDelegate
184
+ {
185
+ [_mergeItemButton click ];
186
+ [self clickButton: @" unsetDelegate_button" ];
161
187
}
162
188
163
- - (void )sendTestAppCommand : (NSString *)URLString
189
+ - (void )waitForExpectation : (NSPredicate *)predicate
190
+ evaluatedWithObject : (id )object
191
+ timeout : (NSTimeInterval )timeout
164
192
{
165
- [[ NSWorkspace sharedWorkspace ] openURL: [ NSURL URLWithString: URLString] ];
166
- sleep (. 25 ) ;
193
+ [self expectationForPredicate: predicate evaluatedWithObject: object handler: nil ];
194
+ [ self waitForExpectationsWithTimeout: timeout handler: nil ] ;
167
195
}
168
196
169
197
@end
0 commit comments