Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/devtools_app/lib/src/shared/managers/survey.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:convert';

import 'package:clock/clock.dart';
import 'package:devtools_shared/devtools_shared.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart';
Expand Down Expand Up @@ -243,7 +242,7 @@ extension ShowSurveyExtension on DevToolsSurvey {
: Range(
startDate!.millisecondsSinceEpoch,
endDate!.millisecondsSinceEpoch,
).contains(clock.now().millisecondsSinceEpoch);
).contains(_currentClockTime().millisecondsSinceEpoch);

bool get meetsMinVersionRequirement =>
minDevToolsVersion == null ||
Expand All @@ -252,10 +251,18 @@ extension ShowSurveyExtension on DevToolsSurvey {
).isSupported(minSupportedVersion: minDevToolsVersion!);

bool get meetsEnvironmentRequirement =>
devEnvironments == null || devEnvironments!.contains(ga.ideLaunched);
devEnvironments == null ||
ga.ideLaunched.isEmpty ||
devEnvironments!.contains(ga.ideLaunched);

bool get shouldShow =>
meetsDateRequirement &&
meetsMinVersionRequirement &&
meetsEnvironmentRequirement;
}

DateTime _currentClockTime() => fakeClockTimeForSurvey ?? DateTime.now();

/// A hook to set a fake clock time for tests.
@visibleForTesting
DateTime? fakeClockTimeForSurvey;
1 change: 0 additions & 1 deletion packages/devtools_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ resolution: workspace

dependencies:
async: ^2.0.0
clock: ^1.1.1
collection: ^1.15.0
dap: ^1.1.0
dds_service_extensions: ^2.0.0
Expand Down
33 changes: 17 additions & 16 deletions packages/devtools_app/test/shared/managers/survey_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:clock/clock.dart';
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/shared/managers/survey.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
setUp(() {
fakeClockTimeForSurvey = null;
});

group('SurveyService', () {
test('can fetch survey metadata', () async {
final survey = await SurveyService().fetchSurveyContent();
Expand Down Expand Up @@ -59,12 +62,12 @@ void main() {
test('empty survey', () {
final emptySurvey = DevToolsSurvey.fromJson({});

withClock(Clock.fixed(DateTime(2023, 11, 7)), () {
expect(emptySurvey.meetsDateRequirement, isFalse);
});
withClock(Clock.fixed(DateTime(2023, 11, 15)), () {
expect(emptySurvey.meetsDateRequirement, isFalse);
});
fakeClockTimeForSurvey = DateTime(2023, 11, 7);
expect(emptySurvey.meetsDateRequirement, isFalse);

fakeClockTimeForSurvey = DateTime(2023, 11, 15);
expect(emptySurvey.meetsDateRequirement, isFalse);

expect(emptySurvey.meetsMinVersionRequirement, isTrue);
expect(emptySurvey.meetsEnvironmentRequirement, isTrue);
expect(emptySurvey.shouldShow, isFalse);
Expand All @@ -87,9 +90,8 @@ void main() {
});

ideLaunched = 'VSCode';
withClock(Clock.fixed(DateTime(2023, 11, 7)), () {
expect(survey.shouldShow, isTrue);
});
fakeClockTimeForSurvey = DateTime(2023, 11, 7);
expect(survey.shouldShow, isTrue);
});

test('meetsDateRequirement', () {
Expand All @@ -98,12 +100,11 @@ void main() {
'endDate': '2023-11-14T09:00:00-07:00',
});

withClock(Clock.fixed(DateTime(2023, 11, 7)), () {
expect(survey.meetsDateRequirement, isTrue);
});
withClock(Clock.fixed(DateTime(2023, 11, 15)), () {
expect(survey.meetsDateRequirement, isFalse);
});
fakeClockTimeForSurvey = DateTime(2023, 11, 7);
expect(survey.meetsDateRequirement, isTrue);

fakeClockTimeForSurvey = DateTime(2023, 11, 15);
expect(survey.meetsDateRequirement, isFalse);
});

test('meetsMinVersionRequirement', () {
Expand Down
Loading