-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
220 additions
and
0 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
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
63 changes: 63 additions & 0 deletions
63
packages/stream_chat_flutter/test/test_utils/data_generator.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,63 @@ | ||
import 'package:faker_dart/faker_dart.dart'; | ||
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
||
List<Message> generateConversation( | ||
int count, { | ||
List<User>? users, | ||
int? noOfUsers, | ||
int unreadCount = 0, | ||
}) { | ||
assert( | ||
users == null || noOfUsers == null, | ||
'Only one of users or noOfUsers ' | ||
'should be provided'); | ||
assert(count > 0, 'Count should be greater than 0'); | ||
assert(count > unreadCount, 'Count should be greater than unreadCount'); | ||
|
||
users ??= generateUsers(noOfUsers!); | ||
|
||
final faker = Faker.instance; | ||
|
||
final messages = <Message>[]; | ||
for (var i = 0; i < count - unreadCount; i++) { | ||
final user = users[i % users.length]; | ||
messages.add( | ||
Message( | ||
id: faker.datatype.uuid(), | ||
text: faker.lorem.sentence(), | ||
user: user, | ||
createdAt: DateTime.now().subtract(Duration(minutes: i)), | ||
), | ||
); | ||
} | ||
|
||
for (var i = 0; i < unreadCount; i++) { | ||
final user = users.where((element) => element is! OwnUser).first; | ||
messages.add( | ||
Message( | ||
id: faker.datatype.uuid(), | ||
text: faker.lorem.sentence(), | ||
user: user, | ||
createdAt: | ||
DateTime.now().subtract(Duration(minutes: i + count - unreadCount)), | ||
), | ||
); | ||
} | ||
|
||
return messages; | ||
} | ||
|
||
List<User> generateUsers(int count) { | ||
final faker = Faker.instance; | ||
final users = <User>[]; | ||
for (var i = 0; i < count; i++) { | ||
users.add( | ||
User( | ||
id: faker.datatype.uuid(), | ||
name: faker.name.fullName(), | ||
), | ||
); | ||
} | ||
|
||
return users; | ||
} |