|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
8 | | -#import <XCTest/XCTest.h> |
9 | 8 | #import <RNCAsyncStorage/RNCAsyncStorage.h> |
| 9 | +#import <XCTest/XCTest.h> |
10 | 10 |
|
11 | 11 | @interface AsyncStorageExample_macOSUITests : XCTestCase |
12 | 12 |
|
13 | 13 | @end |
14 | 14 |
|
15 | | -@implementation AsyncStorageExample_macOSUITests |
16 | | -{ |
17 | | - XCUIApplication *_app; |
18 | | - XCUIElement *_window; |
19 | | - XCUIElement *_restartButton; |
20 | | - XCUIElement *_getSetClearButton; |
21 | | - XCUIElement *_mergeItemButton; |
| 15 | +@implementation AsyncStorageExample_macOSUITests { |
| 16 | + XCUIApplication *_app; |
| 17 | + XCUIElement *_window; |
| 18 | + XCUIElement *_restartButton; |
| 19 | + XCUIElement *_getSetClearButton; |
| 20 | + XCUIElement *_mergeItemButton; |
22 | 21 | } |
23 | 22 |
|
24 | | -- (void)setUp { |
25 | | - // In UI tests it is usually best to stop immediately when a failure occurs. |
26 | | - self.continueAfterFailure = NO; |
| 23 | +- (void)setUp |
| 24 | +{ |
| 25 | + // In UI tests it is usually best to stop immediately when a failure occurs. |
| 26 | + self.continueAfterFailure = NO; |
27 | 27 |
|
28 | | - _app = [[XCUIApplication alloc] init]; |
29 | | - [_app launch]; |
30 | | - |
31 | | - _window = _app.windows[@"RNCAsyncStorageExample macOS"]; |
32 | | - XCTAssert(_window.exists); |
| 28 | + _app = [[XCUIApplication alloc] init]; |
| 29 | + [_app launch]; |
33 | 30 |
|
34 | | - _restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch; |
35 | | - XCTAssert(_restartButton.exists); |
| 31 | + _window = _app.windows[@"RNCAsyncStorageExample macOS"]; |
| 32 | + XCTAssert(_window.exists); |
36 | 33 |
|
37 | | - _getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch; |
38 | | - XCTAssert(_getSetClearButton.exists); |
| 34 | + _restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch; |
| 35 | + XCTAssert(_restartButton.exists); |
39 | 36 |
|
40 | | - _mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch; |
41 | | - XCTAssert(_mergeItemButton.exists); |
42 | | - |
43 | | - [self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"]; |
| 37 | + _getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch; |
| 38 | + XCTAssert(_getSetClearButton.exists); |
| 39 | + |
| 40 | + _mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch; |
| 41 | + XCTAssert(_mergeItemButton.exists); |
| 42 | + |
| 43 | + [self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"]; |
44 | 44 | } |
45 | 45 |
|
46 | | -- (void)testShouldStoreValueInAsyncStorage { |
47 | | - [self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"]; |
| 46 | +- (void)testShouldStoreValueInAsyncStorage |
| 47 | +{ |
| 48 | + [self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"]; |
| 49 | + |
| 50 | + [_getSetClearButton click]; |
48 | 51 |
|
49 | | - [_getSetClearButton click]; |
| 52 | + XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"]; |
50 | 53 |
|
51 | | - XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"]; |
| 54 | + XCTAssertEqualObjects(storedNumber.label, @""); |
52 | 55 |
|
53 | | - XCTAssertEqualObjects(storedNumber.label, @""); |
| 56 | + XCUIElement *increaseBy10Button = |
| 57 | + _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch; |
54 | 58 |
|
55 | | - XCUIElement *increaseBy10Button = _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch; |
| 59 | + int tapTimes = arc4random_uniform(10) + 1; |
56 | 60 |
|
57 | | - int tapTimes = arc4random_uniform(10) + 1; |
58 | | - |
59 | | - for (int i = 0; i < tapTimes; i++) { |
60 | | - [increaseBy10Button click]; |
61 | | - } |
| 61 | + for (int i = 0; i < tapTimes; i++) { |
| 62 | + [increaseBy10Button click]; |
| 63 | + } |
62 | 64 |
|
63 | | - NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10]; |
64 | | - |
65 | | - XCTAssertEqualObjects(storedNumber.label, expectedText); |
| 65 | + NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10]; |
| 66 | + |
| 67 | + XCTAssertEqualObjects(storedNumber.label, expectedText); |
66 | 68 | } |
67 | 69 |
|
68 | | -- (void)testShouldClearItem { |
69 | | - [self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"]; |
| 70 | +- (void)testShouldClearItem |
| 71 | +{ |
| 72 | + [self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"]; |
70 | 73 |
|
71 | | - [_getSetClearButton click]; |
| 74 | + [_getSetClearButton click]; |
72 | 75 |
|
73 | | - XCUIElement *increaseBy10Button = _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch; |
74 | | - [increaseBy10Button click]; |
| 76 | + XCUIElement *increaseBy10Button = |
| 77 | + _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch; |
| 78 | + [increaseBy10Button click]; |
75 | 79 |
|
76 | | - XCUIElement *clearButton = _window.buttons[@"clear_button"].staticTexts.firstMatch; |
77 | | - [clearButton click]; |
78 | | - [_restartButton click]; |
| 80 | + XCUIElement *clearButton = _window.buttons[@"clear_button"].staticTexts.firstMatch; |
| 81 | + [clearButton click]; |
| 82 | + [_restartButton click]; |
79 | 83 |
|
80 | | - XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"]; |
81 | | - XCTAssertEqualObjects(storedNumber.label, @""); |
| 84 | + XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"]; |
| 85 | + XCTAssertEqualObjects(storedNumber.label, @""); |
82 | 86 | } |
83 | 87 |
|
84 | | -- (NSString *)performInputWithFormat:format { |
85 | | - NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah"; |
86 | | - NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23"; |
87 | | - NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green"; |
88 | | - NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10"; |
89 | | - |
90 | | - XCUIElement *nameInput = _window.textFields[@"testInput-name"]; |
91 | | - [nameInput click]; |
92 | | - [nameInput typeText:name]; |
93 | | - |
94 | | - XCUIElement *ageInput = _window.textFields[@"testInput-age"]; |
95 | | - [ageInput click]; |
96 | | - [ageInput typeText:age]; |
97 | | - |
98 | | - XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"]; |
99 | | - [eyesInput click]; |
100 | | - [eyesInput typeText:eyeColor]; |
101 | | - |
102 | | - XCUIElement *showInput = _window.textFields[@"testInput-shoe"]; |
103 | | - [showInput click]; |
104 | | - [showInput typeText:shoeSize]; |
105 | | - |
106 | | - return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize]; |
| 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]; |
107 | 112 | } |
108 | 113 |
|
109 | | -- (void)testShouldMergeItemsInAsyncStorage { |
110 | | - [self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"]; |
111 | | - |
112 | | - [_mergeItemButton click]; |
113 | | - |
114 | | - XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch; |
115 | | - XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch; |
116 | | - XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch; |
117 | | - XCUIElement *storyText = _window.staticTexts[@"storyTextView"]; |
118 | | - |
119 | | - NSString *messageFormat = @"%@ is %@, has %@ eyes and shoe size of %@."; |
120 | | - |
121 | | - NSString *story = [self performInputWithFormat:messageFormat]; |
122 | | - [saveItemButton click]; |
123 | | - [_restartButton click]; |
124 | | - [restoreItemButton click]; |
125 | | - XCTAssertEqualObjects(storyText.label, story); |
126 | | - [_restartButton click]; |
127 | | - |
128 | | - // merging here |
129 | | - |
130 | | - NSString *newStory = [self performInputWithFormat:messageFormat]; |
131 | | - [mergeItemButton click]; |
132 | | - [_restartButton click]; |
133 | | - [restoreItemButton click]; |
134 | | - XCTAssertEqualObjects(storyText.label, newStory); |
| 114 | +- (void)testShouldMergeItemsInAsyncStorage |
| 115 | +{ |
| 116 | + [self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"]; |
| 117 | + |
| 118 | + [_mergeItemButton click]; |
| 119 | + |
| 120 | + XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch; |
| 121 | + XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch; |
| 122 | + XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch; |
| 123 | + XCUIElement *storyText = _window.staticTexts[@"storyTextView"]; |
| 124 | + |
| 125 | + NSString *messageFormat = @"%@ is %@, has %@ eyes and shoe size of %@."; |
| 126 | + |
| 127 | + NSString *story = [self performInputWithFormat:messageFormat]; |
| 128 | + [saveItemButton click]; |
| 129 | + [_restartButton click]; |
| 130 | + [restoreItemButton click]; |
| 131 | + XCTAssertEqualObjects(storyText.label, story); |
| 132 | + [_restartButton click]; |
| 133 | + |
| 134 | + // merging here |
| 135 | + |
| 136 | + NSString *newStory = [self performInputWithFormat:messageFormat]; |
| 137 | + [mergeItemButton click]; |
| 138 | + [_restartButton click]; |
| 139 | + [restoreItemButton click]; |
| 140 | + XCTAssertEqualObjects(storyText.label, newStory); |
135 | 141 | } |
136 | 142 |
|
137 | | -- (void)testMergeItemDelegate { |
138 | | - [self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"]; |
139 | | - |
140 | | - [_mergeItemButton click]; |
141 | | - |
142 | | - XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch; |
143 | | - XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch; |
144 | | - XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch; |
145 | | - XCUIElement *storyText = _window.staticTexts[@"storyTextView"]; |
146 | | - |
147 | | - NSString *story = [self performInputWithFormat:@"%@ from delegate is %@ from delegate, has %@ eyes and shoe size of %@."]; |
148 | | - [mergeItemButton click]; |
149 | | - [_restartButton click]; |
150 | | - [restoreItemButton click]; |
151 | | - XCTAssertEqualObjects(storyText.label, story); |
| 143 | +- (void)testMergeItemDelegate |
| 144 | +{ |
| 145 | + [self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"]; |
| 146 | + |
| 147 | + [_mergeItemButton click]; |
| 148 | + |
| 149 | + XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch; |
| 150 | + XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch; |
| 151 | + XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch; |
| 152 | + XCUIElement *storyText = _window.staticTexts[@"storyTextView"]; |
| 153 | + |
| 154 | + NSString *story = |
| 155 | + [self performInputWithFormat: |
| 156 | + @"%@ from delegate is %@ from delegate, has %@ eyes and shoe size of %@."]; |
| 157 | + [mergeItemButton click]; |
| 158 | + [_restartButton click]; |
| 159 | + [restoreItemButton click]; |
| 160 | + XCTAssertEqualObjects(storyText.label, story); |
152 | 161 | } |
153 | 162 |
|
154 | | -- (void)sendTestAppCommand:(NSString *)URLString { |
155 | | - [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]]; |
156 | | - sleep(.25); |
| 163 | +- (void)sendTestAppCommand:(NSString *)URLString |
| 164 | +{ |
| 165 | + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]]; |
| 166 | + sleep(.25); |
157 | 167 | } |
158 | 168 |
|
159 | 169 | @end |
0 commit comments