mirror of
https://github.com/foss42/apidash.git
synced 2025-12-08 14:08:22 +08:00
tests: add tests for dashbot action buttons(cv: 95.5)
This commit is contained in:
55
test/dashbot/widgets/action_buttons/test_utils.dart
Normal file
55
test/dashbot/widgets/action_buttons/test_utils.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:apidash/dashbot/core/model/chat_attachment.dart';
|
||||
import 'package:apidash/dashbot/core/providers/dashbot_window_notifier.dart';
|
||||
import 'package:apidash/dashbot/features/chat/models/chat_action.dart';
|
||||
import 'package:apidash/dashbot/features/chat/viewmodel/chat_viewmodel.dart';
|
||||
import 'package:apidash/dashbot/core/constants/constants.dart';
|
||||
|
||||
class TestChatViewmodel extends ChatViewmodel {
|
||||
TestChatViewmodel(super.ref);
|
||||
|
||||
final List<ChatAction> applyAutoFixCalls = [];
|
||||
final List<({String text, ChatMessageType type, bool countAsUser})>
|
||||
sendMessageCalls = [];
|
||||
final List<ChatAttachment> openApiAttachmentCalls = [];
|
||||
|
||||
bool throwOnApplyAutoFix = false;
|
||||
|
||||
@override
|
||||
Future<void> applyAutoFix(ChatAction action) async {
|
||||
applyAutoFixCalls.add(action);
|
||||
if (throwOnApplyAutoFix) {
|
||||
throw Exception('applyAutoFix error');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendMessage({
|
||||
required String text,
|
||||
ChatMessageType type = ChatMessageType.general,
|
||||
bool countAsUser = true,
|
||||
}) async {
|
||||
sendMessageCalls.add((text: text, type: type, countAsUser: countAsUser));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> handleOpenApiAttachment(ChatAttachment att) async {
|
||||
openApiAttachmentCalls.add(att);
|
||||
}
|
||||
}
|
||||
|
||||
class RecordingDashbotWindowNotifier extends DashbotWindowNotifier {
|
||||
int hideCalls = 0;
|
||||
int showCalls = 0;
|
||||
|
||||
@override
|
||||
void hide() {
|
||||
hideCalls += 1;
|
||||
super.hide();
|
||||
}
|
||||
|
||||
@override
|
||||
void show() {
|
||||
showCalls += 1;
|
||||
super.show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user