Skip to content

Commit a140e3e

Browse files
committed
test: Have eg.streamMessage and eg.dmMessage accept message content
1 parent 90c4c84 commit a140e3e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

test/example_data.dart

+20-7
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,25 @@ Map<String, dynamic> _messagePropertiesFromSender(User? sender) {
103103
};
104104
}
105105

106+
Map<String, dynamic> _messagePropertiesFromContent(String? content, String? contentMarkdown) {
107+
if (contentMarkdown != null) {
108+
assert(content == null);
109+
return {
110+
'content': contentMarkdown,
111+
'content_type': 'text/x-markdown',
112+
};
113+
} else {
114+
return {
115+
'content': content ?? '<p>This is an example message.</p>',
116+
'content_type': 'text/html',
117+
};
118+
}
119+
}
120+
106121
const _stream = stream;
107122

108123
StreamMessage streamMessage(
109-
{User? sender, ZulipStream? stream, String? topic}) {
124+
{User? sender, ZulipStream? stream, String? topic, String? content, String? contentMarkdown}) {
110125
final effectiveStream = stream ?? _stream();
111126
// The use of JSON here is convenient in order to delegate parts of the data
112127
// to helper functions. The main downside is that it loses static typing
@@ -116,11 +131,9 @@ StreamMessage streamMessage(
116131
return StreamMessage.fromJson({
117132
..._messagePropertiesBase,
118133
..._messagePropertiesFromSender(sender),
134+
..._messagePropertiesFromContent(content, contentMarkdown),
119135
'display_recipient': effectiveStream.name,
120136
'stream_id': effectiveStream.streamId,
121-
122-
'content': '<p>This is an example stream message.</p>',
123-
'content_type': 'text/html',
124137
'flags': [],
125138
'id': 1234567, // TODO generate example IDs
126139
'subject': topic ?? 'example topic',
@@ -133,17 +146,17 @@ StreamMessage streamMessage(
133146
///
134147
/// See also:
135148
/// * [streamMessage], to construct an example stream message.
136-
DmMessage dmMessage({required User from, required List<User> to}) {
149+
DmMessage dmMessage(
150+
{required User from, required List<User> to, String? content, String? contentMarkdown}) {
137151
assert(!to.any((user) => user.userId == from.userId));
138152
return DmMessage.fromJson({
139153
..._messagePropertiesBase,
140154
..._messagePropertiesFromSender(from),
155+
..._messagePropertiesFromContent(content, contentMarkdown),
141156
'display_recipient': [from, ...to]
142157
.map((u) => {'id': u.userId, 'email': u.email, 'full_name': u.fullName})
143158
.toList(growable: false),
144159

145-
'content': '<p>This is an example DM.</p>',
146-
'content_type': 'text/html',
147160
'flags': [],
148161
'id': 1234567, // TODO generate example IDs
149162
'subject': '',

0 commit comments

Comments
 (0)