Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ArendJanKramer committed Jan 22, 2025
1 parent 09fda77 commit cd26293
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/pages/vlm/live_inference_pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _VLMPlaygroundState extends State<VLMPlayground> {
labelText: "Max new tokens",
suffix: "",
initialValue: provider.maxTokens,
roundPowerOfTwo: true,
roundPowerOfTwo: false,
onChanged: (value) {
provider.maxTokens = value;
}),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/toolbar_text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _ToolbarTextInputState extends State<ToolbarTextInput> {
if (!_focusNode.hasFocus) {
// When the TextBox loses focus, round and update
final inputValue = int.tryParse(_controller.text.replaceAll(RegExp(r'[^0-9]'), '')) ?? 0;
final rounded = _nearestPowerOfTwo(inputValue);
final rounded = (widget.roundPowerOfTwo ?? false) ? _nearestPowerOfTwo(inputValue) : inputValue;

_controller.text = rounded.toString();
widget.onChanged!(rounded);
Expand Down
36 changes: 32 additions & 4 deletions test/pages/vlm/widgets/assistant_message_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

import 'dart:ui';

import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:inference/pages/vlm/widgets/assistant_message.dart';
import 'package:inference/project.dart';
Expand All @@ -26,7 +30,7 @@ void main() {

testMessage = Message(
Speaker.assistant,
"Test message",
"Test message Test message Test message",
null,
DateTime.now(),
true,
Expand All @@ -42,11 +46,11 @@ void main() {
);
}

testWidgets('renders correctly with message and icon',
(WidgetTester tester) async {
testWidgets('renders correctly with message', (WidgetTester tester) async {
await tester.pumpWidget(createTestWidget(AssistantMessage(testMessage)));

expect(find.text("Test message"), findsOneWidget);
expect(
find.text("Test message Test message Test message"), findsOneWidget);

// Find all `Container` widgets and pick the first one
final containerFinder = find.descendant(
Expand All @@ -66,5 +70,29 @@ void main() {
final AssetImage image2 = thumbnail.image as AssetImage;
expect(image.assetName, equals(image2.assetName));
});

testWidgets('copies message to clipboard when copy button is pressed',
(WidgetTester tester) async {
await tester.pumpWidget(createTestWidget(AssistantMessage(testMessage)));

final assistantMessageFinder = find.byType(AssistantMessage);
expect(assistantMessageFinder, findsOneWidget);

final markdown = find.byType(MarkdownBody);

final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
await gesture.addPointer();
final center = tester.getCenter(markdown.first);
print(center);
await gesture.moveTo(center);

await tester.pumpAndSettle();

await tester.tap(find.byIcon(FluentIcons.copy));
await tester.pump();

final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
expect(clipboardData!.text, "Test message Test message Test message");
});
});
}

0 comments on commit cd26293

Please sign in to comment.