Paper design: warm paper, serif reading text and a typeset transcript
Adds the Paper design and generalises design tokens (transcript, composer, selected-row styles, reading type, panel fill, chat colour saturation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
Widget _thread(ComposerBarGateway gateway, AppDesign design) => MaterialApp(
|
||||
theme: design.light(),
|
||||
home: Scaffold(
|
||||
body: ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
session: const {'id': 's', 'directory': '/Users/ada/repos/tank'},
|
||||
syncToken: 0,
|
||||
onBack: () {},
|
||||
drafts: MemoryChatDraftStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('Paper: the composer is an underlined writing area, not a '
|
||||
'pill, and its rule takes the accent on focus', (tester) async {
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(_thread(gateway, AppDesign.paper));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('chat-composer-pill')), findsNothing);
|
||||
final area = find.byKey(const Key('chat-composer-underline'));
|
||||
expect(area, findsOneWidget);
|
||||
for (final key in [
|
||||
'chat-composer-attach',
|
||||
'chat-composer-field',
|
||||
'chat-composer-primary',
|
||||
]) {
|
||||
expect(
|
||||
find.descendant(of: area, matching: find.byKey(Key(key))),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
final scheme = Theme.of(tester.element(area)).colorScheme;
|
||||
Color? rule() =>
|
||||
(tester
|
||||
.widget<AnimatedContainer>(
|
||||
find.byKey(const Key('chat-composer-rule')),
|
||||
)
|
||||
.decoration
|
||||
as BoxDecoration?)
|
||||
?.color;
|
||||
expect(rule(), scheme.outline);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-composer-field')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(rule(), scheme.primary);
|
||||
});
|
||||
|
||||
testWidgets('Default keeps the pill', (tester) async {
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(_thread(gateway, AppDesign.standard));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-composer-pill')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-composer-underline')), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_activity_note.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_editorial_note.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_quote.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart';
|
||||
import 'package:pipelines_app/ui/text/monospace.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/paper_fonts.dart';
|
||||
|
||||
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
|
||||
|
||||
final JsonMap _operator = _row({
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Fix the Windows paths.'},
|
||||
],
|
||||
});
|
||||
|
||||
JsonMap _tool(String id, String name, String status) => {
|
||||
'type': 'tool',
|
||||
'id': id,
|
||||
'name': name,
|
||||
'state': {
|
||||
'status': status,
|
||||
'input': {'command': 'go test ./...'},
|
||||
if (status == 'error') 'error': {'message': 'exit status 1'},
|
||||
},
|
||||
};
|
||||
|
||||
final JsonMap _agent = _row({
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
_tool('t1', 'Bash', 'completed'),
|
||||
_tool('t2', 'Read', 'completed'),
|
||||
_tool('t3', 'Bash', 'completed'),
|
||||
{
|
||||
'type': 'text',
|
||||
'text':
|
||||
'## Cause\n\nFixed the separators.\n\n'
|
||||
'- one\n- two\n\n```go\nreturn filepath.Join(a, b)\n```',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
final JsonMap _followup = _row({
|
||||
'id': 'f1',
|
||||
'role': 'user',
|
||||
'origin': 'followup',
|
||||
'client': 'Agent follow-up',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Check whether run 42 finished.'},
|
||||
],
|
||||
});
|
||||
|
||||
Widget _host(AppDesign design, List<JsonMap> rows) => MaterialApp(
|
||||
theme: design.light(),
|
||||
home: Scaffold(
|
||||
body: ListView(
|
||||
children: [
|
||||
for (final row in rows)
|
||||
ChatMessageView(row: row, textBuilder: chatMarkdownText),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
double _left(WidgetTester tester, Finder finder) =>
|
||||
tester.getTopLeft(finder).dx;
|
||||
|
||||
/// The style the text containing [text] is laid out in: the root of the
|
||||
/// first [RichText] that draws it.
|
||||
TextStyle _style(WidgetTester tester, String text) {
|
||||
final rich = tester
|
||||
.widgetList<RichText>(find.byType(RichText))
|
||||
.firstWhere((rich) => rich.text.toPlainText().contains(text));
|
||||
return rich.text.style ?? const TextStyle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('Paper: the operator turn is an indented block quote with a '
|
||||
'small-caps label and a rule, not a bubble', (tester) async {
|
||||
await tester.pumpWidget(_host(AppDesign.paper, [_operator, _agent]));
|
||||
final quote = find.byType(PaperQuote);
|
||||
expect(quote, findsOneWidget);
|
||||
expect(find.byType(TerminalPromptLine), findsNothing);
|
||||
final label = find.byKey(const Key('chat-paper-quote-label'));
|
||||
expect(tester.widget<Text>(label).data, 'YOU');
|
||||
expect(tester.widget<Text>(label).style?.fontStyle, FontStyle.italic);
|
||||
// Indented past the answer's text edge, not on the trailing side.
|
||||
final words = find.text('Fix the Windows paths.');
|
||||
final answer = find.text('Fixed the separators.');
|
||||
expect(_left(tester, words), greaterThan(_left(tester, answer)));
|
||||
expect(_left(tester, words) - _left(tester, answer), lessThan(40));
|
||||
// The rule runs down the quote's leading edge.
|
||||
final rule = tester.widget<DecoratedBox>(
|
||||
find.descendant(of: quote, matching: find.byType(DecoratedBox)).first,
|
||||
);
|
||||
final side =
|
||||
((rule.decoration as BoxDecoration).border! as BorderDirectional).start;
|
||||
expect(side.width, paperQuoteRule);
|
||||
});
|
||||
|
||||
testWidgets('Paper: answers are serif prose, code keeps the monospace', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host(AppDesign.paper, [_agent]));
|
||||
final prose = _style(tester, 'Fixed the separators.');
|
||||
expect(prose.fontFamily, paperSerifFamily);
|
||||
expect(prose.height, closeTo(1.55, 0.01));
|
||||
final heading = _style(tester, 'Cause');
|
||||
expect(heading.fontFamily, paperSerifFamily);
|
||||
expect(heading.fontWeight, FontWeight.w600);
|
||||
expect(heading.fontSize, greaterThan(prose.fontSize!));
|
||||
final code = _style(tester, 'return filepath.Join(a, b)');
|
||||
expect(code.fontFamily, appMonospaceFamily);
|
||||
expect(code.fontSize, lessThan(prose.fontSize!));
|
||||
expect(find.text('•'), findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets('Paper: tool activity is a muted marginal note naming the '
|
||||
'tools, and it still opens the details', (tester) async {
|
||||
await tester.pumpWidget(_host(AppDesign.paper, [_agent]));
|
||||
expect(find.byType(TerminalActivityRows), findsNothing);
|
||||
final note = find.byType(PaperActivityNote);
|
||||
expect(note, findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: note,
|
||||
matching: find.textContaining('Used 3 tools — Bash, Read'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final text = tester.widget<Text>(
|
||||
find.descendant(of: note, matching: find.byType(Text)),
|
||||
);
|
||||
expect(text.style?.fontStyle, FontStyle.italic);
|
||||
await tester.tap(note);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Activity details'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Paper: a follow-up is a small italic editorial note', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host(AppDesign.paper, [_followup]));
|
||||
expect(find.byType(PaperEditorialNote), findsOneWidget);
|
||||
final header = find.byKey(const Key('chat-automated-prompt-header'));
|
||||
final text = tester.widget<Text>(header).textSpan!.toPlainText();
|
||||
expect(text, startsWith('FOLLOW-UP FROM AGENT'));
|
||||
// The body is selectable text in the note's ambient style.
|
||||
final body = DefaultTextStyle.of(
|
||||
tester.element(find.text('Check whether run 42 finished.')),
|
||||
).style;
|
||||
expect(body.fontStyle, FontStyle.italic);
|
||||
// No card: the note has no Material fill.
|
||||
final note = tester.widget<Material>(
|
||||
find.byKey(const Key('chat-automated-prompt')),
|
||||
);
|
||||
expect(note.type, MaterialType.transparency);
|
||||
});
|
||||
|
||||
testWidgets('Default is unchanged: a trailing bubble, no Paper pieces', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_host(AppDesign.standard, [_operator, _agent, _followup]),
|
||||
);
|
||||
expect(find.byType(PaperQuote), findsNothing);
|
||||
expect(find.byType(PaperActivityNote), findsNothing);
|
||||
expect(find.byType(PaperEditorialNote), findsNothing);
|
||||
expect(find.byType(ChatUserBubble), findsOneWidget);
|
||||
final bubble = find.byType(ChatUserBubble);
|
||||
final answer = find.text('Fixed the separators.');
|
||||
expect(_left(tester, bubble), greaterThan(_left(tester, answer)));
|
||||
expect(
|
||||
_style(tester, 'Fixed the separators.').fontFamily,
|
||||
isNot(paperSerifFamily),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Terminal is unchanged: prompt line and tool rows', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host(AppDesign.terminal, [_operator, _agent]));
|
||||
expect(find.byType(TerminalPromptLine), findsOneWidget);
|
||||
expect(find.byType(TerminalActivityRows), findsOneWidget);
|
||||
expect(find.byType(PaperQuote), findsNothing);
|
||||
expect(find.byType(PaperActivityNote), findsNothing);
|
||||
expect(
|
||||
_style(tester, 'Fixed the separators.').fontFamily,
|
||||
appMonospaceFamily,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -91,4 +91,27 @@ void main() {
|
||||
expect(find.text(designSaveFailedText), findsOneWidget);
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
});
|
||||
|
||||
testWidgets('choosing Paper stores it, restyles the page live and is '
|
||||
'restored on the next launch', (tester) async {
|
||||
final store = MemoryAppDesignStore();
|
||||
final designs = AppDesignController(store: store);
|
||||
await _pump(tester, designs);
|
||||
|
||||
// Every row shows its design's swatch.
|
||||
expect(
|
||||
find.byType(DesignSwatchPreview),
|
||||
findsNWidgets(AppDesign.values.length),
|
||||
);
|
||||
expect(find.text(AppDesign.paper.description), findsOneWidget);
|
||||
await tester.tap(find.text(AppDesign.paper.label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(store.id, 'paper');
|
||||
expect(designs.design, AppDesign.paper);
|
||||
expect(_tokens(tester).transcript, TranscriptStyle.manuscript);
|
||||
|
||||
final next = AppDesignController(store: MemoryAppDesignStore(store.id));
|
||||
await next.restore();
|
||||
expect(next.design, AppDesign.paper);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user