mirror of
https://github.com/block/buzz.git
synced 2026-11-27 19:52:31 +00:00
## Summary Mobile showed "(edited)" only in the author header. A grouped follow-up message has no header, so an edited follow-up had no marker at all. This ports the placement from desktop https://github.com/block/buzz-app/pull/2020 to the channel and thread message bodies: - **After prose:** the marker joins the last line, for example `Hi how are ya. (edited)`. This includes a final list item or quote, as on desktop. It is drawn in the timestamp style, with the metadata colour on received messages and the bubble ink on your own messages. - **After a block that text cannot join:** the marker goes on its own line inside the same text bubble. This applies to code, tables, rules, display math, indented code, a heading, a last line that ends in a link, and a bare list, quote or checkbox marker. A link renders as a widget span, so a joined marker would be read before the link by screen readers. Any body that contains ```` ``` ```` always uses its own line. gpt_markdown's fence rules differ from CommonMark, so putting the marker inside the Markdown could change how the code renders. - **After trailing images:** the marker goes below the gallery, outside the bubble. - The marker is injected only at render time: a private-use slot character that the renderer removes from authored content first. Copy text, previews and notifications still use the original message content. **Out of scope:** the mobile forum models (`ForumPost`, `ThreadReply`) have no edited state and don't fold edits, so forum posts still show no marker. Search and inbox previews also show no marker, which matches the preview rules. ### Related issue Desktop parity for https://github.com/block/buzz-app/pull/2020. I found no existing mobile issue or PR for this. ### Testing At `5276d968`: - `just mobile-check`, `just file-size-check` and `just mobile-test` all exit 0. - `edited_marker_test.dart`: a table test of which endings join inline and which take their own line, including `` ```npm install``` ``, `~~~`, indented code, tables, rules, math and bare block markers. - `message_content_bubble_cases.dart`: rendered widget checks. For each risky ending, the edited render is the unedited render plus one `(edited)` line inside the same text bubble. The tests also cover colours, trailing media, an open `<u>` and authored slot characters. With the guards removed, this test fails. - `channel_detail_page_test.dart`, edit journey: an edited message and an edited grouped follow-up are marked and an unedited message isn't. Copy text copies `Edited text` without the marker. Opening the thread marks the edited head and the edited reply. With the thread wiring removed, this test fails. - Contrast (from review): received 5.34:1 light and 8.61:1 dark; own-bubble accents at least 4.60:1. - Android emulator run (screenshots below): every edited case shows the marker where the rules above say, in light and dark. Not done: iOS simulator and VoiceOver. - Found during the emulator run, not caused by this PR: an edit made to a thread reply before the thread is opened is not loaded, so the reply shows its original text and no marker. The thread query asks only for content kinds, and the channel history did not supply the earlier edit. An edit that arrives while the thread is open shows correctly (screenshot). **Android emulator** (debug build of `5276d968` on a local relay, seeded with edited messages): | Prose, grouped follow-up, own bubbles, list | Code block, table, fenced inline text, trailing image | | - | - | |  |  | | Dark | Dark, trailing image | Thread (edit arrived while open) | | - | - | - | |  |  |  | **Widget renders** (throwaway test, not committed): | Light | Dark | | - | - | |  |  | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Logan Johnson <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
445 lines
14 KiB
Dart
445 lines
14 KiB
Dart
part of 'message_content_test.dart';
|
|
|
|
void bubbleContentTests() {
|
|
final bubbles = find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget.key is ValueKey<String> &&
|
|
(widget.key! as ValueKey<String>).value.startsWith(
|
|
'message-text-bubble-',
|
|
),
|
|
);
|
|
testWidgets('message shapes remain inside their bounds without tails', (
|
|
tester,
|
|
) async {
|
|
for (final tail in [false, true]) {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
MessageContent(content: 'Hello', bubble: true, bubbleEnd: tail),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final decoration = tester.widget<LocalSendBubbleSurface>(
|
|
find.descendant(
|
|
of: bubbles,
|
|
matching: find.byType(LocalSendBubbleSurface),
|
|
),
|
|
);
|
|
final bounds = decoration.shape
|
|
.getOuterPath(Offset.zero & tester.getSize(bubbles))
|
|
.getBounds();
|
|
expect(bounds.left, 0);
|
|
expect(bounds.bottom, tester.getSize(bubbles).height);
|
|
}
|
|
});
|
|
|
|
for (final brightness in Brightness.values) {
|
|
testWidgets('bubbles inherit every chat color in $brightness', (
|
|
tester,
|
|
) async {
|
|
for (final choice in chatColorChoices) {
|
|
final theme = mobileAppearanceTheme(brightness, choice.wireValue);
|
|
for (final own in [false, true]) {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
MessageContent(
|
|
content: 'Themed message',
|
|
bubble: true,
|
|
ownMessage: own,
|
|
),
|
|
theme: theme,
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final surface = tester.widget<LocalSendBubbleSurface>(
|
|
find.byType(LocalSendBubbleSurface),
|
|
);
|
|
expect(
|
|
surface.color,
|
|
own
|
|
? theme.extension<ChatColors>()!.outgoing
|
|
: receivedMessageSurface(brightness),
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
for (final dark in [false, true]) {
|
|
testWidgets('outgoing headings, mentions and links contrast in dark=$dark', (
|
|
tester,
|
|
) async {
|
|
String? tapped;
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
MessageContent(
|
|
content:
|
|
'# H1\n\n## H2\n\n### H3\n\n#### H4\n\n##### H5\n\n###### H6\n\n@Alice @Helper [Website](https://example.com)',
|
|
bubble: true,
|
|
ownMessage: true,
|
|
mentionNames: const {'person': 'Alice', 'agent': 'Helper'},
|
|
agentMentionPubkeys: const {'agent'},
|
|
onMentionTap: (pubkey) => tapped = pubkey,
|
|
),
|
|
dark: dark,
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final foreground = ChatColors.of(
|
|
tester.element(find.byType(MessageContent)),
|
|
).foreground;
|
|
for (final heading in ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']) {
|
|
final text = tester.widget<RichText>(_findRich(heading).last);
|
|
final colors = <Color?>[];
|
|
void inspect(InlineSpan span, TextStyle? inherited) {
|
|
final effective = inherited?.merge(span.style) ?? span.style;
|
|
if (span is TextSpan) {
|
|
if (span.text?.contains(heading) == true) {
|
|
colors.add(effective?.color);
|
|
}
|
|
for (final child in span.children ?? const <InlineSpan>[]) {
|
|
inspect(child, effective);
|
|
}
|
|
}
|
|
}
|
|
|
|
inspect(text.text, null);
|
|
expect(colors, [foreground]);
|
|
}
|
|
final linkColor = ChatColors.of(
|
|
tester.element(find.byType(MessageContent)),
|
|
).foreground;
|
|
for (final label in ['Alice', 'Helper']) {
|
|
expect(tester.widget<Text>(find.text(label)).style?.color, linkColor);
|
|
}
|
|
expect(
|
|
tester.widget<BuzzAgentIcon>(find.byType(BuzzAgentIcon)).color,
|
|
linkColor,
|
|
);
|
|
final link = tester.widget<Text>(
|
|
find.byWidgetPredicate(
|
|
(w) => w is Text && w.textSpan?.toPlainText() == 'Website',
|
|
),
|
|
);
|
|
expect(link.textSpan?.style?.color, linkColor);
|
|
await tester.tap(find.text('Alice'));
|
|
expect(tapped, 'person');
|
|
await tester.tap(find.text('Helper'));
|
|
expect(tapped, 'agent');
|
|
});
|
|
}
|
|
|
|
for (final content in [
|
|
'- screenshots:\n \n explanation',
|
|
'1. screenshots:\n \n explanation',
|
|
'> screenshots:\n> \n> explanation',
|
|
'> screenshots:\n\nexplanation',
|
|
]) {
|
|
testWidgets('nested media retains its Markdown block: $content', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_testable(MessageContent(content: content, bubble: true)),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(bubbles, findsOneWidget);
|
|
final markdown = tester.widget<GptMarkdown>(find.byType(GptMarkdown));
|
|
expect(markdown.data, content);
|
|
final media = find.byKey(
|
|
const ValueKey(
|
|
'message-media-image-preview:https://example.com/result.png',
|
|
),
|
|
);
|
|
expect(find.descendant(of: bubbles, matching: media), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
|
|
testWidgets(
|
|
'image corners remain uniform throughout the conversation group',
|
|
(tester) async {
|
|
for (final grouped in [false, true]) {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
MessageContent(
|
|
content: '',
|
|
bubble: true,
|
|
bubbleStart: !grouped,
|
|
bubbleEnd: !grouped,
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final frame = tester.widget<Container>(
|
|
find.byKey(
|
|
const ValueKey(
|
|
'message-media-image-preview:https://example.com/photo.png',
|
|
),
|
|
),
|
|
);
|
|
final corners =
|
|
(frame.decoration! as BoxDecoration).borderRadius! as BorderRadius;
|
|
expect(corners.topLeft.x, Radii.container);
|
|
expect(corners.bottomLeft.x, Radii.container);
|
|
expect(corners.topRight.x, Radii.container);
|
|
expect(corners.bottomRight.x, Radii.container);
|
|
}
|
|
},
|
|
);
|
|
|
|
testWidgets('photo gallery stays outside its caption bubble', (tester) async {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
const MessageContent(
|
|
content:
|
|
'Photos\n\n',
|
|
bubble: true,
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final gallery = find.byKey(const ValueKey('message-media-stack'));
|
|
expect(gallery, findsOneWidget);
|
|
expect(bubbles, findsOneWidget);
|
|
expect(find.descendant(of: bubbles, matching: gallery), findsNothing);
|
|
expect(
|
|
tester.getTopLeft(gallery).dy,
|
|
greaterThanOrEqualTo(tester.getBottomLeft(bubbles).dy),
|
|
);
|
|
});
|
|
|
|
testWidgets('neutral bubbles hug short text and distinguish own messages', (
|
|
tester,
|
|
) async {
|
|
for (final own in [false, true]) {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
MessageContent(content: 'Hello', bubble: true, ownMessage: own),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(bubbles, findsOneWidget);
|
|
expect(tester.getSize(bubbles).width, lessThan(160));
|
|
final decoration = tester.widget<LocalSendBubbleSurface>(
|
|
find.descendant(
|
|
of: bubbles,
|
|
matching: find.byType(LocalSendBubbleSurface),
|
|
),
|
|
);
|
|
expect(decoration.color, isNotNull);
|
|
expect(
|
|
find.descendant(of: bubbles, matching: _findRich('Hello')),
|
|
findsWidgets,
|
|
);
|
|
}
|
|
});
|
|
|
|
testWidgets('attachments stay outside bubbles and text order is preserved', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
const MessageContent(
|
|
content:
|
|
// The escaped destination must still match its plain imeta URL.
|
|
'Before\n\n[file.txt](https://example.com/file\\_a.txt)\n\nAfter',
|
|
tags: [
|
|
['imeta', 'url https://example.com/file_a.txt', 'm text/plain'],
|
|
],
|
|
bubble: true,
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(bubbles, findsNWidgets(2));
|
|
expect(
|
|
find.descendant(of: bubbles, matching: _findRich('file.txt')),
|
|
findsNothing,
|
|
);
|
|
expect(
|
|
tester.getTopLeft(_findRich('Before')).dy,
|
|
lessThan(tester.getTopLeft(_findRich('file.txt')).dy),
|
|
);
|
|
expect(
|
|
tester.getTopLeft(_findRich('file.txt')).dy,
|
|
lessThan(tester.getTopLeft(_findRich('After')).dy),
|
|
);
|
|
});
|
|
|
|
testWidgets('fenced attachment examples remain in the text bubble', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
const MessageContent(
|
|
content: '```text\n\n```',
|
|
bubble: true,
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(bubbles, findsOneWidget);
|
|
expect(
|
|
find.descendant(
|
|
of: bubbles,
|
|
matching: _findRich(''),
|
|
),
|
|
findsWidgets,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('bubble text reflows at narrow width and large text', (
|
|
tester,
|
|
) async {
|
|
_setSurfaceSize(tester, const Size(320, 800));
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
await tester.pumpWidget(
|
|
_testable(
|
|
MediaQuery(
|
|
data: const MediaQueryData(
|
|
size: Size(320, 800),
|
|
textScaler: TextScaler.linear(2),
|
|
),
|
|
child: const SizedBox(
|
|
width: 230,
|
|
child: MessageContent(
|
|
content:
|
|
'A longer message that wraps across multiple lines without clipping.',
|
|
bubble: true,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getSize(bubbles).width, lessThanOrEqualTo(230));
|
|
expect(tester.getSize(bubbles).height, greaterThan(80));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
|
|
void editedMarkerTests() {
|
|
Iterable<String> plainTexts(WidgetTester tester) => tester
|
|
.widgetList<RichText>(find.byType(RichText))
|
|
.map((text) => text.text.toPlainText());
|
|
TextSpan? markerSpan(WidgetTester tester) {
|
|
TextSpan? found;
|
|
for (final text in tester.widgetList<RichText>(find.byType(RichText))) {
|
|
text.text.visitChildren((span) {
|
|
if (span is TextSpan && span.text == '(edited)') found = span;
|
|
return found == null;
|
|
});
|
|
}
|
|
return found;
|
|
}
|
|
|
|
testWidgets('an edit is marked after the body, never inside other text', (
|
|
tester,
|
|
) async {
|
|
Future<void> show(String content, {bool edited = true, bool own = false}) =>
|
|
tester
|
|
.pumpWidget(
|
|
_testable(
|
|
MessageContent(
|
|
content: content,
|
|
bubble: true,
|
|
edited: edited,
|
|
ownMessage: own,
|
|
),
|
|
),
|
|
)
|
|
.then((_) => tester.pumpAndSettle());
|
|
|
|
// Prose: inline after the last line, in the muted metadata colour.
|
|
await show('First\n\nHi how are ya.');
|
|
expect(
|
|
plainTexts(tester),
|
|
anyElement(endsWith('\nHi how are ya. (edited)')),
|
|
);
|
|
final context = tester.element(find.byType(MessageContent));
|
|
expect(markerSpan(tester)?.style?.color, context.colors.onSurfaceVariant);
|
|
|
|
// Your own accent bubble draws it in the bubble's ink.
|
|
await show('Mine', own: true);
|
|
expect(plainTexts(tester), contains('Mine (edited)'));
|
|
expect(
|
|
markerSpan(tester)?.style?.color,
|
|
ChatColors.of(tester.element(find.byType(MessageContent))).foreground,
|
|
);
|
|
|
|
// Bodies the slot could restyle render exactly as unedited, plus the
|
|
// marker on its own line inside the same text bubble.
|
|
for (final content in [
|
|
'```npm install```',
|
|
'Run this:\n```npm install```',
|
|
'Intro\n\n```\ncode\n```',
|
|
'````\ncode\n````',
|
|
'```\nunclosed',
|
|
'| a | b |\n| - | - |\n| 1 | 2 |',
|
|
'Above\n\n---',
|
|
'ok\n-',
|
|
'ok\n#',
|
|
'todo\n[x]',
|
|
'# Heading',
|
|
'ok\n\nhttps://example.com/file.pdf',
|
|
]) {
|
|
await show(content, edited: false);
|
|
final unedited = plainTexts(tester).toList();
|
|
await show(content);
|
|
expect(plainTexts(tester), [...unedited, '(edited)'], reason: content);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const ValueKey('message-text-bubble-0')),
|
|
matching: find.text('(edited)'),
|
|
),
|
|
findsOneWidget,
|
|
reason: content,
|
|
);
|
|
}
|
|
|
|
// An escaped bracket is text, not display math, so the marker joins it.
|
|
await show(r'see \[x\]');
|
|
expect(plainTexts(tester), contains('see [x] (edited)'));
|
|
|
|
// Inside an unclosed <u> or a heading the marker keeps its own style.
|
|
await show('see <u>this');
|
|
expect(markerSpan(tester)?.style?.decoration, TextDecoration.none);
|
|
|
|
// Trailing media: the marker follows it, outside every text bubble.
|
|
await show('');
|
|
expect(find.text('(edited)'), findsOneWidget);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget.key is ValueKey<String> &&
|
|
(widget.key! as ValueKey<String>).value.startsWith(
|
|
'message-text-bubble-',
|
|
),
|
|
),
|
|
matching: find.text('(edited)'),
|
|
),
|
|
findsNothing,
|
|
);
|
|
|
|
// Unedited bodies stay unmarked. An authored slot character is drawn as
|
|
// written, and only an edit adds the marker, on its own line.
|
|
bool shows(String text) => tester
|
|
.widgetList<RichText>(find.byType(RichText))
|
|
.any((rich) => rich.text.toPlainText().contains(text));
|
|
await show('Plain', edited: false);
|
|
expect(markerSpan(tester), isNull);
|
|
await show('Sneaky $editedSlot', edited: false);
|
|
expect(shows('Sneaky $editedSlot'), isTrue);
|
|
expect(markerSpan(tester), isNull);
|
|
await show('Sneaky $editedSlot');
|
|
expect(shows('Sneaky $editedSlot'), isTrue);
|
|
expect(find.text('(edited)'), findsOneWidget);
|
|
// Also when the authored slot is in an earlier part of the message.
|
|
await show('Sneaky $editedSlot\n\nafter');
|
|
expect(shows('Sneaky $editedSlot'), isTrue);
|
|
expect(find.text('(edited)'), findsOneWidget);
|
|
});
|
|
}
|