Unverified Commit 3c0f3f4e authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Add boxes around version freshness alerts (#96152)

parent 5d5958f3
...@@ -879,7 +879,7 @@ class VersionFreshnessValidator { ...@@ -879,7 +879,7 @@ class VersionFreshnessValidator {
final String updateMessage; final String updateMessage;
switch (remoteVersionStatus) { switch (remoteVersionStatus) {
case VersionCheckResult.newVersionAvailable: case VersionCheckResult.newVersionAvailable:
updateMessage = newVersionAvailableMessage(); updateMessage = _newVersionAvailableMessage;
break; break;
case VersionCheckResult.versionIsCurrent: case VersionCheckResult.versionIsCurrent:
case VersionCheckResult.unknown: case VersionCheckResult.unknown:
...@@ -887,7 +887,7 @@ class VersionFreshnessValidator { ...@@ -887,7 +887,7 @@ class VersionFreshnessValidator {
break; break;
} }
logger.printStatus(updateMessage, emphasis: true); logger.printBox(updateMessage);
await Future.wait<void>(<Future<void>>[ await Future.wait<void>(<Future<void>>[
stamp.store( stamp.store(
newTimeWarningWasPrinted: now, newTimeWarningWasPrinted: now,
...@@ -900,26 +900,13 @@ class VersionFreshnessValidator { ...@@ -900,26 +900,13 @@ class VersionFreshnessValidator {
@visibleForTesting @visibleForTesting
String versionOutOfDateMessage(Duration frameworkAge) { String versionOutOfDateMessage(Duration frameworkAge) {
String warning = 'WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.';
// Append enough spaces to match the message box width.
warning += ' ' * (74 - warning.length);
return ''' return '''
╔════════════════════════════════════════════════════════════════════════════╗ WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.
$warning
║ ║
║ To update to the latest version, run "flutter upgrade". ║
╚════════════════════════════════════════════════════════════════════════════╝
''';
}
@visibleForTesting To update to the latest version, run "flutter upgrade".''';
String newVersionAvailableMessage() {
return '''
╔════════════════════════════════════════════════════════════════════════════╗
║ A new version of Flutter is available! ║
║ ║
║ To update to the latest version, run "flutter upgrade". ║
╚════════════════════════════════════════════════════════════════════════════╝
''';
} }
const String _newVersionAvailableMessage = '''
A new version of Flutter is available!
To update to the latest version, run "flutter upgrade".''';
...@@ -134,7 +134,7 @@ void main() { ...@@ -134,7 +134,7 @@ void main() {
expect(flutterVersion.getVersionString(redactUnknownBranches: true), '$channel/1234abcd'); expect(flutterVersion.getVersionString(redactUnknownBranches: true), '$channel/1234abcd');
expect(flutterVersion.getBranchName(redactUnknownBranches: true), channel); expect(flutterVersion.getBranchName(redactUnknownBranches: true), channel);
_expectVersionMessage('', testLogger); expect(testLogger.statusText, isEmpty);
expect(processManager.hasRemainingExpectations, isFalse); expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(clock: _testClock), FlutterVersion: () => FlutterVersion(clock: _testClock),
...@@ -160,7 +160,7 @@ void main() { ...@@ -160,7 +160,7 @@ void main() {
latestFlutterCommitDate: getChannelOutOfDateVersion(), latestFlutterCommitDate: getChannelOutOfDateVersion(),
).run(); ).run();
_expectVersionMessage('', logger); expect(logger.statusText, isEmpty);
}); });
testWithoutContext('does not ping server when version stamp is up-to-date', () async { testWithoutContext('does not ping server when version stamp is up-to-date', () async {
...@@ -181,7 +181,7 @@ void main() { ...@@ -181,7 +181,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(), latestFlutterCommitDate: getChannelUpToDateVersion(),
).run(); ).run();
_expectVersionMessage(newVersionAvailableMessage(), logger); expect(logger.statusText, contains('A new version of Flutter is available!'));
expect(cache.setVersionStamp, true); expect(cache.setVersionStamp, true);
}); });
...@@ -204,7 +204,7 @@ void main() { ...@@ -204,7 +204,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(), latestFlutterCommitDate: getChannelUpToDateVersion(),
).run(); ).run();
_expectVersionMessage('', logger); expect(logger.statusText, isEmpty);
}); });
testWithoutContext('pings server when version stamp is missing', () async { testWithoutContext('pings server when version stamp is missing', () async {
...@@ -221,7 +221,7 @@ void main() { ...@@ -221,7 +221,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(), latestFlutterCommitDate: getChannelUpToDateVersion(),
).run(); ).run();
_expectVersionMessage(newVersionAvailableMessage(), logger); expect(logger.statusText, contains('A new version of Flutter is available!'));
expect(cache.setVersionStamp, true); expect(cache.setVersionStamp, true);
}); });
...@@ -243,7 +243,7 @@ void main() { ...@@ -243,7 +243,7 @@ void main() {
latestFlutterCommitDate: getChannelUpToDateVersion(), latestFlutterCommitDate: getChannelUpToDateVersion(),
).run(); ).run();
_expectVersionMessage(newVersionAvailableMessage(), logger); expect(logger.statusText, contains('A new version of Flutter is available!'));
}); });
testWithoutContext('does not print warning when unable to connect to server if not out of date', () async { testWithoutContext('does not print warning when unable to connect to server if not out of date', () async {
...@@ -260,7 +260,7 @@ void main() { ...@@ -260,7 +260,7 @@ void main() {
// latestFlutterCommitDate defaults to null because we failed to get remote version // latestFlutterCommitDate defaults to null because we failed to get remote version
).run(); ).run();
_expectVersionMessage('', logger); expect(logger.statusText, isEmpty);
}); });
testWithoutContext('prints warning when unable to connect to server if really out of date', () async { testWithoutContext('prints warning when unable to connect to server if really out of date', () async {
...@@ -281,7 +281,8 @@ void main() { ...@@ -281,7 +281,8 @@ void main() {
// latestFlutterCommitDate defaults to null because we failed to get remote version // latestFlutterCommitDate defaults to null because we failed to get remote version
).run(); ).run();
_expectVersionMessage(versionOutOfDateMessage(_testClock.now().difference(getChannelOutOfDateVersion())), logger); final Duration frameworkAge = _testClock.now().difference(getChannelOutOfDateVersion());
expect(logger.statusText, contains('WARNING: your installation of Flutter is ${frameworkAge.inDays} days old.'));
}); });
group('$VersionCheckStamp for $channel', () { group('$VersionCheckStamp for $channel', () {
...@@ -593,11 +594,6 @@ void main() { ...@@ -593,11 +594,6 @@ void main() {
}); });
} }
void _expectVersionMessage(String message, BufferLogger logger) {
expect(logger.statusText.trim(), message.trim());
logger.clear();
}
class FakeCache extends Fake implements Cache { class FakeCache extends Fake implements Cache {
String versionStamp; String versionStamp;
bool setVersionStamp = false; bool setVersionStamp = false;
......
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