Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
130 lines
4.1 KiB
Dart
130 lines
4.1 KiB
Dart
import 'package:cutdex_ui/theme.dart';
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
for (final kind in ['searchable', 'popover', 'context']) {
|
|
for (final stored in <Object>[true, 120.0]) {
|
|
testWidgets('$kind popup isolates ancestor state $stored', (
|
|
tester,
|
|
) async {
|
|
final bucket = PageStorageBucket();
|
|
const ancestorKey = PageStorageKey('parent-state');
|
|
Widget popup() => switch (kind) {
|
|
'searchable' => AppSelect<int>(
|
|
value: 0,
|
|
label: 'Select',
|
|
emptyLabel: 'Empty',
|
|
searchable: true,
|
|
searchHint: 'Search',
|
|
onChanged: (_) {},
|
|
options: [
|
|
for (var i = 0; i < 40; i++) AppSelectOption(i, 'Choice $i'),
|
|
],
|
|
),
|
|
'popover' => AppPopover(
|
|
builder: (_, toggle) => TextButton(
|
|
key: const Key('trigger'),
|
|
onPressed: toggle,
|
|
child: const Text('Open'),
|
|
),
|
|
child: SizedBox(
|
|
height: 150,
|
|
child: ListView(
|
|
primary: false,
|
|
children: [
|
|
for (var i = 0; i < 40; i++)
|
|
SizedBox(height: 32, child: Text('Choice $i')),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
_ => AppContextMenu(
|
|
itemsBuilder: (_) => [
|
|
for (var i = 0; i < 40; i++)
|
|
AppMenuItem(label: 'Choice $i', onPressed: () {}),
|
|
],
|
|
child: const SizedBox(
|
|
key: Key('trigger'),
|
|
width: 200,
|
|
height: 100,
|
|
child: ColoredBox(color: Colors.transparent),
|
|
),
|
|
),
|
|
};
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: AppTheme.penDark,
|
|
home: Scaffold(
|
|
body: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 240,
|
|
child: PageStorage(
|
|
bucket: bucket,
|
|
child: Builder(
|
|
key: ancestorKey,
|
|
builder: (context) {
|
|
bucket.writeState(context, stored);
|
|
return popup();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(
|
|
kind == 'searchable'
|
|
? find.byType(TextField)
|
|
: find.byKey(const Key('trigger')),
|
|
buttons: kind == 'context'
|
|
? kSecondaryMouseButton
|
|
: kPrimaryMouseButton,
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
final positions = tester
|
|
.stateList<ScrollableState>(
|
|
find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget is Scrollable &&
|
|
axisDirectionToAxis(widget.axisDirection) == Axis.vertical,
|
|
),
|
|
)
|
|
.map((state) => state.position)
|
|
.toList();
|
|
expect(positions, isNotEmpty);
|
|
for (final position in positions) {
|
|
expect(
|
|
position.pixels,
|
|
0,
|
|
reason: 'Popup must not restore its parent offset',
|
|
);
|
|
}
|
|
positions
|
|
.firstWhere((position) => position.maxScrollExtent > 50)
|
|
.jumpTo(25);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
bucket.readState(tester.element(find.byKey(ancestorKey))),
|
|
stored,
|
|
);
|
|
await tester.tapAt(const Offset(790, 590));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Choice 3'), findsNothing);
|
|
expect(
|
|
bucket.readState(tester.element(find.byKey(ancestorKey))),
|
|
stored,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
}
|
|
}
|
|
}
|