TF-1080 Add unit test for mappingMailboxIdToDeleted
This commit is contained in:
@@ -42,13 +42,13 @@ import 'package:tmail_ui_user/features/mailbox/domain/usecases/move_mailbox_inte
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/rename_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/usecases/search_mailbox_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories_expand_mode.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/open_mailbox_view_event.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/utils/mailbox_utils.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/duplicate_name_validator.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification/empty_name_validator.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/domain/state/verify_name_view_state.dart';
|
||||
@@ -603,7 +603,10 @@ class MailboxController extends BaseMailboxController {
|
||||
final session = mailboxDashBoardController.sessionCurrent;
|
||||
|
||||
if (session != null && accountId != null) {
|
||||
final tupleMap = _generateMapDescendantIdsAndMailboxIdList([presentationMailbox]);
|
||||
final tupleMap = MailboxUtils.generateMapDescendantIdsAndMailboxIdList(
|
||||
[presentationMailbox],
|
||||
defaultMailboxTree.value,
|
||||
folderMailboxTree.value);
|
||||
final mapDescendantIds = tupleMap.value1;
|
||||
final listMailboxId = tupleMap.value2;
|
||||
|
||||
@@ -675,41 +678,15 @@ class MailboxController extends BaseMailboxController {
|
||||
}
|
||||
}
|
||||
|
||||
Tuple2<Map<MailboxId, List<MailboxId>>, List<MailboxId>> _generateMapDescendantIdsAndMailboxIdList(
|
||||
List<PresentationMailbox> selectedMailboxList
|
||||
) {
|
||||
Map<MailboxId, List<MailboxId>> mapDescendantIds = {};
|
||||
List<MailboxId> allMailboxIds = [];
|
||||
|
||||
for (var mailbox in selectedMailboxList) {
|
||||
final currentMailboxId = mailbox.id;
|
||||
|
||||
if (allMailboxIds.contains(currentMailboxId)) {
|
||||
continue;
|
||||
} else {
|
||||
final matchedNode = findMailboxNodeById(currentMailboxId);
|
||||
|
||||
if (matchedNode != null) {
|
||||
final descendantIds = matchedNode.descendantsAsList().mailboxIds;
|
||||
final descendantIdsReversed = descendantIds.reversed.toList();
|
||||
|
||||
mapDescendantIds[currentMailboxId] = descendantIdsReversed;
|
||||
allMailboxIds.addAll(descendantIdsReversed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log('MailboxController::_generateMapDescendantIdsByMailboxList(): mapDescendantIds: $mapDescendantIds');
|
||||
|
||||
return Tuple2(mapDescendantIds, allMailboxIds);
|
||||
}
|
||||
|
||||
void _deleteMultipleMailboxAction(List<PresentationMailbox> selectedMailboxList) {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
final session = mailboxDashBoardController.sessionCurrent;
|
||||
|
||||
if (session != null && accountId != null) {
|
||||
final tupleMap = _generateMapDescendantIdsAndMailboxIdList(selectedMailboxList);
|
||||
final tupleMap = MailboxUtils.generateMapDescendantIdsAndMailboxIdList(
|
||||
selectedMailboxList,
|
||||
defaultMailboxTree.value,
|
||||
folderMailboxTree.value);
|
||||
final mapDescendantIds = tupleMap.value1;
|
||||
final listMailboxId = tupleMap.value2;
|
||||
consumeState(_deleteMultipleMailboxInteractor.execute(
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';
|
||||
|
||||
class MailboxUtils {
|
||||
|
||||
static Tuple2<Map<MailboxId, List<MailboxId>>, List<MailboxId>> generateMapDescendantIdsAndMailboxIdList(
|
||||
List<PresentationMailbox> selectedMailboxList,
|
||||
MailboxTree defaultMailboxTree,
|
||||
MailboxTree folderMailboxTree,
|
||||
) {
|
||||
Map<MailboxId, List<MailboxId>> mapDescendantIds = {};
|
||||
List<MailboxId> allMailboxIds = [];
|
||||
|
||||
for (var mailbox in selectedMailboxList) {
|
||||
final currentMailboxId = mailbox.id;
|
||||
|
||||
if (allMailboxIds.contains(currentMailboxId)) {
|
||||
continue;
|
||||
} else {
|
||||
final matchedNode = defaultMailboxTree.findNode((node) => node.item.id == currentMailboxId)
|
||||
?? folderMailboxTree.findNode((node) => node.item.id == currentMailboxId);
|
||||
|
||||
if (matchedNode != null) {
|
||||
final descendantIds = matchedNode.descendantsAsList().mailboxIds;
|
||||
final descendantIdsReversed = descendantIds.reversed.toList();
|
||||
|
||||
mapDescendantIds[currentMailboxId] = descendantIdsReversed;
|
||||
allMailboxIds.addAll(descendantIdsReversed);
|
||||
}
|
||||
}
|
||||
}
|
||||
log('MailboxUtils::generateMapDescendantIdsAndMailboxIdList(): mapDescendantIds: $mapDescendantIds');
|
||||
return Tuple2(mapDescendantIds, allMailboxIds);
|
||||
}
|
||||
}
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/utils/mailbox_utils.dart';
|
||||
|
||||
void main() {
|
||||
group('generate mapping delete multiple mailbox test', () {
|
||||
|
||||
final expectedMapOfTwoMailboxId = {
|
||||
MailboxId(Id("A")): [
|
||||
MailboxId(Id('A_1_1')),
|
||||
MailboxId(Id('A_1')),
|
||||
MailboxId(Id('A_2_1')),
|
||||
MailboxId(Id('A_2')),
|
||||
MailboxId(Id('A'))
|
||||
],
|
||||
MailboxId(Id("B_1")): [MailboxId(Id('B_1'))],
|
||||
};
|
||||
|
||||
final expectedListMailboxId = [
|
||||
MailboxId(Id('A_1_1')),
|
||||
MailboxId(Id('A_1')),
|
||||
MailboxId(Id('A_2_1')),
|
||||
MailboxId(Id('A_2')),
|
||||
MailboxId(Id('A')),
|
||||
MailboxId(Id('B_1')),
|
||||
];
|
||||
|
||||
final expectedMapOfOneMailboxId = {
|
||||
MailboxId(Id("A")): [
|
||||
MailboxId(Id('A_1_1')),
|
||||
MailboxId(Id('A_1')),
|
||||
MailboxId(Id('A_2_1')),
|
||||
MailboxId(Id('A_2')),
|
||||
MailboxId(Id('A'))
|
||||
]
|
||||
};
|
||||
|
||||
final expectedMapOfThreeMailboxId = {
|
||||
MailboxId(Id("A")): [
|
||||
MailboxId(Id('A_1_1')),
|
||||
MailboxId(Id('A_1')),
|
||||
MailboxId(Id('A_2_1')),
|
||||
MailboxId(Id('A_2')),
|
||||
MailboxId(Id('A'))
|
||||
],
|
||||
MailboxId(Id("B_1")): [MailboxId(Id('B_1'))],
|
||||
MailboxId(Id("C_1")): [MailboxId(Id('C_1'))],
|
||||
};
|
||||
|
||||
test('_generateMapDescendantIdsAndMailboxIdList should return map with 2 items when mailboxes belong to 2 different tree', () async {
|
||||
final defaultMailboxTree = MailboxTree(MailboxNode(PresentationMailbox(MailboxId(Id('root')))));
|
||||
|
||||
final folderMailboxTree = MailboxTree(
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('root'))),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_2')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_2_1')), parentId: MailboxId(Id('A_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_1')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_1_1')), parentId: MailboxId(Id('A_1'))))
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B_2')), parentId: MailboxId(Id('B'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_2_1')), parentId: MailboxId(Id('B_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_1')), parentId: MailboxId(Id('B')))),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
final selectedMailboxList = [
|
||||
PresentationMailbox(MailboxId(Id("A")), parentId: null),
|
||||
PresentationMailbox(MailboxId(Id('A_1')), parentId: MailboxId(Id('A'))),
|
||||
PresentationMailbox(MailboxId(Id('A_2_1')), parentId: MailboxId(Id('A_2'))),
|
||||
PresentationMailbox(MailboxId(Id("B_1")), parentId: MailboxId(Id('B')))
|
||||
];
|
||||
|
||||
final tupleResult = MailboxUtils.generateMapDescendantIdsAndMailboxIdList(
|
||||
selectedMailboxList,
|
||||
defaultMailboxTree,
|
||||
folderMailboxTree);
|
||||
|
||||
expect(tupleResult.value1, equals(expectedMapOfTwoMailboxId));
|
||||
});
|
||||
|
||||
test('_generateMapDescendantIdsAndMailboxIdList should return list with 5 item when mailboxes belong to 2 different tree', () async {
|
||||
final defaultMailboxTree = MailboxTree(MailboxNode(PresentationMailbox(MailboxId(Id('root')))));
|
||||
|
||||
final folderMailboxTree = MailboxTree(
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('root'))),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_2')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_2_1')), parentId: MailboxId(Id('A_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_1')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_1_1')), parentId: MailboxId(Id('A_1'))))
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B_2')), parentId: MailboxId(Id('B'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_2_1')), parentId: MailboxId(Id('B_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_1')), parentId: MailboxId(Id('B')))),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
final selectedMailboxList = [
|
||||
PresentationMailbox(MailboxId(Id("A")), parentId: null),
|
||||
PresentationMailbox(MailboxId(Id('A_1')), parentId: MailboxId(Id('A'))),
|
||||
PresentationMailbox(MailboxId(Id('A_2_1')), parentId: MailboxId(Id('A_2'))),
|
||||
PresentationMailbox(MailboxId(Id("B_1")), parentId: MailboxId(Id('B')))
|
||||
];
|
||||
|
||||
final tupleResult = MailboxUtils.generateMapDescendantIdsAndMailboxIdList(
|
||||
selectedMailboxList,
|
||||
defaultMailboxTree,
|
||||
folderMailboxTree);
|
||||
|
||||
expect(tupleResult.value2, equals(expectedListMailboxId));
|
||||
});
|
||||
|
||||
test('_generateMapDescendantIdsAndMailboxIdList should return map with 1 items when mailboxes belong to 2 different tree', () async {
|
||||
final defaultMailboxTree = MailboxTree(MailboxNode(PresentationMailbox(MailboxId(Id('root')))));
|
||||
|
||||
final folderMailboxTree = MailboxTree(
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('root'))),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_2')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_2_1')), parentId: MailboxId(Id('A_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_1')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_1_1')), parentId: MailboxId(Id('A_1'))))
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B_2')), parentId: MailboxId(Id('B'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_2_1')), parentId: MailboxId(Id('B_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_1')), parentId: MailboxId(Id('B')))),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
final selectedMailboxList = [
|
||||
PresentationMailbox(MailboxId(Id("A")), parentId: null),
|
||||
];
|
||||
|
||||
final tupleResult = MailboxUtils.generateMapDescendantIdsAndMailboxIdList(
|
||||
selectedMailboxList,
|
||||
defaultMailboxTree,
|
||||
folderMailboxTree);
|
||||
|
||||
expect(tupleResult.value1, equals(expectedMapOfOneMailboxId));
|
||||
});
|
||||
|
||||
test('_generateMapDescendantIdsAndMailboxIdList should return map with 3 items when mailboxes belong to 2 different tree', () async {
|
||||
final defaultMailboxTree = MailboxTree(MailboxNode(PresentationMailbox(MailboxId(Id('root')))));
|
||||
|
||||
final folderMailboxTree = MailboxTree(
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('root'))),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_2')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_2_1')), parentId: MailboxId(Id('A_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('A_1')), parentId: MailboxId(Id('A'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('A_1_1')), parentId: MailboxId(Id('A_1'))))
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('B_2')), parentId: MailboxId(Id('B'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_2_1')), parentId: MailboxId(Id('B_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('B_1')), parentId: MailboxId(Id('B')))),
|
||||
]
|
||||
),
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('C')), parentId: null),
|
||||
childrenItems: [
|
||||
MailboxNode(
|
||||
PresentationMailbox(MailboxId(Id('C_2')), parentId: MailboxId(Id('C'))),
|
||||
childrenItems: [
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('C_2_1')), parentId: MailboxId(Id('C_2'))))
|
||||
]
|
||||
),
|
||||
MailboxNode(PresentationMailbox(MailboxId(Id('C_1')), parentId: MailboxId(Id('C')))),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
final selectedMailboxList = [
|
||||
PresentationMailbox(MailboxId(Id("A")), parentId: null),
|
||||
PresentationMailbox(MailboxId(Id("B_1")), parentId: MailboxId(Id('B'))),
|
||||
PresentationMailbox(MailboxId(Id("C_1")), parentId: MailboxId(Id('C')))
|
||||
];
|
||||
|
||||
final tupleResult = MailboxUtils.generateMapDescendantIdsAndMailboxIdList(
|
||||
selectedMailboxList,
|
||||
defaultMailboxTree,
|
||||
folderMailboxTree);
|
||||
|
||||
expect(tupleResult.value1, equals(expectedMapOfThreeMailboxId));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user