-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TF-3298 Fix blink when refresh email list (#3299)
- Loading branch information
Showing
5 changed files
with
399 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
test/features/email/sorting_list_email_by_order_id_list_test.dart
This file was deleted.
Oops, something went wrong.
166 changes: 166 additions & 0 deletions
166
test/features/thread/data/extensions/list_email_extension_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:jmap_dart_client/jmap/core/id.dart'; | ||
import 'package:jmap_dart_client/jmap/mail/email/email.dart'; | ||
import 'package:model/extensions/email_id_extensions.dart'; | ||
import 'package:tmail_ui_user/features/thread/data/extensions/list_email_extension.dart'; | ||
|
||
void main() { | ||
group('ListEmailExtension::sortEmailsById::test', () { | ||
test('Sort the full list', () { | ||
final referenceIds = <Id>[ | ||
Id('id1'), | ||
Id('id2'), | ||
Id('id3'), | ||
Id('id4'), | ||
]; | ||
|
||
final emails = <Email>[ | ||
Email(id: EmailId(Id('id3'))), | ||
Email(id: EmailId(Id('id1'))), | ||
Email(id: EmailId(Id('id4'))), | ||
Email(id: EmailId(Id('id2'))), | ||
]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
['id1', 'id2', 'id3', 'id4'], | ||
); | ||
}); | ||
|
||
test('Emails list has more elements than referenceIds', () { | ||
final referenceIds = <Id>[ | ||
Id('id1'), | ||
Id('id2'), | ||
Id('id3'), | ||
]; | ||
|
||
final emails = <Email>[ | ||
Email(id: EmailId(Id('id3'))), | ||
Email(id: EmailId(Id('id4'))), | ||
Email(id: EmailId(Id('id1'))), | ||
Email(id: EmailId(Id('id5'))), | ||
Email(id: EmailId(Id('id2'))), | ||
]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
['id1', 'id2', 'id3', 'id4', 'id5'], | ||
); | ||
}); | ||
|
||
test('Emails list has fewer elements than referenceIds', () { | ||
final referenceIds = <Id>[ | ||
Id('id1'), | ||
Id('id2'), | ||
Id('id3'), | ||
Id('id4'), | ||
]; | ||
|
||
final emails = <Email>[ | ||
Email(id: EmailId(Id('id3'))), | ||
Email(id: EmailId(Id('id1'))), | ||
]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
['id1', 'id3'], | ||
); | ||
}); | ||
|
||
test('Emails list is empty', () { | ||
final referenceIds = <Id>[ | ||
Id('id1'), | ||
Id('id2'), | ||
Id('id3'), | ||
]; | ||
|
||
final emails = <Email>[]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
[], | ||
); | ||
}); | ||
|
||
test('ReferenceIds list is empty', () { | ||
final referenceIds = <Id>[]; | ||
|
||
final emails = <Email>[ | ||
Email(id: EmailId(Id('id3'))), | ||
Email(id: EmailId(Id('id4'))), | ||
Email(id: EmailId(Id('id1'))), | ||
Email(id: EmailId(Id('id5'))), | ||
]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
['id3', 'id4', 'id1', 'id5'], | ||
); | ||
}); | ||
|
||
test('Both lists are empty', () { | ||
final referenceIds = <Id>[]; | ||
final emails = <Email>[]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
[], | ||
); | ||
}); | ||
|
||
test('Emails have ids that do not match referenceIds', () { | ||
final referenceIds = <Id>[ | ||
Id('id1'), | ||
Id('id2'), | ||
]; | ||
|
||
final emails = <Email>[ | ||
Email(id: EmailId(Id('id3'))), | ||
Email(id: EmailId(Id('id4'))), | ||
Email(id: EmailId(Id('id5'))), | ||
]; | ||
|
||
final result = emails.sortEmailsById(referenceIds); | ||
|
||
expect( | ||
result.map((e) => e.id!.asString).toList(), | ||
['id3', 'id4', 'id5'], | ||
); | ||
}); | ||
|
||
test('should keep emails with null IDs in their original order at the end', () { | ||
// Arrange | ||
final referenceIds = [ | ||
Id('id2'), | ||
Id('id1'), | ||
]; | ||
|
||
final emails = [ | ||
Email(id: EmailId(Id('id1'))), | ||
Email(id: null), | ||
Email(id: EmailId(Id('id2'))), | ||
]; | ||
|
||
// Act | ||
final sortedEmails = emails.sortEmailsById(referenceIds); | ||
|
||
// Assert | ||
expect( | ||
sortedEmails.map((e) => e.id?.asString).toList(), | ||
['id2', 'id1', null], | ||
); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.