-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[371] Added the parameter
dialogKey
to UpgraderAlert
that is used…
… by the alert dialog.
- Loading branch information
1 parent
2ee99be
commit 66f3766
Showing
8 changed files
with
268 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2024 Larry Aasen. All rights reserved. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:upgrader/upgrader.dart'; | ||
|
||
final dialogKey = GlobalKey(debugLabel: 'gloabl_upgrader_alert_dialog'); | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
// Only call clearSavedSettings() during testing to reset internal values. | ||
await Upgrader.clearSavedSettings(); // REMOVE this for release builds | ||
|
||
final log = | ||
() => print('$dialogKey mounted=${dialogKey.currentContext?.mounted}'); | ||
unawaited(Future.delayed(Duration(seconds: 0)).then((value) => log())); | ||
unawaited(Future.delayed(Duration(seconds: 3)).then((value) => log())); | ||
unawaited(Future.delayed(Duration(seconds: 4)).then((value) => log())); | ||
|
||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Upgrader Example', | ||
home: UpgradeAlert( | ||
dialogKey: dialogKey, | ||
child: Scaffold( | ||
appBar: AppBar(title: Text('Upgrader Example')), | ||
body: Center(child: Text('Checking...')), | ||
)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2024 Larry Aasen. All rights reserved. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
Widget wrapper(Widget child) { | ||
return MaterialApp( | ||
home: Scaffold( | ||
body: child, | ||
appBar: AppBar(title: const Text('Upgrader test')), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
// Copyright (c) 2024 Larry Aasen. All rights reserved. | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:package_info_plus/package_info_plus.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:upgrader/upgrader.dart'; | ||
|
||
import 'mock_itunes_client.dart'; | ||
import 'test_utils.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
late SharedPreferences preferences; | ||
|
||
setUp(() async { | ||
SharedPreferences.setMockInitialValues({}); | ||
preferences = await SharedPreferences.getInstance(); | ||
}); | ||
|
||
tearDown(() async { | ||
await preferences.clear(); | ||
return true; | ||
}); | ||
testWidgets('test UpgradeCard no update', (WidgetTester tester) async { | ||
expect(Upgrader.sharedInstance.isTooSoon(), false); | ||
|
||
final upgradeCard = wrapper(UpgradeCard()); | ||
await tester.pumpWidget(upgradeCard); | ||
|
||
// Pump the UI | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('IGNORE'), findsNothing); | ||
expect(find.text('LATER'), findsNothing); | ||
expect(find.text('UPDATE'), findsNothing); | ||
expect(find.text('Release Notes'), findsNothing); | ||
}); | ||
|
||
testWidgets('test UpgradeCard upgrade', (WidgetTester tester) async { | ||
final client = MockITunesSearchClient.setupMockClient(); | ||
final upgrader = Upgrader( | ||
upgraderOS: MockUpgraderOS(ios: true), | ||
client: client, | ||
debugLogging: true); | ||
|
||
upgrader.installPackageInfo( | ||
packageInfo: PackageInfo( | ||
appName: 'Upgrader', | ||
packageName: 'com.larryaasen.upgrader', | ||
version: '0.9.9', | ||
buildNumber: '400')); | ||
upgrader.initialize().then((value) {}); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(upgrader.isTooSoon(), false); | ||
|
||
var called = false; | ||
var notCalled = true; | ||
final upgradeCard = wrapper( | ||
UpgradeCard( | ||
upgrader: upgrader, | ||
onUpdate: () { | ||
called = true; | ||
return true; | ||
}, | ||
onIgnore: () { | ||
notCalled = false; | ||
return true; | ||
}, | ||
onLater: () { | ||
notCalled = false; | ||
}, | ||
), | ||
); | ||
await tester.pumpWidget(upgradeCard); | ||
|
||
// Pump the UI so the upgrade card is displayed | ||
await tester.pumpAndSettle(); | ||
|
||
expect(upgrader.messages, isNull); | ||
upgrader.messages = UpgraderMessages(); | ||
expect(upgrader.messages, isNotNull); | ||
|
||
expect(find.text(upgrader.messages!.releaseNotes), findsOneWidget); | ||
expect(find.text(upgrader.releaseNotes!), findsOneWidget); | ||
await tester.tap(find.text(upgrader.messages!.buttonTitleUpdate)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(called, true); | ||
expect(notCalled, true); | ||
expect(find.text(upgrader.messages!.buttonTitleUpdate), findsNothing); | ||
}, skip: false); | ||
|
||
testWidgets('test UpgradeCard ignore', (WidgetTester tester) async { | ||
final client = MockITunesSearchClient.setupMockClient(); | ||
final upgrader = Upgrader( | ||
upgraderOS: MockUpgraderOS(ios: true), | ||
client: client, | ||
debugLogging: true); | ||
|
||
upgrader.installPackageInfo( | ||
packageInfo: PackageInfo( | ||
appName: 'Upgrader', | ||
packageName: 'com.larryaasen.upgrader', | ||
version: '0.9.9', | ||
buildNumber: '400')); | ||
upgrader.initialize().then((value) {}); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(upgrader.isTooSoon(), false); | ||
|
||
var called = false; | ||
var notCalled = true; | ||
final upgradeCard = wrapper( | ||
UpgradeCard( | ||
upgrader: upgrader, | ||
onUpdate: () { | ||
notCalled = false; | ||
return true; | ||
}, | ||
onIgnore: () { | ||
called = true; | ||
return true; | ||
}, | ||
onLater: () { | ||
notCalled = false; | ||
}, | ||
), | ||
); | ||
await tester.pumpWidget(upgradeCard); | ||
|
||
// Pump the UI so the upgrade card is displayed | ||
await tester.pumpAndSettle(); | ||
|
||
expect(upgrader.messages, isNull); | ||
upgrader.messages = UpgraderMessages(); | ||
expect(upgrader.messages, isNotNull); | ||
|
||
await tester.tap(find.text(upgrader.messages!.buttonTitleIgnore)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(called, true); | ||
expect(notCalled, true); | ||
expect(find.text(upgrader.messages!.buttonTitleIgnore), findsNothing); | ||
}, skip: false); | ||
|
||
testWidgets('test UpgradeCard later', (WidgetTester tester) async { | ||
final client = MockITunesSearchClient.setupMockClient(); | ||
final upgrader = Upgrader( | ||
upgraderOS: MockUpgraderOS(ios: true), | ||
client: client, | ||
debugLogging: true); | ||
|
||
upgrader.installPackageInfo( | ||
packageInfo: PackageInfo( | ||
appName: 'Upgrader', | ||
packageName: 'com.larryaasen.upgrader', | ||
version: '0.9.9', | ||
buildNumber: '400')); | ||
upgrader.initialize().then((value) {}); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(upgrader.isTooSoon(), false); | ||
|
||
var called = false; | ||
var notCalled = true; | ||
final upgradeCard = wrapper( | ||
UpgradeCard( | ||
upgrader: upgrader, | ||
onUpdate: () { | ||
notCalled = false; | ||
return true; | ||
}, | ||
onIgnore: () { | ||
notCalled = false; | ||
return true; | ||
}, | ||
onLater: () { | ||
called = true; | ||
}, | ||
), | ||
); | ||
await tester.pumpWidget(upgradeCard); | ||
|
||
// Pump the UI so the upgrade card is displayed | ||
await tester.pumpAndSettle(const Duration(milliseconds: 5000)); | ||
|
||
expect(upgrader.messages, isNull); | ||
upgrader.messages = UpgraderMessages(); | ||
expect(upgrader.messages, isNotNull); | ||
|
||
await tester.tap(find.text(upgrader.messages!.buttonTitleLater)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(called, true); | ||
expect(notCalled, true); | ||
expect(find.text(upgrader.messages!.buttonTitleLater), findsNothing); | ||
}, skip: false); | ||
} |
Oops, something went wrong.