Keep chat workspace above Android navigation and use pane chat color
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'a',
|
||||
'title': 'Chat a',
|
||||
'directory': '/home/a',
|
||||
'color': 'orange',
|
||||
},
|
||||
{
|
||||
'id': 'b',
|
||||
'title': 'Chat b',
|
||||
'directory': '/home/b',
|
||||
'color': 'teal',
|
||||
},
|
||||
{'id': 'c', 'title': 'Chat c', 'directory': '/home/c'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
Finder _thread(String id) => find.byWidgetPredicate(
|
||||
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
||||
);
|
||||
|
||||
Future<void> _mount(WidgetTester tester, Size size) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.view.viewPadding = const FakeViewPadding(top: 24, bottom: 24);
|
||||
tester.view.padding = const FakeViewPadding(top: 24, bottom: 24);
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: AdaptiveShell(
|
||||
cupertino: false,
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void _expectComposerBottom(WidgetTester tester, double expected) {
|
||||
final pill = find.descendant(
|
||||
of: _thread('a'),
|
||||
matching: find.byKey(const Key('chat-composer-pill')),
|
||||
);
|
||||
expect(tester.getBottomLeft(pill).dy, closeTo(expected, 1));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
Color _border(WidgetTester tester, String id) {
|
||||
final box = tester.widget<DecoratedBox>(
|
||||
find
|
||||
.ancestor(
|
||||
of: _thread(id),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is DecoratedBox &&
|
||||
widget.position == DecorationPosition.foreground &&
|
||||
widget.decoration is BoxDecoration &&
|
||||
(widget.decoration as BoxDecoration).border is Border,
|
||||
),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
return ((box.decoration as BoxDecoration).border! as Border).top.color;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'Android pushed chat clears gesture bar once and keyboard correctly',
|
||||
(tester) async {
|
||||
await _mount(tester, const Size(390, 844));
|
||||
_expectComposerBottom(tester, 844 - 24 - kChatComposerBottomMargin);
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
|
||||
tester.view.padding = const FakeViewPadding(top: 24);
|
||||
await tester.pumpAndSettle();
|
||||
_expectComposerBottom(tester, 844 - 300 - kChatComposerBottomMargin);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'retained workspace restores Android bottom safe area on phone resize',
|
||||
(tester) async {
|
||||
await _mount(tester, const Size(1400, 900));
|
||||
final state = tester.state(_thread('a'));
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.state(_thread('a')), same(state));
|
||||
_expectComposerBottom(tester, 844 - 24 - kChatComposerBottomMargin);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('active pane border follows chat color and uncolored fallback', (
|
||||
tester,
|
||||
) async {
|
||||
await _mount(tester, const Size(1800, 1000));
|
||||
final controller = tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
|
||||
.controller;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_border(tester, 'a'), Colors.transparent);
|
||||
expect(
|
||||
_border(tester, 'b'),
|
||||
chatColorShade(tester.element(_thread('b')), 'teal'),
|
||||
);
|
||||
controller.activate(
|
||||
controller.panes.firstWhere((p) => p.sessionId == 'a').id,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_border(tester, 'a'),
|
||||
chatColorShade(tester.element(_thread('a')), 'orange'),
|
||||
);
|
||||
expect(_border(tester, 'b'), Colors.transparent);
|
||||
controller.splitActive('c', ChatSplitAxis.vertical);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_border(tester, 'c'),
|
||||
Theme.of(tester.element(_thread('c'))).colorScheme.primary,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user