Skip to content

Commit

Permalink
Merge pull request #1079 from bannzai/revert-1078-add/announcement_ba…
Browse files Browse the repository at this point in the history
…r/last_pill_sheet

Revert "Add last pill sheet"
  • Loading branch information
bannzai authored Feb 10, 2024
2 parents 2649749 + dec4dd6 commit c2b3b79
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:pilll/features/record/components/announcement_bar/components/last_pill_sheet.dart';
import 'package:pilll/utils/analytics.dart';
import 'package:pilll/provider/pill_sheet_group.dart';
import 'package:pilll/provider/pilll_ads.dart';
Expand Down Expand Up @@ -72,18 +71,12 @@ class AnnouncementBar extends HookConsumerWidget {
}
}

if (latestPillSheetGroup != null) {
if (latestPillSheetGroup != null && latestPillSheetGroup.activePillSheet == null) {
// ピルシートグループが存在していてactivedPillSheetが無い場合はピルシート終了が何かしらの理由がなくなったと見なし終了表示にする
if (latestPillSheetGroup.activePillSheet == null) {
return EndedPillSheet(
isPremium: user.isPremium,
isTrial: user.isTrial,
);
}
final lastPillSheet = latestPillSheetGroup.pillSheets.lastOrNull;
if (lastPillSheet != null && today().difference(lastPillSheet.estimatedEndTakenDate).inDays.abs() < 10) {
return LastPillSheet(isTrial: user.isTrial, isPremium: user.isPremium);
}
return EndedPillSheet(
isPremium: user.isPremium,
isTrial: user.isTrial,
);
}

if (user.isTrial) {
Expand All @@ -108,19 +101,12 @@ class AnnouncementBar extends HookConsumerWidget {
return RestDurationAnnouncementBar(restDurationNotification: restDurationNotification);
}

if (latestPillSheetGroup != null) {
if (latestPillSheetGroup != null && latestPillSheetGroup.activePillSheet == null) {
// ピルシートグループが存在していてactivedPillSheetが無い場合はピルシート終了が何かしらの理由がなくなったと見なし終了表示にする
if (latestPillSheetGroup.activePillSheet == null) {
return EndedPillSheet(
isPremium: user.isPremium,
isTrial: user.isTrial,
);
}

final lastPillSheet = latestPillSheetGroup.pillSheets.lastOrNull;
if (lastPillSheet != null && today().difference(lastPillSheet.estimatedEndTakenDate).inDays < 10) {
return LastPillSheet(isTrial: user.isTrial, isPremium: user.isPremium);
}
return EndedPillSheet(
isPremium: user.isPremium,
isTrial: user.isTrial,
);
}
}

Expand Down

This file was deleted.

58 changes: 41 additions & 17 deletions test/features/record/announcement_bar/announcement_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void main() {
testWidgets('#DiscountPriceDeadline', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2021, 04, 29);

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

Expand Down Expand Up @@ -107,22 +108,21 @@ void main() {
testWidgets('#PremiumTrialLimitAnnouncementBar', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2021, 04, 29);
final n = today();

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

var pillSheet = PillSheet.create(
PillSheetType.pillsheet_21,
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(
pillSheetIDs: ["1"],
pillSheets: [pillSheet],
createdAt: now(),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());

SharedPreferences.setMockInitialValues({
IntKey.totalCountOfActionForTakenPill: totalCountOfActionForTakenPillForLongTimeUser,
Expand Down Expand Up @@ -155,17 +155,17 @@ void main() {
await tester.pump();

expect(
find.byWidgetPredicate((widget) {
print(widget);
return widget is PremiumTrialLimitAnnouncementBar;
}),
find.byWidgetPredicate((widget) => widget is PremiumTrialLimitAnnouncementBar),
findsOneWidget,
);
});
testWidgets('#EndedPillSheet', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2021, 04, 29);
final n = today();

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

var pillSheet = PillSheet.create(
Expand Down Expand Up @@ -218,6 +218,7 @@ void main() {
testWidgets('today is before 2022-08-10', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10).subtract(const Duration(seconds: 1));

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

Expand Down Expand Up @@ -278,6 +279,7 @@ void main() {
testWidgets('today is 2022-08-10', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10);

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

Expand Down Expand Up @@ -340,6 +342,7 @@ void main() {
testWidgets('today is 2022-08-11', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 11);

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

Expand Down Expand Up @@ -402,6 +405,7 @@ void main() {
testWidgets('now is 2022-08-23T23:59:59', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 23, 23, 59, 59);

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

Expand Down Expand Up @@ -464,6 +468,7 @@ void main() {
testWidgets('now is 2022-08-24T00:00:00', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 24);

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

Expand Down Expand Up @@ -531,6 +536,8 @@ void main() {
testWidgets('today is before 2022-08-10', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10).subtract(const Duration(seconds: 1));

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

Expand All @@ -539,7 +546,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -594,6 +601,8 @@ void main() {
testWidgets('today is 2022-08-10', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 10);

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

Expand All @@ -602,7 +611,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -657,6 +666,8 @@ void main() {
testWidgets('today is 2022-08-11', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 11);

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

Expand All @@ -665,7 +676,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -720,6 +731,8 @@ void main() {
testWidgets('now is 2022-08-23T23:59:59', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 23, 23, 59, 59);

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

Expand All @@ -728,7 +741,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -783,6 +796,8 @@ void main() {
testWidgets('now is 2022-08-23T23:59:59 and already closed', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 23, 23, 59, 59);

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

Expand All @@ -791,7 +806,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -846,6 +861,8 @@ void main() {
testWidgets('now is 2022-08-24T00:00:00', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2022, 08, 24);

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

Expand All @@ -854,7 +871,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -910,6 +927,8 @@ void main() {
testWidgets('#RecommendSignupForPremiumAnnouncementBar', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2021, 04, 29);

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

Expand All @@ -918,7 +937,7 @@ void main() {
lastTakenDate: mockToday,
beginDate: mockToday.subtract(
// NOTE: Not into rest duration and notification duration
const Duration(days: 15),
const Duration(days: 10),
),
);
final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheet], createdAt: now());
Expand Down Expand Up @@ -962,6 +981,8 @@ void main() {
testWidgets('#RestDurationAnnouncementBar', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2021, 04, 29);

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

Expand Down Expand Up @@ -1013,7 +1034,10 @@ void main() {
testWidgets('#EndedPillSheet', (WidgetTester tester) async {
final mockTodayRepository = MockTodayService();
final mockToday = DateTime(2021, 04, 29);
final n = today();

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

var pillSheet = PillSheet.create(
Expand Down

0 comments on commit c2b3b79

Please sign in to comment.