Unverified Commit 9e1b4b22 authored by Dan Field's avatar Dan Field Committed by GitHub

tests for about page (#35290)

parent 9c31f9f4
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart' show visibleForTesting;
/// Signature for callbacks passed to [LicenseRegistry.addLicense]. /// Signature for callbacks passed to [LicenseRegistry.addLicense].
typedef LicenseEntryCollector = Stream<LicenseEntry> Function(); typedef LicenseEntryCollector = Stream<LicenseEntry> Function();
...@@ -306,4 +308,11 @@ class LicenseRegistry { ...@@ -306,4 +308,11 @@ class LicenseRegistry {
for (LicenseEntryCollector collector in _collectors) for (LicenseEntryCollector collector in _collectors)
yield* collector(); yield* collector();
} }
/// Resets the internal state of [LicenseRegistry]. Intended for use in
/// testing.
@visibleForTesting
static void reset() {
_collectors = null;
}
} }
...@@ -9,6 +9,10 @@ import 'package:flutter/material.dart'; ...@@ -9,6 +9,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
tearDown(() {
LicenseRegistry.reset();
});
testWidgets('AboutListTile control test', (WidgetTester tester) async { testWidgets('AboutListTile control test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -131,6 +135,72 @@ void main() { ...@@ -131,6 +135,72 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(tester.getTopLeft(find.text('DEF')), const Offset(8.0 + safeareaPadding, 527.0)); expect(tester.getTopLeft(find.text('DEF')), const Offset(8.0 + safeareaPadding, 287.0));
}, skip: isBrowser);
testWidgets('LicensePage returns early if unmounted', (WidgetTester tester) async {
final Completer<LicenseEntry> licenseCompleter = Completer<LicenseEntry>();
LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromFuture(licenseCompleter.future);
});
await tester.pumpWidget(
const MaterialApp(
home: LicensePage(),
),
);
await tester.pump();
await tester.pumpWidget(
const MaterialApp(
home: Placeholder(),
),
);
await tester.pumpAndSettle();
final FakeLicenseEntry licenseEntry = FakeLicenseEntry();
licenseCompleter.complete(licenseEntry);
expect(licenseEntry.paragraphsCalled, false);
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('LicensePage returns late if unmounted', (WidgetTester tester) async {
final Completer<LicenseEntry> licenseCompleter = Completer<LicenseEntry>();
LicenseRegistry.addLicense(() {
return Stream<LicenseEntry>.fromFuture(licenseCompleter.future);
});
await tester.pumpWidget(
const MaterialApp(
home: LicensePage(),
),
);
await tester.pump();
final FakeLicenseEntry licenseEntry = FakeLicenseEntry();
licenseCompleter.complete(licenseEntry);
await tester.pumpWidget(
const MaterialApp(
home: Placeholder(),
),
);
await tester.pumpAndSettle();
expect(licenseEntry.paragraphsCalled, true);
}, skip: isBrowser);
}
class FakeLicenseEntry extends LicenseEntry {
FakeLicenseEntry();
bool get paragraphsCalled => _paragraphsCalled;
bool _paragraphsCalled = false;
@override
Iterable<String> packages = <String>[];
@override
Iterable<LicenseParagraph> get paragraphs {
_paragraphsCalled = true;
return <LicenseParagraph>[];
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment