feat(app): chat sections are clear collapsible dividers; closed chats start collapsed
This commit is contained in:
@@ -134,9 +134,7 @@ void main() {
|
||||
|
||||
expect(gateway.sent('chat_rename'), isEmpty);
|
||||
expect(
|
||||
find.text(
|
||||
'Usage: /rename <title> — renames this session.',
|
||||
),
|
||||
find.text('Usage: /rename <title> — renames this session.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -44,28 +44,32 @@ void main() {
|
||||
expect(chatFormAnswerError(fields, {'note': 'ok', 'count': 5}), '');
|
||||
});
|
||||
|
||||
test('integer input becomes an int, including decimal and exponent forms', () {
|
||||
final field = <String, dynamic>{'key': 'count', 'type': 'integer'};
|
||||
expect(chatFormFieldValue(field, '1.0'), isA<int>());
|
||||
expect(chatFormFieldValue(field, '1.0'), 1);
|
||||
expect(chatFormFieldValue(field, '1e3'), 1000);
|
||||
expect(chatFormFieldValue(field, '1.5'), 1.5);
|
||||
expect((chatFormFieldValue(field, 'nope')! as num).isNaN, isTrue);
|
||||
expect(chatFormFieldValue({'type': 'number'}, '1e3'), 1000.0);
|
||||
test(
|
||||
'integer input becomes an int, including decimal and exponent forms',
|
||||
() {
|
||||
final field = <String, dynamic>{'key': 'count', 'type': 'integer'};
|
||||
expect(chatFormFieldValue(field, '1.0'), isA<int>());
|
||||
expect(chatFormFieldValue(field, '1.0'), 1);
|
||||
expect(chatFormFieldValue(field, '1e3'), 1000);
|
||||
expect(chatFormFieldValue(field, '1.5'), 1.5);
|
||||
expect((chatFormFieldValue(field, 'nope')! as num).isNaN, isTrue);
|
||||
expect(chatFormFieldValue({'type': 'number'}, '1e3'), 1000.0);
|
||||
|
||||
final fields = [field];
|
||||
expect(
|
||||
chatVisibleFormAnswers(
|
||||
fields,
|
||||
{'count': chatFormFieldValue(field, '1.0')},
|
||||
),
|
||||
{'count': 1},
|
||||
);
|
||||
expect(
|
||||
chatFormAnswerError(fields, {'count': chatFormFieldValue(field, '1.0')}),
|
||||
'',
|
||||
);
|
||||
});
|
||||
final fields = [field];
|
||||
expect(
|
||||
chatVisibleFormAnswers(fields, {
|
||||
'count': chatFormFieldValue(field, '1.0'),
|
||||
}),
|
||||
{'count': 1},
|
||||
);
|
||||
expect(
|
||||
chatFormAnswerError(fields, {
|
||||
'count': chatFormFieldValue(field, '1.0'),
|
||||
}),
|
||||
'',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('a malformed pattern is reported with the documented wording', () {
|
||||
final fields = [
|
||||
@@ -84,9 +88,12 @@ void main() {
|
||||
// An unparseable server pattern constrains nothing, like a browser ignoring
|
||||
// an invalid `pattern` attribute.
|
||||
expect(
|
||||
chatFormAnswerError([
|
||||
{'key': 'code', 'type': 'string', 'pattern': '('},
|
||||
], {'code': 'anything'}),
|
||||
chatFormAnswerError(
|
||||
[
|
||||
{'key': 'code', 'type': 'string', 'pattern': '('},
|
||||
],
|
||||
{'code': 'anything'},
|
||||
),
|
||||
'',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -253,9 +253,7 @@ void main() {
|
||||
) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(form: question(), onSubmit: (_, _) async {}),
|
||||
),
|
||||
scrollHost(ChatQuestionCard(form: question(), onSubmit: (_, _) async {})),
|
||||
);
|
||||
final node = tester.getSemantics(
|
||||
find.byKey(const ValueKey<String>('chat-question-input-note')),
|
||||
@@ -296,65 +294,67 @@ void main() {
|
||||
expect(sent!['count'], isA<int>());
|
||||
});
|
||||
|
||||
testWidgets('decline and cancel send their recorded actions with no answers', (
|
||||
tester,
|
||||
) async {
|
||||
final actions = <String>[];
|
||||
final answers = <Map<String, dynamic>>[];
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: question(),
|
||||
onSubmit: (sent, action) async {
|
||||
actions.add(action);
|
||||
answers.add(sent);
|
||||
},
|
||||
testWidgets(
|
||||
'decline and cancel send their recorded actions with no answers',
|
||||
(tester) async {
|
||||
final actions = <String>[];
|
||||
final answers = <Map<String, dynamic>>[];
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: question(),
|
||||
onSubmit: (sent, action) async {
|
||||
actions.add(action);
|
||||
answers.add(sent);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Decline'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cancel question'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(actions, ['decline', 'cancel']);
|
||||
expect(answers, [<String, dynamic>{}, <String, dynamic>{}]);
|
||||
});
|
||||
);
|
||||
await tester.tap(find.text('Decline'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cancel question'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(actions, ['decline', 'cancel']);
|
||||
expect(answers, [<String, dynamic>{}, <String, dynamic>{}]);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an all-external form confirms completion without field answers', (
|
||||
tester,
|
||||
) async {
|
||||
Map<String, dynamic>? sent;
|
||||
String? action;
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: {
|
||||
'id': 'form-external',
|
||||
'title': 'Open the form',
|
||||
'actions': ['accept'],
|
||||
'fields': [
|
||||
{
|
||||
'key': 'form',
|
||||
'title': 'External form',
|
||||
'type': 'external',
|
||||
'url': 'https://example.com/complete',
|
||||
},
|
||||
],
|
||||
},
|
||||
onSubmit: (answers, next) async {
|
||||
sent = answers;
|
||||
action = next;
|
||||
},
|
||||
testWidgets(
|
||||
'an all-external form confirms completion without field answers',
|
||||
(tester) async {
|
||||
Map<String, dynamic>? sent;
|
||||
String? action;
|
||||
await tester.pumpWidget(
|
||||
scrollHost(
|
||||
ChatQuestionCard(
|
||||
form: {
|
||||
'id': 'form-external',
|
||||
'title': 'Open the form',
|
||||
'actions': ['accept'],
|
||||
'fields': [
|
||||
{
|
||||
'key': 'form',
|
||||
'title': 'External form',
|
||||
'type': 'external',
|
||||
'url': 'https://example.com/complete',
|
||||
},
|
||||
],
|
||||
},
|
||||
onSubmit: (answers, next) async {
|
||||
sent = answers;
|
||||
action = next;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('Confirm completion'), findsOneWidget);
|
||||
expect(find.text('https://example.com/complete'), findsOneWidget);
|
||||
await tester.tap(find.text('Confirm completion'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sent, isEmpty);
|
||||
expect(action, 'accept');
|
||||
});
|
||||
);
|
||||
expect(find.text('Confirm completion'), findsOneWidget);
|
||||
expect(find.text('https://example.com/complete'), findsOneWidget);
|
||||
await tester.tap(find.text('Confirm completion'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(sent, isEmpty);
|
||||
expect(action, 'accept');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an unsupported external URL shows the web alert wording', (
|
||||
tester,
|
||||
@@ -405,7 +405,12 @@ void main() {
|
||||
'resolved': true,
|
||||
'answers': {'enabled': true, 'extra': 'kept'},
|
||||
'fields': [
|
||||
{'key': 'enabled', 'title': '', 'description': '', 'type': 'boolean'},
|
||||
{
|
||||
'key': 'enabled',
|
||||
'title': '',
|
||||
'description': '',
|
||||
'type': 'boolean',
|
||||
},
|
||||
],
|
||||
},
|
||||
onSubmit: (_, _) async {},
|
||||
|
||||
@@ -71,10 +71,7 @@ void main() {
|
||||
|
||||
group('arrival count', () {
|
||||
test('counts only messages after the release point', () {
|
||||
expect(
|
||||
chatNewMessageCount(['m1', 'm2', 'm3'], 'm2'),
|
||||
1,
|
||||
);
|
||||
expect(chatNewMessageCount(['m1', 'm2', 'm3'], 'm2'), 1);
|
||||
expect(
|
||||
chatNewMessageCount(['older', 'm1', 'm2', 'live', 'newer'], 'm2'),
|
||||
2,
|
||||
@@ -98,22 +95,13 @@ void main() {
|
||||
|
||||
group('restore', () {
|
||||
test('no saved position lands on the newest end', () {
|
||||
expect(
|
||||
chatRestoreOffset(savedOffset: null, maxScrollExtent: 640),
|
||||
640,
|
||||
);
|
||||
expect(chatRestoreOffset(savedOffset: null, maxScrollExtent: 640), 640);
|
||||
});
|
||||
|
||||
test('a saved position is kept within the current extent', () {
|
||||
expect(
|
||||
chatRestoreOffset(savedOffset: 120, maxScrollExtent: 640),
|
||||
120,
|
||||
);
|
||||
expect(chatRestoreOffset(savedOffset: 120, maxScrollExtent: 640), 120);
|
||||
expect(chatRestoreOffset(savedOffset: 0, maxScrollExtent: 640), 0);
|
||||
expect(
|
||||
chatRestoreOffset(savedOffset: 900, maxScrollExtent: 640),
|
||||
640,
|
||||
);
|
||||
expect(chatRestoreOffset(savedOffset: 900, maxScrollExtent: 640), 640);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -44,15 +44,12 @@ void main() {
|
||||
});
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(controller.permissionFrames, hasLength(ChatThreadCards.settledLimit + 1));
|
||||
expect(
|
||||
controller.permissionFrames.first['request_id'],
|
||||
'req-5',
|
||||
);
|
||||
expect(
|
||||
controller.permissionFrames.last['request_id'],
|
||||
'req-pending',
|
||||
controller.permissionFrames,
|
||||
hasLength(ChatThreadCards.settledLimit + 1),
|
||||
);
|
||||
expect(controller.permissionFrames.first['request_id'], 'req-5');
|
||||
expect(controller.permissionFrames.last['request_id'], 'req-pending');
|
||||
});
|
||||
|
||||
test('settled forms are bounded while the pending one is kept', () async {
|
||||
@@ -75,7 +72,10 @@ void main() {
|
||||
});
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(controller.questionForms, hasLength(ChatThreadCards.settledLimit + 1));
|
||||
expect(
|
||||
controller.questionForms,
|
||||
hasLength(ChatThreadCards.settledLimit + 1),
|
||||
);
|
||||
expect(controller.questionForms.first['id'], 'form-5');
|
||||
expect(controller.questionForms.last['id'], 'form-pending');
|
||||
});
|
||||
|
||||
@@ -35,9 +35,7 @@ JsonMap tallPage() => chatPage([
|
||||
]);
|
||||
|
||||
ScrollController transcriptScroll(WidgetTester tester) =>
|
||||
tester
|
||||
.widget<ListView>(find.byKey(const Key('chat-thread-s')))
|
||||
.controller!;
|
||||
tester.widget<ListView>(find.byKey(const Key('chat-thread-s'))).controller!;
|
||||
|
||||
void main() {
|
||||
testWidgets('a streaming transcript stays pinned to its newest end', (
|
||||
@@ -62,7 +60,9 @@ void main() {
|
||||
|
||||
// A new message and further deltas grow the turn; every frame keeps the
|
||||
// newest end visible without an animation the operator has to chase.
|
||||
gateway.emitEvent(chatTextFrame('One streamed paragraph. ', messageId: 'live'));
|
||||
gateway.emitEvent(
|
||||
chatTextFrame('One streamed paragraph. ', messageId: 'live'),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
gateway.emitEvent(chatTextFrame('And another delta. ', messageId: 'live'));
|
||||
@@ -115,19 +115,15 @@ void main() {
|
||||
// The operator's position is not moved by an arrival; only the
|
||||
// control's count changes.
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(
|
||||
find.text('Jump to latest · 1 new message'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Jump to latest · 1 new message'), findsOneWidget);
|
||||
|
||||
gateway.emitEvent(chatTextFrame('A second answer. ', messageId: 'live-2'));
|
||||
gateway.emitEvent(
|
||||
chatTextFrame('A second answer. ', messageId: 'live-2'),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(scroll.position.pixels, closeTo(releasedAt, 0.5));
|
||||
expect(
|
||||
find.text('Jump to latest · 2 new messages'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Jump to latest · 2 new messages'), findsOneWidget);
|
||||
|
||||
if (cupertino) {
|
||||
// The affordance is a standard Cupertino control; no Material
|
||||
|
||||
@@ -184,7 +184,9 @@ void main() {
|
||||
]) {
|
||||
expect(find.text(body), findsOneWidget, reason: body);
|
||||
}
|
||||
Navigator.of(tester.element(find.text('NEWEST folded reasoning body.'))).pop();
|
||||
Navigator.of(
|
||||
tester.element(find.text('NEWEST folded reasoning body.')),
|
||||
).pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Load older'),
|
||||
|
||||
Reference in New Issue
Block a user