Organize settings into retained topic tabs
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_tabs.dart';
|
||||
import 'settings_topic_test_helper.dart';
|
||||
|
||||
class _Page extends StatefulWidget {
|
||||
const _Page({required this.name, required this.onMount});
|
||||
final String name;
|
||||
final VoidCallback onMount;
|
||||
@override
|
||||
State<_Page> createState() => _PageState();
|
||||
}
|
||||
|
||||
class _PageState extends State<_Page> {
|
||||
final text = TextEditingController();
|
||||
final scroll = ScrollController();
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.onMount();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
text.dispose();
|
||||
scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SingleChildScrollView(
|
||||
controller: scroll,
|
||||
child: Column(
|
||||
children: [
|
||||
CupertinoTextField(controller: text),
|
||||
for (var i = 0; i < 80; i++) Text('${widget.name} item $i'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('lazy topic pages retain draft and scroll ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
final mounts = <SettingsTopic, int>{};
|
||||
final tabs = SettingsTopicTabs(
|
||||
pages: {
|
||||
for (final topic in SettingsTopic.values)
|
||||
topic: (_) => _Page(
|
||||
name: topic.name,
|
||||
onMount: () =>
|
||||
mounts.update(topic, (count) => count + 1, ifAbsent: () => 1),
|
||||
),
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: tabs))
|
||||
: MaterialApp(home: Scaffold(body: tabs)),
|
||||
);
|
||||
expect(mounts, {SettingsTopic.appearance: 1});
|
||||
final appearance = tester.state<_PageState>(find.byType(_Page));
|
||||
appearance.text.text = 'Keep this draft';
|
||||
appearance.scroll.jumpTo(150);
|
||||
await tester.pump();
|
||||
await selectSettingsTopic(tester, 'Connection');
|
||||
expect(mounts, {
|
||||
SettingsTopic.appearance: 1,
|
||||
SettingsTopic.connection: 1,
|
||||
});
|
||||
final connection = tester.state<_PageState>(find.byType(_Page));
|
||||
connection.text.text = 'Unsubmitted server';
|
||||
connection.scroll.jumpTo(280);
|
||||
await selectSettingsTopic(tester, 'Appearance');
|
||||
expect(tester.state(find.byType(_Page)), same(appearance));
|
||||
expect(appearance.text.text, 'Keep this draft');
|
||||
expect(appearance.scroll.offset, 150);
|
||||
await selectSettingsTopic(tester, 'Connection');
|
||||
expect(tester.state(find.byType(_Page)), same(connection));
|
||||
expect(connection.text.text, 'Unsubmitted server');
|
||||
expect(connection.scroll.offset, 280);
|
||||
expect(mounts.values, everyElement(1));
|
||||
});
|
||||
|
||||
testWidgets('all topics reachable at narrow large text ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final tabs = SettingsTopicTabs(
|
||||
pages: {
|
||||
for (final topic in SettingsTopic.values)
|
||||
topic: (_) => Text('${topic.label} content'),
|
||||
},
|
||||
);
|
||||
Widget scale(BuildContext context, Widget? child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(2)),
|
||||
child: child!,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
builder: scale,
|
||||
home: CupertinoPageScaffold(child: tabs),
|
||||
)
|
||||
: MaterialApp(
|
||||
builder: scale,
|
||||
home: Scaffold(body: tabs),
|
||||
),
|
||||
);
|
||||
for (final topic in SettingsTopic.values) {
|
||||
await selectSettingsTopic(tester, topic.label);
|
||||
expect(find.text('${topic.label} content'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user