Identify mobile chat peeks and expose switching and resize affordances
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_pane_presentation.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_pane_backdrop.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_pane_switch_motion.dart';
|
||||
@@ -165,7 +166,11 @@ void main() {
|
||||
expect(wrapped.top, greaterThan(_peekTop));
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||
closeTo((800 - 6) * .2, .5),
|
||||
closeTo(
|
||||
(800 - 6) * .2 -
|
||||
tester.getSize(find.byType(ChatPeekHeader).first).height,
|
||||
.5,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('a'))).height,
|
||||
@@ -371,7 +376,11 @@ void main() {
|
||||
final peek = tester.getRect(rect(a));
|
||||
expect(
|
||||
scrolls['a']!.position.viewportDimension,
|
||||
closeTo(peek.height, .5),
|
||||
closeTo(
|
||||
peek.height -
|
||||
tester.getSize(find.byType(ChatPeekHeader).first).height,
|
||||
.5,
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const ValueKey('bar-a')), findsNothing);
|
||||
await tester.dragFrom(peek.center, const Offset(0, -90));
|
||||
@@ -394,7 +403,11 @@ void main() {
|
||||
expect(scrolls['a']!.offset, 300);
|
||||
expect(
|
||||
scrolls['a']!.position.viewportDimension,
|
||||
closeTo(peek.height, .5),
|
||||
closeTo(
|
||||
peek.height -
|
||||
tester.getSize(find.byType(ChatPeekHeader).first).height,
|
||||
.5,
|
||||
),
|
||||
);
|
||||
expect(pressed, 0);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_mobile_peek_divider.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
|
||||
class _Thread extends StatefulWidget {
|
||||
const _Thread({super.key});
|
||||
@override
|
||||
State<_Thread> createState() => _ThreadState();
|
||||
}
|
||||
|
||||
class _ThreadState extends State<_Thread> {
|
||||
final scroll = ScrollController();
|
||||
final draft = TextEditingController(text: 'Keep this draft');
|
||||
@override
|
||||
void dispose() {
|
||||
scroll.dispose();
|
||||
draft.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Material(
|
||||
child: ListView(
|
||||
controller: scroll,
|
||||
children: [
|
||||
TextField(controller: draft),
|
||||
for (var i = 0; i < 40; i++)
|
||||
SizedBox(height: 48, child: Text('Line $i')),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final height in [32.0, 48.0]) {
|
||||
testWidgets(
|
||||
'peek title and switch fit $height height at 2x ($cupertino)',
|
||||
(tester) async {
|
||||
var activated = 0;
|
||||
Size? bodySize;
|
||||
final viewport = MediaQuery(
|
||||
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 320,
|
||||
height: height,
|
||||
child: ChatMobilePaneViewport(
|
||||
peek: true,
|
||||
active: false,
|
||||
barReveal: const AlwaysStoppedAnimation(0),
|
||||
onActivate: () => activated++,
|
||||
label: 'A long working project name',
|
||||
paneId: 'first',
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
bodySize = constraints.biggest;
|
||||
return const SizedBox.expand();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: viewport))
|
||||
: MaterialApp(home: Scaffold(body: viewport)),
|
||||
);
|
||||
expect(find.text('A long working project name'), findsOneWidget);
|
||||
expect(find.text('Switch'), findsOneWidget);
|
||||
final headerSize = tester.getSize(find.byType(ChatPeekHeader));
|
||||
expect(headerSize.height, lessThanOrEqualTo(height));
|
||||
expect(bodySize!.height, closeTo(height - headerSize.height, .01));
|
||||
await tester.tap(find.text('Switch'));
|
||||
await tester.pump();
|
||||
expect(activated, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
testWidgets('peek header reserves real body space and keeps reading state', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final panes = ChatWorkspaceController()..open('Project alpha');
|
||||
final first = panes.activePaneId!;
|
||||
panes.splitActive('Project beta', ChatSplitAxis.horizontal);
|
||||
final second = panes.activePaneId!;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(disableAnimations: true),
|
||||
child: ChatWorkspace(
|
||||
controller: panes,
|
||||
singlePane: true,
|
||||
mobilePeeks: true,
|
||||
paneTitle: (pane) => pane.sessionId,
|
||||
paneBuilder: (_, pane, active) =>
|
||||
_Thread(key: ValueKey(pane.sessionId)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final state = tester.state<_ThreadState>(
|
||||
find.byKey(const ValueKey('Project alpha')),
|
||||
);
|
||||
final peek = tester.getRect(find.byKey(ValueKey('chat-workspace-$first')));
|
||||
final header = tester.getRect(find.byType(ChatPeekHeader));
|
||||
expect(header.top, peek.top);
|
||||
expect(
|
||||
state.scroll.position.viewportDimension,
|
||||
closeTo(peek.height - header.height, .01),
|
||||
);
|
||||
state.scroll.jumpTo(state.scroll.position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getRect(find.text('Line 39').first).bottom,
|
||||
closeTo(peek.bottom, .5),
|
||||
);
|
||||
state.scroll.jumpTo(300);
|
||||
await tester.pump();
|
||||
await tester.tap(find.text('Switch'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(panes.activePaneId, first);
|
||||
expect(
|
||||
tester.state(find.byKey(const ValueKey('Project alpha'))),
|
||||
same(state),
|
||||
);
|
||||
expect(state.draft.text, 'Keep this draft');
|
||||
expect(state.scroll.offset, 300);
|
||||
panes.activate(second);
|
||||
await tester.pumpAndSettle();
|
||||
expect(state.scroll.offset, 300);
|
||||
expect(find.byTooltip('Drag to resize inactive chat'), findsOneWidget);
|
||||
await tester.drag(find.byType(ChatMobilePeekDivider), const Offset(0, 500));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getSize(find.byKey(ValueKey('chat-workspace-$first'))).height,
|
||||
48,
|
||||
);
|
||||
expect(
|
||||
state.scroll.position.viewportDimension,
|
||||
closeTo(48 - header.height, .01),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
panes.dispose();
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
@@ -142,7 +143,11 @@ void main() {
|
||||
expect(tester.getRect(rect(b)).top, _peekTop);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||
closeTo((800 - 6) * .2, .01),
|
||||
closeTo(
|
||||
(800 - 6) * .2 -
|
||||
tester.getSize(find.byType(ChatPeekHeader).first).height,
|
||||
.01,
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
|
||||
Reference in New Issue
Block a user