Files
cutdex/packages/cutdex_ui/test/popup_storage_isolation_test.dart
T
lingjhf abc1868550
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
2026-10-08 18:17:12 +00:00

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());
});
}
}
}