diff --git a/lib/features/record/components/announcement_bar/announcement_bar.dart b/lib/features/record/components/announcement_bar/announcement_bar.dart index 1e3f403378..1c592319b4 100644 --- a/lib/features/record/components/announcement_bar/announcement_bar.dart +++ b/lib/features/record/components/announcement_bar/announcement_bar.dart @@ -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); + } } } } diff --git a/test/features/record/announcement_bar/announcement_bar_test.dart b/test/features/record/announcement_bar/announcement_bar_test.dart index aa10adcf88..7cbec2f388 100644 --- a/test/features/record/announcement_bar/announcement_bar_test.dart +++ b/test/features/record/announcement_bar/announcement_bar_test.dart @@ -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)); @@ -886,6 +1032,7 @@ void main() { trialDeadlineDate: today().addDays(-90), beginTrialDate: null, discountEntitlementDeadlineDate: null, + appliedShareRewardPremiumTrialCount: 1, ), ), ), @@ -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);