Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
bannzai committed Oct 7, 2024
1 parent 45214b6 commit ed4f0b0
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ class AnnouncementBar extends HookConsumerWidget {
if (defaultTargetPlatform == TargetPlatform.iOS) {
final trialDeadlineDate = user.trialDeadlineDate;
if (trialDeadlineDate != null) {
final range = DateRange(trialDeadlineDate.addDays(90), trialDeadlineDate.addDays(93));
if (range.inRange(today())) {
return ShareRewardPremiumTrialAnnoumcenetBar(user: user);
if (user.appliedShareRewardPremiumTrialCount == 0) {
if (today().isAfter(trialDeadlineDate.addDays(90))) {
return ShareRewardPremiumTrialAnnoumcenetBar(user: user);
}
} else {
final range = DateRange(trialDeadlineDate.addDays(90), trialDeadlineDate.addDays(93));
if (range.inRange(today())) {
return ShareRewardPremiumTrialAnnoumcenetBar(user: user);
}
}
}
}
Expand Down
152 changes: 150 additions & 2 deletions test/features/record/announcement_bar/announcement_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,153 @@ void main() {
findsNothing,
);
});
testWidgets('today between trialDeadlineDate.addDays(90 ~ 93)', (WidgetTester tester) async {
testWidgets('today between trialDeadlineDate.addDays(91) and appliedShareRewardPremiumTrialCount is 0', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10).subtract(const Duration(seconds: 1));

when(mockTodayRepository.now()).thenReturn(mockToday);
todayRepository = mockTodayRepository;

var pillSheet = PillSheet.create(
PillSheetType.pillsheet_21,
lastTakenDate: mockToday.subtract(const Duration(days: 1)),
beginDate: mockToday.subtract(
const Duration(days: 25),
),
);
final pillSheetGroup = PillSheetGroup(
pillSheetIDs: ["1"],
pillSheets: [pillSheet],
createdAt: now(),
pillSheetAppearanceMode: PillSheetAppearanceMode.number,
);

SharedPreferences.setMockInitialValues({
IntKey.totalCountOfActionForTakenPill: totalCountOfActionForTakenPillForLongTimeUser,
});
final sharedPreferences = await SharedPreferences.getInstance();
await tester.pumpWidget(
ProviderScope(
overrides: [
appIsReleasedProvider.overrideWith((ref) => true),
latestPillSheetGroupProvider.overrideWith((ref) => Stream.value(pillSheetGroup)),
userProvider.overrideWith(
(ref) => Stream.value(
User(
isPremium: false,
trialDeadlineDate: today().addDays(-91),
beginTrialDate: null,
discountEntitlementDeadlineDate: null,
appliedShareRewardPremiumTrialCount: 0,
),
),
),
isLinkedProvider.overrideWithValue(false),
isJaLocaleProvider.overrideWithValue(true),
pilllAdsProvider.overrideWith(
(ref) => Stream.value(
PilllAds(
description: 'これは広告用のテキスト',
destinationURL: 'https://github.com/bannzai',
endDateTime: DateTime(2022, 8, 23, 23, 59, 59),
startDateTime: DateTime(2022, 8, 10, 0, 0, 0),
hexColor: '#111111',
imageURL: null,
),
),
),
sharedPreferencesProvider.overrideWith((ref) => sharedPreferences),
remoteConfigParameterProvider.overrideWithValue(RemoteConfigParameter()),
applyShareRewardPremiumTrialProvider.overrideWith((ref) => MockApplyShareRewardPremiumTrial())
],
child: const MaterialApp(
home: Material(child: AnnouncementBar()),
),
),
);
await tester.pumpAndSettle(const Duration(milliseconds: 400));

debugDefaultTargetPlatformOverride = null;

expect(
find.byWidgetPredicate((widget) => widget is ShareRewardPremiumTrialAnnoumcenetBar),
findsOneWidget,
);
});
testWidgets('today between trialDeadlineDate.addDays(100) and appliedShareRewardPremiumTrialCount is 0', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10).subtract(const Duration(seconds: 1));

when(mockTodayRepository.now()).thenReturn(mockToday);
todayRepository = mockTodayRepository;

var pillSheet = PillSheet.create(
PillSheetType.pillsheet_21,
lastTakenDate: mockToday.subtract(const Duration(days: 1)),
beginDate: mockToday.subtract(
const Duration(days: 25),
),
);
final pillSheetGroup = PillSheetGroup(
pillSheetIDs: ["1"],
pillSheets: [pillSheet],
createdAt: now(),
pillSheetAppearanceMode: PillSheetAppearanceMode.number,
);

SharedPreferences.setMockInitialValues({
IntKey.totalCountOfActionForTakenPill: totalCountOfActionForTakenPillForLongTimeUser,
});
final sharedPreferences = await SharedPreferences.getInstance();
await tester.pumpWidget(
ProviderScope(
overrides: [
appIsReleasedProvider.overrideWith((ref) => true),
latestPillSheetGroupProvider.overrideWith((ref) => Stream.value(pillSheetGroup)),
userProvider.overrideWith(
(ref) => Stream.value(
User(
isPremium: false,
trialDeadlineDate: today().addDays(-100),
beginTrialDate: null,
discountEntitlementDeadlineDate: null,
appliedShareRewardPremiumTrialCount: 0,
),
),
),
isLinkedProvider.overrideWithValue(false),
isJaLocaleProvider.overrideWithValue(true),
pilllAdsProvider.overrideWith(
(ref) => Stream.value(
PilllAds(
description: 'これは広告用のテキスト',
destinationURL: 'https://github.com/bannzai',
endDateTime: DateTime(2022, 8, 23, 23, 59, 59),
startDateTime: DateTime(2022, 8, 10, 0, 0, 0),
hexColor: '#111111',
imageURL: null,
),
),
),
sharedPreferencesProvider.overrideWith((ref) => sharedPreferences),
remoteConfigParameterProvider.overrideWithValue(RemoteConfigParameter()),
applyShareRewardPremiumTrialProvider.overrideWith((ref) => MockApplyShareRewardPremiumTrial())
],
child: const MaterialApp(
home: Material(child: AnnouncementBar()),
),
),
);
await tester.pumpAndSettle(const Duration(milliseconds: 400));

debugDefaultTargetPlatformOverride = null;

expect(
find.byWidgetPredicate((widget) => widget is ShareRewardPremiumTrialAnnoumcenetBar),
findsOneWidget,
);
});
testWidgets('today between trialDeadlineDate.addDays(90 ~ 93) and appliedShareRewardPremiumTrialCount is 1', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10).subtract(const Duration(seconds: 1));

Expand Down Expand Up @@ -886,6 +1032,7 @@ void main() {
trialDeadlineDate: today().addDays(-90),
beginTrialDate: null,
discountEntitlementDeadlineDate: null,
appliedShareRewardPremiumTrialCount: 1,
),
),
),
Expand Down Expand Up @@ -921,7 +1068,8 @@ void main() {
findsOneWidget,
);
});
testWidgets('today is not between trialDeadlineDate.addDays(90 ~ 93)', (WidgetTester tester) async {
testWidgets('today is not between trialDeadlineDate.addDays(90 ~ 93) and appliedShareRewardPremiumTrialCount is 1',
(WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10);

Expand Down

0 comments on commit ed4f0b0

Please sign in to comment.