halkyon/packages/halkyon_app/test/app/about_test.dart

84 lines
2.5 KiB
Dart
Raw Normal View History

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
import 'package:halkyon_app/testing.dart';
import 'package:material_ui/material_ui.dart';
void main() {
late TestAppDependencies dependencies;
setUp(() => dependencies = TestAppDependencies());
/// Opens About from a button, with [version], [legalese] and [children]
/// as the app gives them.
Future<void> open(
WidgetTester tester, {
String? version,
String? legalese,
List<Widget> children = const [],
Locale locale = const Locale('en'),
}) async {
await tester.pumpWidget(
testApp(
Builder(
builder: (context) => TextButton(
onPressed: () => showAppAbout(
context,
version: version,
legalese: legalese,
children: children,
),
child: const Text('About'),
),
),
dependencies: dependencies,
locale: locale,
),
);
await tester.tap(find.text('About'));
await tester.pumpAndSettle();
}
testWidgets('names the app and where the source of what the instance runs '
'is, which both licences require offering', (tester) async {
await open(tester);
expect(find.text('Halkyon Test'), findsWidgets);
expect(find.text('The source of what this instance runs:'), findsOneWidget);
expect(find.text('https://code.example.org/halkyon'), findsOneWidget);
// Flutter's own button to every package's notice.
expect(find.text('View licenses'), findsOneWidget);
});
testWidgets("says so when the instance can't be asked", (tester) async {
dependencies.sourceCodeError = Exception('No connection');
await open(tester);
expect(
find.text("Couldn't reach this instance to ask where its source is."),
findsOneWidget,
);
});
testWidgets("shows the app's version, legalese and own parts where it "
'gives them', (tester) async {
await open(
tester,
version: '0.18.0',
legalese: 'Free software.',
children: const [Text('Data in the app')],
);
expect(find.text('0.18.0'), findsOneWidget);
expect(find.text('Free software.'), findsOneWidget);
expect(find.text('Data in the app'), findsOneWidget);
});
testWidgets('speaks German', (tester) async {
await open(tester, locale: const Locale('de'));
expect(
find.text('Der Quellcode dessen, was diese Instanz ausführt:'),
findsOneWidget,
);
});
}