Unverified Commit 67a68e9f authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tools] Fix analytics opt out event (#48585)

parent c90b1182
......@@ -115,8 +115,10 @@ class ConfigCommand extends FlutterCommand {
if (argResults.wasParsed('analytics')) {
final bool value = boolArg('analytics');
flutterUsage.enabled = value;
// We send the analytics event *before* toggling the flag intentionally
// to be sure that opt-out events are sent correctly.
AnalyticsConfigEvent(enabled: value).send();
flutterUsage.enabled = value;
globals.printStatus('Analytics reporting ${value ? 'enabled' : 'disabled'}.');
}
......
......@@ -200,6 +200,18 @@ void main() {
final ConfigCommand configCommand = ConfigCommand();
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
when(mockUsage.sendEvent(
captureAny,
captureAny,
label: captureAnyNamed('label'),
value: anyNamed('value'),
parameters: anyNamed('parameters'),
)).thenAnswer((Invocation invocation) async {
expect(mockUsage.enabled, true);
expect(invocation.positionalArguments, <String>['analytics', 'enabled']);
expect(invocation.namedArguments[#label], 'false');
});
await commandRunner.run(<String>[
'config',
'--no-analytics',
......@@ -219,16 +231,6 @@ void main() {
any,
label: anyNamed('label'),
));
expect(verify(mockUsage.sendEvent(
captureAny,
captureAny,
label: captureAnyNamed('label'),
value: anyNamed('value'),
parameters: anyNamed('parameters'),
)).captured,
<dynamic>['analytics', 'enabled', 'false'],
);
}, overrides: <Type, Generator>{
Usage: () => mockUsage,
});
......
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