forked from macosui/macos_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresizeable_pane_test.dart
155 lines (129 loc) · 4.89 KB
/
resizeable_pane_test.dart
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
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:macos_ui/macos_ui.dart';
void main() {
const matrix = ResizableSide.values;
group('ResizablePane', () {
for (var side in matrix) {
group(side == ResizableSide.left ? "left" : "right", () {
const double maxWidth = 300;
const double minWidth = 100;
const double startWidth = 200;
final resizablePane = ResizablePane(
builder: (context, scrollController) => const Text('Hello there'),
minWidth: minWidth,
startWidth: startWidth,
maxWidth: maxWidth,
resizableSide: side,
);
final view = MacosApp(
home: MacosWindow(
child: MacosScaffold(
children: [
resizablePane,
ContentArea(
builder: (context, scrollController) =>
const Text('Hello there'),
),
],
),
),
);
final resizablePaneFinder = find.byWidget(resizablePane);
final dragFinder = find.descendant(
of: resizablePaneFinder,
matching: find.byType(GestureDetector),
);
final directionModifier = side == ResizableSide.right ? 1 : -1;
final double safeDelta = 50.0 * directionModifier;
final double overflowDelta = 500.0 * directionModifier;
testWidgets('initial width equals startWidth', (tester) async {
await tester.pumpWidget(view);
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(resizablePaneRenderObject.size.width, startWidth);
});
testWidgets('dragging wider works', (tester) async {
await tester.pumpWidget(view);
await tester.drag(
dragFinder,
Offset(safeDelta, 0),
);
await tester.pump();
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(
resizablePaneRenderObject.size.width,
startWidth + safeDelta * directionModifier,
);
});
testWidgets('dragging wider respects maxWidth', (tester) async {
await tester.pumpWidget(view);
await tester.drag(
dragFinder,
Offset(overflowDelta, 0),
);
await tester.pump();
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(resizablePaneRenderObject.size.width, maxWidth);
});
testWidgets(
'drag events past maxWidth have no effect',
(tester) async {
await tester.pumpWidget(view);
final dragStartLocation = tester.getCenter(dragFinder);
final drag = await tester.startGesture(dragStartLocation);
await drag.moveBy(Offset(overflowDelta, 0));
await drag.moveBy(Offset(-10.0 * directionModifier, 0));
await drag.up();
await tester.pump();
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(resizablePaneRenderObject.size.width, maxWidth);
},
);
testWidgets('dragging narrower works', (tester) async {
await tester.pumpWidget(view);
await tester.drag(
dragFinder,
Offset(-safeDelta, 0),
);
await tester.pump();
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(
resizablePaneRenderObject.size.width,
startWidth - safeDelta * directionModifier,
);
});
testWidgets('dragging narrower respects minWidth', (tester) async {
await tester.pumpWidget(view);
await tester.drag(
dragFinder,
Offset(-overflowDelta, 0),
);
await tester.pump();
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(resizablePaneRenderObject.size.width, minWidth);
});
testWidgets(
'drag events past minWidth have no effect',
(tester) async {
await tester.pumpWidget(view);
final dragStartLocation = tester.getCenter(dragFinder);
final drag = await tester.startGesture(dragStartLocation);
await drag.moveBy(Offset(-overflowDelta, 0));
await drag.moveBy(Offset(10.0 * directionModifier, 0));
await drag.up();
await tester.pump();
var resizablePaneRenderObject =
tester.renderObject<RenderBox>(resizablePaneFinder);
expect(resizablePaneRenderObject.size.width, minWidth);
},
);
});
}
});
}