From fd828de0db944b113c1015cd0353d21dc31242db Mon Sep 17 00:00:00 2001 From: zin- Date: Wed, 28 Aug 2024 12:47:29 +0900 Subject: [PATCH] coverage wip #377 --- .../scenarios/memo/detail_scenarios.dart | 148 ++++++++---------- .../repository/database_tuple_entity.dart | 7 - test/act_counter/act_counter_test.dart | 28 +++- 3 files changed, 91 insertions(+), 92 deletions(-) diff --git a/integration_test/scenarios/memo/detail_scenarios.dart b/integration_test/scenarios/memo/detail_scenarios.dart index 15328edba..712f8fb7c 100644 --- a/integration_test/scenarios/memo/detail_scenarios.dart +++ b/integration_test/scenarios/memo/detail_scenarios.dart @@ -229,94 +229,84 @@ void main() => group( const archivedMemName = "$insertedMemName - archived"; setUp(() async { - await dbA.insert( - defTableMems, - { - defColMemsName.name: unarchivedMemName, - defColCreatedAt.name: DateTime.now(), - }, - ); - await dbA.insert( - defTableMems, - { - defColMemsName.name: archivedMemName, - defColCreatedAt.name: DateTime.now(), - defColArchivedAt.name: DateTime.now(), - }, - ); + final unarchivedMemId = await dbA.insert(defTableMems, { + defColMemsName.name: unarchivedMemName, + defColCreatedAt.name: DateTime.now(), + }); + await dbA.insert(defTableMemItems, { + defFkMemItemsMemId.name: unarchivedMemId, + defColMemItemsType.name: MemItemType.memo.name, + defColMemItemsValue.name: insertedMemMemo, + defColCreatedAt.name: zeroDate, + }); + final archivedMemId = await dbA.insert(defTableMems, { + defColMemsName.name: archivedMemName, + defColCreatedAt.name: DateTime.now(), + defColArchivedAt.name: DateTime.now(), + }); + await dbA.insert(defTableMemItems, { + defFkMemItemsMemId.name: archivedMemId, + defColMemItemsType.name: MemItemType.memo.name, + defColMemItemsValue.name: insertedMemMemo, + defColCreatedAt.name: zeroDate, + }); }); - testWidgets( - ": archive.", - (widgetTester) async { - await runApplication(); - await widgetTester.pumpAndSettle(); - await widgetTester.tap(find.text(unarchivedMemName)); - await widgetTester.pumpAndSettle(); - - await widgetTester.tap(find.byIcon(Icons.more_vert)); - await widgetTester.pumpAndSettle(); - - await widgetTester.tap(find.byIcon(Icons.archive)); - await widgetTester.pumpAndSettle(); - - expect( - find.text(unarchivedMemName), - findsNothing, - ); - expect( + testWidgets(": archive.", (widgetTester) async { + await runApplication(); + await widgetTester.pumpAndSettle(); + await widgetTester.tap(find.text(unarchivedMemName)); + await widgetTester.pumpAndSettle(); + + await widgetTester.tap(find.byIcon(Icons.more_vert)); + await widgetTester.pumpAndSettle(); + + await widgetTester.tap(find.byIcon(Icons.archive)); + await widgetTester.pumpAndSettle(); + + expect(find.text(unarchivedMemName), findsNothing); + expect( find.text(l10n.archiveMemSuccessMessage(unarchivedMemName)), - findsOneWidget, - ); + findsOneWidget); - final findUnarchivedMem = - Equals(defColMemsName, unarchivedMemName); - final mems = await dbA.select( - defTableMems, + final findUnarchivedMem = + Equals(defColMemsName, unarchivedMemName); + final mems = await dbA.select(defTableMems, where: findUnarchivedMem.where(), - whereArgs: findUnarchivedMem.whereArgs(), - ); - expect(mems.length, 1); - expect(mems.single[defColArchivedAt.name], isNotNull); - }, - ); + whereArgs: findUnarchivedMem.whereArgs()); + expect(mems.length, 1); + expect(mems.single[defColArchivedAt.name], isNotNull); + }); - testWidgets( - ": unarchive.", - (widgetTester) async { - await runApplication(); - await widgetTester.pumpAndSettle(); - await widgetTester.tap(filterListIconFinder); - await widgetTester.pumpAndSettle(); - await widgetTester.tap(showArchiveSwitchFinder); - await widgetTester.pumpAndSettle(); - await closeMemListFilter(widgetTester); - await widgetTester.pumpAndSettle(); - await widgetTester.tap(find.text(archivedMemName)); - await widgetTester.pumpAndSettle(); - - await widgetTester.tap(find.byIcon(Icons.more_vert)); - await widgetTester.pumpAndSettle(); - - await widgetTester.tap(find.byIcon(Icons.unarchive)); - await widgetTester.pumpAndSettle(); - - expect( + testWidgets(": unarchive.", (widgetTester) async { + await runApplication(); + await widgetTester.pumpAndSettle(); + await widgetTester.tap(filterListIconFinder); + await widgetTester.pumpAndSettle(); + await widgetTester.tap(showArchiveSwitchFinder); + await widgetTester.pumpAndSettle(); + await closeMemListFilter(widgetTester); + await widgetTester.pumpAndSettle(); + await widgetTester.tap(find.text(archivedMemName)); + await widgetTester.pumpAndSettle(); + + await widgetTester.tap(find.byIcon(Icons.more_vert)); + await widgetTester.pumpAndSettle(); + + await widgetTester.tap(find.byIcon(Icons.unarchive)); + await widgetTester.pumpAndSettle(); + + expect( find.text(l10n.unarchiveMemSuccessMessage(archivedMemName)), - findsOneWidget, - ); + findsOneWidget); - final findArchivedMem = - Equals(defColMemsName, archivedMemName); - final mems = await dbA.select( - defTableMems, + final findArchivedMem = Equals(defColMemsName, archivedMemName); + final mems = await dbA.select(defTableMems, where: findArchivedMem.where(), - whereArgs: findArchivedMem.whereArgs(), - ); - expect(mems.length, 1); - expect(mems.single[defColArchivedAt.name], isNull); - }, - ); + whereArgs: findArchivedMem.whereArgs()); + expect(mems.length, 1); + expect(mems.single[defColArchivedAt.name], isNull); + }); }); }, ); diff --git a/lib/framework/repository/database_tuple_entity.dart b/lib/framework/repository/database_tuple_entity.dart index 5d924921a..b5b0b9c7c 100644 --- a/lib/framework/repository/database_tuple_entity.dart +++ b/lib/framework/repository/database_tuple_entity.dart @@ -9,13 +9,6 @@ mixin SavedDatabaseTupleMixinV1 on EntityV1 { bool get isArchived => archivedAt != null; - void pack(Map tuple) { - id = tuple[defPkId.name]; - createdAt = tuple[defColCreatedAt.name]; - updatedAt = tuple[defColUpdatedAt.name]; - archivedAt = tuple[defColArchivedAt.name]; - } - Map unpack() { return { defPkId.name: id, diff --git a/test/act_counter/act_counter_test.dart b/test/act_counter/act_counter_test.dart index 9bf572d73..c589bf15d 100644 --- a/test/act_counter/act_counter_test.dart +++ b/test/act_counter/act_counter_test.dart @@ -6,9 +6,25 @@ import 'package:mem/core/date_and_time/date_and_time_period.dart'; import 'package:mem/repositories/mem.dart'; void main() { - test( - ": constructor.", - () { + group('ActCounter.from', () { + test(": updatedAt is last act start.", () { + const memId = 1; + final zeroDate = DateTime(0); + final oneDate = DateTime(1); + + final savedMem = SavedMemV1("constructor", null, null)..id = memId; + final acts = [ + SavedAct(memId, DateAndTimePeriod.startNow()) + ..createdAt = zeroDate + ..updatedAt = oneDate, + SavedAct(memId, DateAndTimePeriod.startNow())..createdAt = zeroDate + ]; + + final actCounter = ActCounter.from(savedMem, acts); + + expect(actCounter.updatedAt, equals(acts[0].period.start)); + }); + test(": updatedAt is last act end.", () { const memId = 1; final zeroDate = DateTime(0); final oneDate = DateTime(1); @@ -18,14 +34,14 @@ void main() { SavedAct(memId, DateAndTimePeriod(end: DateAndTime.now())) ..createdAt = zeroDate ..updatedAt = oneDate, - SavedAct(memId, DateAndTimePeriod.startNow())..createdAt = zeroDate, + SavedAct(memId, DateAndTimePeriod.startNow())..createdAt = zeroDate ]; final actCounter = ActCounter.from(savedMem, acts); expect(actCounter.updatedAt, equals(acts[0].period.end)); - }, - ); + }); + }); group('period', () { test(': startDate time is 5:00', () {