Visitar URL original
Add iOS drag integration coverage · flutter/flutter@a6bb2aa · GitHub
Skip to content

Commit a6bb2aa

Browse files
committed
Add iOS drag integration coverage
Add a deterministic reorder target and native UI test for exercising drag interactions in the iOS platform-view integration app.
1 parent 34c5993 commit a6bb2aa

3 files changed

Lines changed: 150 additions & 0 deletions

File tree

‎dev/integration_tests/ios_platform_view_tests/ios/PlatformViewUITests/PlatformViewUITests.m‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,41 @@ - (void)testReorderableListAccessibilityHierarchyUpdates {
136136
NSStringFromCGRect(item2FrameAfterReorder), self.app.debugDescription);
137137
}
138138

139+
- (void)testDragScreen {
140+
XCUIElement *entranceButton = self.app.buttons[@"drag test"];
141+
XCTAssertTrue([entranceButton waitForExistenceWithTimeout:kStandardTimeOut],
142+
@"The element tree is %@", self.app.debugDescription);
143+
[entranceButton tap];
144+
145+
XCUIElement *item3 = self.app.staticTexts[@"Item 3"];
146+
XCUIElement *item1 = self.app.staticTexts[@"Item 1"];
147+
XCTAssertTrue([item3 waitForExistenceWithTimeout:kStandardTimeOut],
148+
@"The element tree is %@", self.app.debugDescription);
149+
XCTAssertTrue([item1 waitForExistenceWithTimeout:kStandardTimeOut],
150+
@"The element tree is %@", self.app.debugDescription);
151+
152+
XCUICoordinate *dragStart =
153+
[item3 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
154+
XCUICoordinate *dragEnd =
155+
[item1 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
156+
[dragStart pressForDuration:1.0 thenDragToCoordinate:dragEnd];
157+
158+
XCUIElement *item2 = self.app.staticTexts[@"Item 2"];
159+
XCUIElement *item5 = self.app.staticTexts[@"Item 5"];
160+
XCTAssertTrue([item2 waitForExistenceWithTimeout:kStandardTimeOut],
161+
@"The element tree is %@", self.app.debugDescription);
162+
XCTAssertTrue([item5 waitForExistenceWithTimeout:kStandardTimeOut],
163+
@"The element tree is %@", self.app.debugDescription);
164+
165+
dragStart = [item2 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
166+
dragEnd = [item5 coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.9)];
167+
[dragStart pressForDuration:1.0 thenDragToCoordinate:dragEnd];
168+
169+
XCUIElement *success = self.app.staticTexts[@"Drag Success"];
170+
XCTAssertTrue([success waitForExistenceWithTimeout:kStandardTimeOut],
171+
@"The element tree is %@", self.app.debugDescription);
172+
}
173+
139174
- (void)testPlatformViewZOrder {
140175
XCUIElement *entranceButton = self.app.buttons[@"platform view z order test"];
141176
XCTAssertTrue([entranceButton waitForExistenceWithTimeout:kStandardTimeOut], @"The element tree is %@", self.app.debugDescription);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/foundation.dart';
6+
import 'package:flutter/material.dart';
7+
8+
class DragScreen extends StatefulWidget {
9+
const DragScreen({super.key});
10+
11+
@override
12+
State<DragScreen> createState() => _DragScreenState();
13+
}
14+
15+
class _DragScreenState extends State<DragScreen> {
16+
List<int> items = <int>[1, 2, 3, 4, 5];
17+
18+
// Target order for Maestro drag-and-drop test validation.
19+
static const List<int> targetOrder = <int>[3, 1, 4, 5, 2];
20+
21+
bool get isCorrectOrder => listEquals(items, targetOrder);
22+
23+
void _onReorder(int oldIndex, int newIndex) {
24+
setState(() {
25+
if (newIndex > oldIndex) {
26+
newIndex -= 1;
27+
}
28+
final int item = items.removeAt(oldIndex);
29+
items.insert(newIndex, item);
30+
});
31+
}
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
return Scaffold(
36+
appBar: AppBar(
37+
title: const Text('Drag Test'),
38+
leading: IconButton(
39+
icon: const Icon(Icons.arrow_back),
40+
onPressed: () => Navigator.of(context).pop(),
41+
),
42+
),
43+
body: Column(
44+
children: <Widget>[
45+
Padding(
46+
padding: const EdgeInsets.all(16.0),
47+
child: Text(
48+
'Reorder items to: ${targetOrder.join(", ")}',
49+
style: Theme.of(context).textTheme.titleMedium,
50+
),
51+
),
52+
Padding(
53+
padding: const EdgeInsets.symmetric(horizontal: 16.0),
54+
child: Text(
55+
'Current order: ${items.join(", ")}',
56+
style: Theme.of(context).textTheme.bodyMedium,
57+
),
58+
),
59+
const SizedBox(height: 16),
60+
Expanded(
61+
child: ReorderableListView.builder(
62+
itemCount: items.length,
63+
onReorderItem: _onReorder,
64+
buildDefaultDragHandles: false,
65+
proxyDecorator: (Widget child, int index, Animation<double> animation) {
66+
return Material(elevation: 4, color: Colors.transparent, child: child);
67+
},
68+
itemBuilder: (BuildContext context, int index) {
69+
final int item = items[index];
70+
return ReorderableDragStartListener(
71+
key: ValueKey<int>(item),
72+
index: index,
73+
child: Container(
74+
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
75+
child: ListTile(
76+
leading: const Icon(Icons.drag_handle),
77+
title: Text(
78+
'Item $item',
79+
style: const TextStyle(fontSize: 18),
80+
semanticsLabel: 'Item $item',
81+
),
82+
),
83+
),
84+
);
85+
},
86+
),
87+
),
88+
if (isCorrectOrder)
89+
Container(
90+
padding: const EdgeInsets.all(24),
91+
color: Colors.green,
92+
width: double.infinity,
93+
child: const Text(
94+
'Drag Success',
95+
textAlign: TextAlign.center,
96+
style: TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold),
97+
),
98+
),
99+
],
100+
),
101+
);
102+
}
103+
}

‎dev/integration_tests/ios_platform_view_tests/lib/main.dart‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
77
import 'package:flutter_driver/driver_extension.dart';
88

9+
import 'drag.dart';
910
import 'reorderable_list_semantics.dart';
1011

1112
void main() {
@@ -140,6 +141,17 @@ class _MyHomePageState extends State<MyHomePage> {
140141
);
141142
},
142143
),
144+
TextButton(
145+
child: const Text('drag test'),
146+
onPressed: () {
147+
Navigator.push(
148+
context,
149+
MaterialPageRoute<DragScreen>(
150+
builder: (BuildContext context) => const DragScreen(),
151+
),
152+
);
153+
},
154+
),
143155
],
144156
),
145157
);

0 commit comments

Comments
 (0)