-
Notifications
You must be signed in to change notification settings - Fork 919
/
Copy pathTableViewTests_ViewTestActor.m
188 lines (143 loc) · 7.93 KB
/
TableViewTests_ViewTestActor.m
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// NewTableViewTests.m
// KIF
//
// Created by Alex Odawa on 1/27/15.
//
//
#import <KIF/KIF.h>
#import "KIFTestStepValidation.h"
#import "UIApplication-KIFAdditions.h"
@interface TableViewTests_ViewTestActor : KIFTestCase
@end
@implementation TableViewTests_ViewTestActor
- (void)beforeEach
{
[[viewTester usingLabel:@"TableViews"] tap];
}
- (void)afterEach
{
[[[viewTester usingLabel:@"Test Suite"] usingTraits:UIAccessibilityTraitButton] tap];
}
- (void)testTappingRows
{
[[viewTester usingIdentifier:@"TableView Tests Table"] tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]];
[[[viewTester usingLabel:@"Last Cell"] usingTraits:UIAccessibilityTraitSelected] waitForView];
[[viewTester usingIdentifier:@"TableView Tests Table"] tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[[[viewTester usingLabel:@"First Cell"] usingTraits:UIAccessibilityTraitSelected] waitForView];
}
- (void)testTappingLastRowAndSection
{
[[viewTester usingIdentifier:@"TableView Tests Table"] tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:-1]];
[[[viewTester usingLabel:@"Last Cell"] usingTraits:UIAccessibilityTraitSelected] waitForView];
}
- (void)testOutOfBounds
{
KIFExpectFailure([[[viewTester usingTimeout:1] usingIdentifier:@"TableView Tests Table"] tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:99]]);
}
- (void)testUnknownTable
{
KIFExpectFailure([[[viewTester usingTimeout:1] usingIdentifier:@"Unknown Table"] tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]);
}
- (void)testScrollingToTop
{
// The way we tap the status bar doesn't work in iOS 12+
// Issue #1172
// Disable this test on 12+ until that issue is resolved.
if (@available(iOS 12.0, *)) {
return;
}
[[viewTester usingIdentifier:@"TableView Tests Table"] tapRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
[viewTester tapStatusBar];
UITableView *tableView = (UITableView *)[viewTester usingIdentifier:@"TableView Tests Table"].view;
[viewTester runBlock:^KIFTestStepResult(NSError *__autoreleasing *error) {
KIFTestWaitCondition(tableView.contentOffset.y == - tableView.contentInset.top, error, @"Waited for scroll view to scroll to top, but it ended at %@", NSStringFromCGPoint(tableView.contentOffset));
return KIFTestStepResultSuccess;
}];
}
- (void)testTappingRowsByLabel
{
// Tap the first row, which is already visible
[[viewTester usingLabel:@"First Cell"] tap];
// Tap the last row, which will need to be scrolled up
[[viewTester usingLabel:@"Last Cell"] tap];
// Tap the first row, which will need to be scrolled down
[[viewTester usingLabel:@"First Cell"] tap];
}
- (void)testTappingRowUnderToolbarByLabel
{
// Ensure the toolbar is visible
[[viewTester usingIdentifier:@"Toolbar"] waitForView];
// Tap row 31, which will scroll so that cell 32 is precisely positioned under the toolbar
[[viewTester usingLabel:@"Cell 31"] tap];
// Tap row 32, which should be scrolled up above the toolbar and then tapped
[[viewTester usingLabel:@"Cell 32"] tap];
}
- (void)testWaitingRowByLabel
{
UIView *v = [[viewTester usingLabel:@"First Cell"] waitForView];
XCTAssertTrue([v isKindOfClass:[UITableViewCell class]] || [v isKindOfClass:NSClassFromString(@"UITableViewLabel")], @"actual: %@", [v class]);
}
- (void)testWaitingRowByLabelAfterTapping
{
// for view lookup changes caused by tapping rows
[[viewTester usingLabel:@"First Cell"] tap];
UIView *v = [[viewTester usingLabel:@"First Cell"] waitForView];
XCTAssertTrue([v isKindOfClass:[UITableViewCell class]] || [v isKindOfClass:NSClassFromString(@"UITableViewLabel")], @"actual: %@", [v class]);
}
- (void)testMoveRowDown
{
[[viewTester usingLabel:@"Edit"] tap];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]].textLabel.text, @"Cell 0", @"");
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:1]].textLabel.text, @"Cell 4", @"");
[[viewTester usingIdentifier:@"TableView Tests Table"] moveRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] toIndexPath:[NSIndexPath indexPathForRow:4 inSection:1]];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]].textLabel.text, @"Cell 1", @"");
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:1]].textLabel.text, @"Cell 0", @"");
[[viewTester usingLabel:@"Done"] tap];
}
- (void)testMoveRowUp
{
[[viewTester usingLabel:@"Edit"] tap];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]].textLabel.text, @"Cell 0", @"");
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:1]].textLabel.text, @"Cell 4", @"");
[[viewTester usingIdentifier:@"TableView Tests Table"] moveRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:1] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]].textLabel.text, @"Cell 4", @"");
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:1]].textLabel.text, @"Cell 3", @"");
[[viewTester usingLabel:@"Done"] tap];
}
- (void)testMoveRowUpUsingNegativeRowIndexes
{
[[viewTester usingLabel:@"Edit"] tap];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-3 inSection:1]].textLabel.text, @"Cell 35", @"");
[viewTester waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:1]];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:1]].textLabel.text, @"Cell 37", @"");
[[viewTester usingIdentifier:@"TableView Tests Table"] moveRowInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:1] toIndexPath:[NSIndexPath indexPathForRow:-3 inSection:1]];
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-3 inSection:1]].textLabel.text, @"Cell 37", @"");
__KIFAssertEqualObjects([[viewTester usingIdentifier:@"TableView Tests Table"] waitForCellInTableViewAtIndexPath:[NSIndexPath indexPathForRow:-1 inSection:1]].textLabel.text, @"Cell 36", @"");
[[viewTester usingLabel:@"Done"] tap];
}
- (void)testTogglingSwitch
{
[[viewTester usingLabel:@"Table View Switch"] setSwitchOn:NO];
[[viewTester usingLabel:@"Table View Switch"] setSwitchOn:YES];
}
- (void)testButtonAbsentAfterRemoveFromSuperview
{
[[viewTester usingLabel:@"Button"] waitForView];
[[viewTester usingLabel:@"Button"].view removeFromSuperview];
[[viewTester usingLabel:@"Button"] waitForAbsenceOfView];
}
- (void)testButtonAbsentAfterSetHidden
{
[[viewTester usingLabel:@"Button"] waitForView];
UIView *button = [viewTester usingLabel:@"Button"].view;
[button setHidden:YES];
[[viewTester usingLabel:@"Button"] waitForAbsenceOfView];
[button setHidden:NO];
[[viewTester usingLabel:@"Button"] waitForView];
}
- (void)testEnteringTextIntoATextFieldInATableCell
{
[[viewTester usingLabel:@"TextField"] enterText:inputFieldTestString];
}
@end