Unverified Commit 757b5365 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add missing test case for Usage (#36379)

parent 1957c663
......@@ -3,7 +3,9 @@
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/base/file_system.dart';
......@@ -22,6 +24,7 @@ import '../src/context.dart';
void main() {
group('analytics', () {
Directory tempDir;
MockFlutterConfig mockFlutterConfig;
setUpAll(() {
Cache.disableLocking();
......@@ -30,6 +33,7 @@ void main() {
setUp(() {
Cache.flutterRoot = '../..';
tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_analytics_test.');
mockFlutterConfig = MockFlutterConfig();
});
tearDown(() {
......@@ -78,6 +82,44 @@ void main() {
FlutterVersion: () => FlutterVersion(const SystemClock()),
Usage: () => Usage(configDirOverride: tempDir.path),
});
testUsingContext('Usage records one feature in experiment setting', () async {
when<bool>(mockFlutterConfig.getValue(flutterWebFeature.configSetting))
.thenReturn(true);
final Usage usage = Usage();
usage.suppressAnalytics = false;
usage.enabled = true;
final Future<Map<String, dynamic>> data = usage.onSend.first;
usage.sendCommand('test');
expect(await data, containsPair(enabledFlutterFeatures, 'enable-web'));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
Usage: () => Usage(configDirOverride: tempDir.path),
Config: () => mockFlutterConfig,
});
testUsingContext('Usage records multiple features in experiment setting', () async {
when<bool>(mockFlutterConfig.getValue(flutterWebFeature.configSetting))
.thenReturn(true);
when<bool>(mockFlutterConfig.getValue(flutterLinuxDesktopFeature.configSetting))
.thenReturn(true);
when<bool>(mockFlutterConfig.getValue(flutterMacOSDesktopFeature.configSetting))
.thenReturn(true);
final Usage usage = Usage();
usage.suppressAnalytics = false;
usage.enabled = true;
final Future<Map<String, dynamic>> data = usage.onSend.first;
usage.sendCommand('test');
expect(await data, containsPair(enabledFlutterFeatures, 'enable-web,enable-linux-desktop,enable-macos-desktop'));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
Usage: () => Usage(configDirOverride: tempDir.path),
Config: () => mockFlutterConfig,
});
});
group('analytics with mocks', () {
......@@ -195,3 +237,5 @@ void main() {
class MockUsage extends Mock implements Usage {}
class MockDoctor extends Mock implements Doctor {}
class MockFlutterConfig extends Mock implements Config {}
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