Skip to content

Commit

Permalink
drop: MemNotification v1
Browse files Browse the repository at this point in the history
wip drop: EntityV1
  • Loading branch information
zin- committed Sep 15, 2024
1 parent 2f6aee9 commit 87874bc
Show file tree
Hide file tree
Showing 32 changed files with 467 additions and 608 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,15 @@ void main() => group(
expect(message.arguments[2], isFalse);
expect(message.arguments[3], isFalse);
expect(
message.arguments[4],
DateTime.fromMillisecondsSinceEpoch(message.arguments[4]),
equals(testStart
.copyWith(
hour: defaultStartOfDay.hour,
minute: defaultStartOfDay.minute,
second: 0,
millisecond: 0,
microsecond: 0)
.add(const Duration(days: 1))
.millisecondsSinceEpoch));
.add(const Duration(days: 1))));
expect(message.arguments[5],
const Duration(days: 1).inMilliseconds);
expect(message.arguments[6], isFalse);
Expand Down
21 changes: 15 additions & 6 deletions integration_test/scenarios/habit/repeated_habit_scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ void main() => group(_name, () {
});

testWidgets(": update.", (widgetTester) async {
widgetTester
.ignoreMockMethodCallHandler(MethodChannelMock.permissionHandler);

await runApplication();
await widgetTester.pumpAndSettle();
await widgetTester.tap(find.text(insertedMemName));
Expand Down Expand Up @@ -231,16 +234,22 @@ void main() => group(_name, () {
await widgetTester.tap(find.byKey(keySaveMemFab));
await widgetTester.pump(waitSideEffectDuration);

final savedMem = (await dbA.select(defTableMems,
final savedMemId = (await dbA.select(defTableMems,
where: "${defColMemsName.name} = ?",
whereArgs: [insertedMemName]))
.single;
final savedMemNotification = (await dbA.select(
.single[defPkId.name];
final savedMemNotifications = (await dbA.select(
defTableMemNotifications,
where: "${defFkMemNotificationsMemId.name} = ?",
whereArgs: [savedMem[defPkId.name]]));
expect(savedMemNotification[0][defColMemNotificationsTime.name], 0);
expect(savedMemNotification[1][defColMemNotificationsTime.name], 1);
whereArgs: [savedMemId],
orderBy: "id ASC"));
expect(savedMemNotifications, hasLength(2));
expect(savedMemNotifications[0][defColMemNotificationsType.name],
MemNotificationType.repeat.name);
expect(savedMemNotifications[0][defColMemNotificationsTime.name], 0);
expect(savedMemNotifications[1][defColMemNotificationsType.name],
MemNotificationType.repeatByNDay.name);
expect(savedMemNotifications[1][defColMemNotificationsTime.name], 1);
});
});
});
89 changes: 43 additions & 46 deletions integration_test/scenarios/memo/detail_scenarios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,52 +176,49 @@ void main() => group(
},
);

testWidgets(
': twice on create.',
retry: maxRetryCount,
(widgetTester) async {
widgetTester.ignoreMockMethodCallHandler(
MethodChannelMock.permissionHandler);
widgetTester.ignoreMockMethodCallHandler(
MethodChannelMock.flutterLocalNotifications);

await runApplication();
await widgetTester.pumpAndSettle();
await widgetTester.tap(newMemFabFinder);
await widgetTester.pumpAndSettle();
const enteringMemName =
"$saveMemName: twice on create - entering";
const enteringMemMemo =
"$saveMemMemo: twice on create - entering";
await widgetTester.enterText(
find.byKey(keyMemName), enteringMemName);
await widgetTester.enterText(
find.byKey(keyMemMemo), enteringMemMemo);
await widgetTester.tap(find.byKey(keySaveMemFab));
await widgetTester.pumpAndSettle(waitSideEffectDuration);

const enteringMemMemo2 = "$enteringMemMemo - 2";
await widgetTester.enterText(
find.byKey(keyMemMemo), enteringMemMemo2);
await widgetTester.tap(find.byKey(keySaveMemFab));
await widgetTester.pumpAndSettle(waitSideEffectDuration);

final getCreatedMem = Equals(defColMemsName, enteringMemName);
final mems = await dbA.select(defTableMems,
where: getCreatedMem.where(),
whereArgs: getCreatedMem.whereArgs());
expect(mems.length, 1);
final getCreatedMemItem = And([
Equals(defFkMemItemsMemId, mems[0][defPkId.name]),
Equals(defColMemItemsType, MemItemType.memo.name)
]);
final memItems = await dbA.select(defTableMemItems,
where: getCreatedMemItem.where(),
whereArgs: getCreatedMemItem.whereArgs());
expect(memItems.single[defColMemItemsValue.name],
enteringMemMemo2);
},
);
testWidgets(': twice on create.', retry: maxRetryCount,
(widgetTester) async {
widgetTester.ignoreMockMethodCallHandler(
MethodChannelMock.permissionHandler);
widgetTester.ignoreMockMethodCallHandler(
MethodChannelMock.flutterLocalNotifications);

await runApplication();
await widgetTester.pumpAndSettle();
await widgetTester.tap(newMemFabFinder);
await widgetTester.pumpAndSettle();
const enteringMemName =
"$saveMemName: twice on create - entering";
const enteringMemMemo =
"$saveMemMemo: twice on create - entering";
await widgetTester.enterText(
find.byKey(keyMemName), enteringMemName);
await widgetTester.enterText(
find.byKey(keyMemMemo), enteringMemMemo);
await widgetTester.tap(find.byKey(keySaveMemFab));
await widgetTester.pumpAndSettle(waitSideEffectDuration);

const enteringMemMemo2 = "$enteringMemMemo - 2";
await widgetTester.enterText(
find.byKey(keyMemMemo), enteringMemMemo2);
await widgetTester.tap(find.byKey(keySaveMemFab));
await widgetTester.pumpAndSettle(waitSideEffectDuration);

final getCreatedMem = Equals(defColMemsName, enteringMemName);
final mems = await dbA.select(defTableMems,
where: getCreatedMem.where(),
whereArgs: getCreatedMem.whereArgs());
expect(mems.length, 1);
final getCreatedMemItem = And([
Equals(defFkMemItemsMemId, mems[0][defPkId.name]),
Equals(defColMemItemsType, MemItemType.memo.name)
]);
final memItems = await dbA.select(defTableMemItems,
where: getCreatedMemItem.where(),
whereArgs: getCreatedMemItem.whereArgs());
expect(
memItems.single[defColMemItemsValue.name], enteringMemMemo2);
});

group(': Archive', () {
const insertedMemName = "$saveMemName: Archive: inserted";
Expand Down
10 changes: 4 additions & 6 deletions lib/components/mem/list/actions.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mem/components/mem/list/states.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/mems/mem_item.dart';
import 'package:mem/mems/mem_item_repository.dart';
import 'package:mem/repositories/mem.dart';
import 'package:mem/repositories/mem_item_entity.dart';
import 'package:mem/repositories/mem_repository.dart';
import 'package:mem/mems/states.dart';

Expand Down Expand Up @@ -38,12 +38,10 @@ final loadMemList = FutureProvider(
);
for (var mem in mems) {
ref.read(memItemsProvider.notifier).upsertAll(
await MemItemRepository()
.ship(memId: mem.id)
.then((v) => v.map((e) => e.toV1())),
await MemItemRepository().ship(memId: mem.id),
(current, updating) =>
current is SavedMemItem &&
updating is SavedMemItem &&
current is SavedMemItemEntity &&
updating is SavedMemItemEntity &&
current.id == updating.id,
);
}
Expand Down
19 changes: 9 additions & 10 deletions lib/components/mem/list/states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:mem/notifications/mem_notifications.dart';
import 'package:mem/repositories/act_entity.dart';
import 'package:mem/repositories/act_repository.dart';
import 'package:mem/repositories/mem.dart';
import 'package:mem/repositories/mem_notification.dart';
import 'package:mem/repositories/mem_notification_entity.dart';
import 'package:mem/repositories/mem_notification_repository.dart';
import 'package:mem/settings/states.dart';

Expand Down Expand Up @@ -216,30 +216,29 @@ final latestActsByMemProvider = StateNotifierProvider.autoDispose<
),
);
final savedMemNotificationsProvider = StateNotifierProvider.autoDispose<
ListValueStateNotifier<SavedMemNotification>, List<SavedMemNotification>>(
ListValueStateNotifier<SavedMemNotificationEntity>,
List<SavedMemNotificationEntity>>(
(ref) => v(
() => ListValueStateNotifier(
ref.watch(
memNotificationsProvider.select(
(value) => value.whereType<SavedMemNotification>().toList()),
(value) => value.whereType<SavedMemNotificationEntity>().toList()),
),
initializer: (current, notifier) => v(
() async {
if (current.isEmpty) {
final memIds =
ref.read(memsProvider).whereType<SavedMemV1>().map((e) => e.id);

final actsByMemIds = await MemNotificationRepository()
.ship(
memIdsIn: memIds,
)
.then((value) => value.map((e) => e.toV1()));
final actsByMemIds = await MemNotificationRepository().ship(
memIdsIn: memIds,
);

ref.read(memNotificationsProvider.notifier).upsertAll(
actsByMemIds,
(current, updating) =>
current is SavedMemNotification &&
updating is SavedMemNotification &&
current is SavedMemNotificationEntity &&
updating is SavedMemNotificationEntity &&
current.id == updating.id,
);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/core/mem_detail.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import 'package:mem/core/mem.dart';
import 'package:mem/core/mem_item.dart';
import 'package:mem/core/mem_notification.dart';
import 'package:mem/repositories/mem_item_entity.dart';

// FIXME 定義するべきではない気がする
// - Mem, MemItems, MemNotificationsの関係はどのレイヤーのもの?
// - Entity~~かDomain~~
// - DBのFK制約が絡むしEntityかも
// - Repositoryも絡んでいくはず
class MemDetail {
final MemV1 mem;
final List<MemItem> memItems;
final List<MemItemEntity> memItems;
final List<MemNotification>? notifications;

MemDetail(this.mem, this.memItems, [this.notifications]);
Expand Down
34 changes: 1 addition & 33 deletions lib/core/mem_item.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:mem/framework/repository/entity.dart';

enum MemItemType {
memo,
}
Expand All @@ -9,35 +7,5 @@ class MemItemV2 {
final MemItemType type;
final dynamic value;

MemItemV2(this.memId, this.type, this.value); // coverage:ignore-line

// factory MemItemV2.memo(int? memId) => MemItemV2(memId, MemItemType.memo, "");
}

class MemItem extends EntityV1 {
// 未保存のMemに紐づくMemItemはmemIdをintで持つことができないため暫定的にnullableにしている
final int? memId;
final MemItemType type;
final dynamic value;

MemItem(this.memId, this.type, this.value);

factory MemItem.memo(int? memId) => MemItem(memId, MemItemType.memo, "");

MemItem copiedWith({
int Function()? memId,
dynamic Function()? value,
}) =>
MemItem(
memId == null ? this.memId : memId(),
type,
value == null ? this.value : value(),
);

@override
String toString() => "${super.toString()}: ${{
"memId": memId,
"type": type,
"value": value,
}}";
MemItemV2(this.memId, this.type, this.value);
}
Loading

0 comments on commit 87874bc

Please sign in to comment.