mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-28 18:34:23 +01:00
Implement and Test Chat Input Field Widget
This commit introduces the ChatInputField widget, a custom text input field designed for use within the ChatView. The ChatInputField widget handles varying screen sizes and gracefully resizes itself according to the available width. It starts with a height of 50 and can expand up to 400 as the user types more lines of text. In addition to the implementation, this commit also includes widget tests to ensure the ChatInputField behaves as expected. - Add ChatInputField widget with dynamic resizing - Include IconButton for sending messages - Add widget tests for ChatInputField - Handle edge cases and overflows
This commit is contained in:
71
test/chat_input_field_test.dart
Normal file
71
test/chat_input_field_test.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:auto_gpt_flutter_client/views/chat/chat_input_field.dart';
|
||||
|
||||
void main() {
|
||||
// Test if the ChatInputField widget renders correctly
|
||||
testWidgets('ChatInputField renders correctly', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatInputField(
|
||||
onSendPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Find the TextField widget
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
// Find the send IconButton
|
||||
expect(find.byIcon(Icons.send), findsOneWidget);
|
||||
});
|
||||
|
||||
// Test if the TextField inside ChatInputField can accept and display input
|
||||
testWidgets('ChatInputField text field accepts input',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatInputField(
|
||||
onSendPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Type 'Hello' into the TextField
|
||||
await tester.enterText(find.byType(TextField), 'Hello');
|
||||
// Rebuild the widget with the new text
|
||||
await tester.pump();
|
||||
|
||||
// Expect to find 'Hello' in the TextField
|
||||
expect(find.text('Hello'), findsOneWidget);
|
||||
});
|
||||
|
||||
// Test if the send button triggers the provided onSendPressed callback
|
||||
testWidgets('ChatInputField send button triggers callback',
|
||||
(WidgetTester tester) async {
|
||||
bool onPressedCalled = false;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatInputField(
|
||||
onSendPressed: () {
|
||||
onPressedCalled = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Tap the send IconButton
|
||||
await tester.tap(find.byIcon(Icons.send));
|
||||
// Rebuild the widget after the tap
|
||||
await tester.pump();
|
||||
|
||||
// Check if the callback was called
|
||||
expect(onPressedCalled, isTrue);
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:auto_gpt_flutter_client/views/new_task_button.dart';
|
||||
import 'package:auto_gpt_flutter_client/views/task/new_task_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:auto_gpt_flutter_client/views/task_list_tile.dart';
|
||||
import 'package:auto_gpt_flutter_client/views/task/task_list_tile.dart';
|
||||
import 'package:auto_gpt_flutter_client/models/task.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
Reference in New Issue
Block a user